mdh
mdh

Reputation: 5563

How to include git dependencies in setup.py for pip installation

I need to include Python packages available via public Github repositories along with my Python (2.7) package. My package should be installable via pip using setup.py.

So far, this could be done using dependency_links in the setup.py file:

setuptools.setup(
   name="my_package",
   version="1.0",
   install_requires=[
       "other_package==1.2"
   ],
   dependency_links=[
      "https://github.com/user/other_package/tarball/master#egg=other_package-1.2"
   ]    
)

This still works when the package gets installed with the --process-dependency-links flag, but the dependency_links functionality seems to be deprecated, since:

pip install git+https://github.com/user/my_package@master#egg=my_package-1.0 --process-dependency-links

gives me the following warning:

DEPRECATION: Dependency Links processing has been deprecated and will be removed in a future release.

Is there an alternative way to include git dependencies in the setup.py file with support for pip installation?

Edit (10/17/2016) to clarify my use case:

Let's say I find a bug in other_package. I fork the respective repo on Github, fix the bug and make a pull request. My pull request doesn't get immediately accepted (or never will be because the package is no longer actively maintained). I would like to distribute my_package together with my fork of other_package and want users to be able to pip install my_package without any further knowledge about the details of this requirement and without having to provide any additional flags upon installation. Users of my_package should further be able to include my_package as a requirement in their own custom packages.

How can this be achieved bearing compatibly with different modes of installation (wheels, eggs, develop, ...) in mind?

Upvotes: 16

Views: 4374

Answers (2)

Zach
Zach

Reputation: 79

I ran into this exact issue (found a bug in someone else's project that mine depended on, made a pull request but didn't have time to wait for them to merge).

I solved it by adding this line to install_requires:

'my-package @ https://github.com/user/my-package/archive/master.tar.gz'

Upvotes: 3

Philip Adler
Philip Adler

Reputation: 2206

Personally, I would avoid including git repositories as dependencies. In the scenarios you describe, I see two options.

Where Package is Unmaintained

If a package is unmaintained, you can either fork the project and distribute your own version, or you can distribute the forked code as as a submodule of your own code (i.e. include the external dependency directly in your distributable package)

Personally I prefer distributing my own version.

Where the package has yet to include your bugfix

In this case, I would distribute the fixed code as a part of your package until such a time as the bug is fixed.

Upvotes: 1

Related Questions