Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sync values in setup.py / install_requires with Pipfile / packages

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]?

like image 657
Rotareti Avatar asked Mar 26 '18 17:03

Rotareti


1 Answers

Within your setup.py:

  1. 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()]
    
  2. 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
like image 77
Scott Robert Schreckengaust Avatar answered Sep 18 '22 07:09

Scott Robert Schreckengaust