Skip to content

Instantly share code, notes, and snippets.

Forked from sobolevn/
Last active December 16, 2019 15:15
What would you like to do?
Formatting, check for errors for git packages
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import toml
def read_pipenv_lock():
with open('Pipfile.lock') as lock:
return json.loads(
def read_pipenv():
with open('Pipfile') as pipfile:
return toml.loads(
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]:
notations.update({dep: convert_version(dependencies[dep]['version'])})
except KeyError as e:
errors.append(f'{dep} - ({e.__class__.__name__}) {e} - {dependencies[dep]}')
return notations
if __name__ == '__main__':
errors = []
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 + '"')
if len(errors):
print('errors encountered:')
for error in errors:
print(f'- {error}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment