If you work on a project that uses both setup.py
and Pipfile
you often find the same values in: Pipfile/[packages]
and setup.py/install_requires
.
Does anyone know how I can tell Pipfile
to use values from setup.py/install_requires
for [packages]
?
Within your setup.py
:
Define a function to read a section:
def locked_requirements(section):
"""Look through the 'Pipfile.lock' to fetch requirements by section."""
with open('Pipfile.lock') as pip_file:
pipfile_json = json.load(pip_file)
if section not in pipfile_json:
print("{0} section missing from Pipfile.lock".format(section))
return []
return [package + detail.get('version', "")
for package, detail in pipfile_json[section].items()]
Within the setup
function return the list from the default
section:
setup(
# ...snip...
install_requires=locked_requirements('default'),
# ...snip...
)
IMPORTANT NOTE: include Pipfile.lock
within the MANIFEST.in
like:
include Pipfile.lock
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With