Skip to content

Instantly share code, notes, and snippets.

@knqyf263
Created April 12, 2018 08:18
Show Gist options
  • Save knqyf263/8ffc9bc6b872a154e7e25d219585cabd to your computer and use it in GitHub Desktop.
Save knqyf263/8ffc9bc6b872a154e7e25d219585cabd to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#coding:utf-8
import json, toml, hashlib
groups = {
'default': [],
'develop': []
}
# Open the Pipfile.
with open("Pipfile") as f:
content = f.read()
# Load the default configuration.
default_config = {
u'source': [{u'url': u'https://pypi.python.org/simple', u'verify_ssl': True, 'name': "pypi"}],
u'packages': {},
u'requires': {},
u'dev-packages': {}
}
config = {}
config.update(default_config)
# Deserialize the TOML, and parse for Environment Variables
parsed = toml.loads(content)
config.update(parsed)
# Structure the data for output.
data = {
'_meta': {
'sources': config['source'],
'requires': config['requires']
},
}
groups['default'] = config['packages']
groups['develop'] = config['dev-packages']
# Update the data structure with group information.
data.update(groups)
content = json.dumps(data, sort_keys=True, separators=(",", ":"))
print(hashlib.sha256(content.encode("utf8")).hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment