How can I add pip extras as git repositories?

While I had no problems refering to git repositories in requirements.txt files, i was unable to find a way to add them as extras in setup.cfg

Is there a way to add (optional) extras that point to git? How?

Try with “options.extras_require” section in config file.

Refer more: https://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files

There are two ways to do this: the dependency_links way, which is deprecated, and the PEP 508 url_req way, which pip only started supporting in the latest version (18.1). I’ll only address the latter way here.

A dependency located on GitHub must be declared in install_requires or extras_require as “project_name @ git+https://github.com/user/repo” (possibly with “#egg=project_name” at the end; I’ve never been clear on the purpose of that bit, but it seems to work without it). As long as you’re using wheel v0.32.0 or higher, you can build wheels with these sorts of requirements in install_requires, and pip 18.1 will be able to install them. Unfortunately, as of the latest version of wheel (0.32.2), there is a bug that prevents it from correctly building wheels with GitHub extras, and the resulting wheels are unusable; see this bug report for more information.

So, the answer is currently, “You can’t, but hopefully soon you can do it the same way as install_requires.”

1 Like

I’m not 100% sure what pip does without reading the source (pip has a lot of unspecified quirks), but—The #egg=xxx part is from the requirements.txt format. It should be conceptually equivalent to xxx @ in PEP 508 style URL requirements, and thus is not meaningful here.

This usually worked for me: pip install <git_url>#egg=xxx[extra1,extra2]. So pip understands this.
setup.cfg, OTOH, is parsed with setuptools so maybe your question is more appropriate there if this doesn’t work.