How to include a git repo as a dependency when using pbr
Asked Answered
B

1

6

I'm using pbr which uses a requirements.txt file to look for dependencies.

I've a line in requirements.txt like git+ssh://[email protected]/user/repo.git and it works when I run pip install -r requirements.txt

However, when I run python setup.py build I run in to the error:

error in setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'+ssh://g'"

There are many Stack Overflow answers that deal with this problem exclusively when using setuptools and all of them suggest putting the Git dependency into the dependency_links list in setup.py.

I would like pbr to be able to deal with my Git dependency directly from requirements.txt in a way that works when I run both python setup.py build and pip install -r requirements.txt.

Is this possible? Are there any close workarounds?

Babblement answered 21/9, 2017 at 11:13 Comment(0)
M
2

In the example you provided, pbr is propagating the whole line to install_requires, which produces an invalid line.

Provide the requirement name via #egg=name

For it to work as intended, the url needs a #egg suffix to tell pbr what requirement is provided by that URL. If the URL looks like this, pbr will scrape a requirement out of the #egg part and propagate only repo to install_requires:

git+ssh://[email protected]/user/repo.git#egg=repo

Version constraints

If a version is included, pbr will add a >= constraint on it. So this would become repo>=1.2.3 in install_requires:

git+ssh://[email protected]/user/repo.git#egg=repo-1.2.3

Dependency Links

It'll also extract a dependency_link item that contains the full URL. You can use it by passing --process-dependency-links to pip. By default, pip will return the error Could not find a version that satisfies the requirement repo unless the package is also available via PyPI. If --process-dependency-links is specified, then it'll fetch it from the Git URL instead.

Use the -e flag, or require pbr>=1.9.0

Prior to version 1.9.0, pbr only recognized http and https URLs, unless the line started with -e. It added support for git://, git+ssh://, git+https:// without -e in this commit.

Munt answered 21/6, 2018 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.