Search code examples
python-3.xsetuptools

Declare a requirement to be installed from github branch


What is the correct way to have a specific branch of a repo as a dependency, and be able to use it for running tests too?

If you only specify dependency_links, setuptools would install it as a dependency but does not install it to run the test:

setup(
    packages=['utils', 'tokens'],
    dependency_links=[
        'https://github.com/Demonware/jose/tarball/python3#egg=jose-1.1.0'
    ],
    # install_requires=['jose'],
    use_2to3=True,
    test_suite='test_jwt',
    zip_safe=True,
)

I rely on python3 branch of jose library. When I run setup.py test, it complains that it cannot find jose package.

If I add install_requires, it simply does install the master branch and not the python3 branch that I need.


Solution

  • Try:

    dependency_links=[
        'https://github.com/Demonware/jose@python3#egg=jose-1.1.0'
    ],
    install_requires=['jose'],
    

    Let me explain. The pip/setuptools VCS URLs have the following structure:

    git+https://repoURL@reference#egg=project-version
    

    RepoURL is a VCS repository URL (https://github.com/Demonware/jose in your case).

    Reference is a tag, a branch or a commit ID (SHA1, could be shortened to 7-10 characters); in your case it's branch python3.

    Project name and version in the #egg= hash are necessary for setuptools to recognize an URL as the URL for project named in install_requiressetuptools must know the name before downloading the project so the #egg= hash is the only way to convey that information. Version is not strictly necessary but it would be useful for such a case as install_requires=['jose>=1.1.0'].