Created
February 18, 2019 15:34
-
-
Save sobolevn/665695b82e4259e9875875167b111e35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import json | |
import toml | |
def read_pipenv_lock(): | |
with open('Pipfile.lock') as lock: | |
return json.loads(lock.read()) | |
def read_pipenv(): | |
with open('Pipfile') as pipfile: | |
return toml.loads(pipfile.read()) | |
def convert_version(version): | |
return version.replace('==', '^') | |
def to_name_version_notation(pipfile, lock, section): | |
category = 'packages' if section == 'default' else 'dev-packages' | |
notations = {} | |
dependencies = lock[section] | |
for dep in dependencies: | |
if dep not in pipfile[category]: | |
continue | |
notations.update({ | |
dep: convert_version(dependencies[dep]['version']), | |
}) | |
return notations | |
pipfile = read_pipenv() | |
lock = read_pipenv_lock() | |
for section in ['default', 'develop']: | |
print('Section:', section) | |
current = to_name_version_notation(pipfile, lock, section) | |
for dep, version in current.items(): | |
print(dep, '=', '"' + version + '"') | |
print() |
@tony I recommend to try dephell
instead: https://github.com/dephell/dephell
It will do the same thing.
@sobolevn : Thank you!
So it'll be able to convert Pipfile to poetry's pyproject.toml ?
Would it require everyone on the team installing dephell, or just poetry?
You can convert your Pipfile
once. And then use just poetry
.
dephell deps convert --from=Pipfile --to-format poetry --to-path pyproject.toml
And then you have a valid poetry file 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!
A bit of an issue I have: