6

I have an internal Python package which I install for tox with

pip install git+ssh://git@bitbucket.org/org/repo.git

This works.

What does not work is to install the extra server.

What I tried

pip install git+ssh://git@bitbucket.org/org/repo.git[server]`

git clone failed with error code 128 (couldn't clone)

pip install git+ssh://git@bitbucket.org/org/repo.git [server]

Cloning works, Invalid requirement: '[server]' (a parsing exception

pip install -e git+ssh://git@bitbucket.org/org/repo#egg=repo[server]

Could not detect requirement name for 'git+ssh://git@bitbucket.org/org/repo.git', please specify one with #egg=your_package_name


I think I might be affected by this bug: How can I install extras with `pip install git+ssh`?

My (simplified) tox.ini:

[tox]
skipsdist = True
envlist = begin,py35,py36,end

[testenv]
commands =
    pip install -e git+ssh://git@bitbucket.org/org/repo#egg=repo[server]
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • @9769953 See [setuptools' extras](https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies). Did you try to use `--install-option`? Maybe something like `--install-option="--extras-require=server"` might work... – Giacomo Alzetta Oct 09 '18 at 09:42
  • 1
    You should pass the egg name for `pip` to be able to split the git url from the additional metadata. `pip install git+ssh://git@bitbucket.org/org/repo.git#egg=project[server]` will work. – hoefling Oct 09 '18 at 10:07
  • @GiacomoAlzetta Thank you! I didn't know of `--install-option="--extras-require"`. I always installed extras via the bracket notation (e.g. `pip install requests[security]`). – Martin Thoma Oct 09 '18 at 10:16
  • @GiacomoAlzetta Do you want to post this as an answer? – Martin Thoma Oct 09 '18 at 10:46
  • @MartinThoma I did not post it as an answer before because I wasn't sure it would work (or whether `--extras-require` was the correct name). turns out they were consistent and my guess worked out :) – Giacomo Alzetta Oct 09 '18 at 12:43
  • 1
    @hoefling It's not a duplicate. That question is a related but different issue and the answers are of no help (although I'd add that my answer would be a valid answer for that question too, so it would make sense to mark that question as a duplicate of this one ...) – Giacomo Alzetta Oct 09 '18 at 12:44
  • @GiacomoAlzetta it's the same one. One just has to read more than the question title (which, i admit, is kinda misleading with the `-e` option): _How can one manage to install extras_requires with pip when installing from a git repository?_ The answer listed there is also a working one and answers this question perfectly. – hoefling Oct 09 '18 at 13:14
  • According to https://pip.pypa.io/en/stable/reference/pip_install/ `pip install git+https://git.repo/some_pkg.git#egg=SomePackage[PDF]` should work ... but at least with ssh, it doesn't :-/ – Martin Thoma Oct 09 '18 at 13:17
  • @MartinThoma can you provide the link to the repo? because AFAICT testing with my own forks runs fine, e.g. `pip install git+ssh://git@github.com/hoefling/mypy.git#egg=mypy[dmypy]` installs the extra requirements just fine. – hoefling Oct 09 '18 at 13:19
  • @hoefling No, it is a private repository. But I think I might have found the issue: https://stackoverflow.com/q/52723919/562769 – Martin Thoma Oct 09 '18 at 14:52
  • it's an issue with `tox` and not with `pip`. As correctly suggested in the comments to that question, wrapping the url in single quotes will solve the issue. – hoefling Oct 09 '18 at 15:01
  • This question is the first Google hit for "pip git extras", is not exactly a duplicate of the other questions listed, and I think should be reopened. – astrojuanlu Oct 25 '22 at 10:06

1 Answers1

4

You can use the --install-option to forward options to setuptools, so the following should work:

pip install --install-option="--extras-require=server" git+ssh://git@bitbucket.org/org/repo.git

See also:

$ pip install --help

Usage:   
  pip install [options] <archive url/path> ...

[...]

Install Options:
  [...]
  --install-option <options>  Extra arguments to be supplied to the setup.py install command (use like --install-option="--install-scripts=/usr/local/bin"). Use multiple --install-option options to pass multiple options to setup.py install. If you are
                              using an option with a directory path, be sure to use absolute path.
  --global-option <options>   Extra global options to be supplied to the setup.py call before the install command.
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
Giacomo Alzetta
  • 2,431
  • 6
  • 17
  • 1
    Sorry, I made a mistake. This does not work :-/ - it installs the base package, but not the extra "server". – Martin Thoma Oct 09 '18 at 13:11
  • 1
    Note that this one is different than passing extras in square brackets. When doing `pip install git+url#egg=name[extras]`, the extras are parsed and installed by `pip`, whereas passing an install option means that `pip` will ignore the extras and they will be managed by either `easy_install` (if `setuptools.setup` is used in the setup script) or by stdlib (`distutils.core.setup` case). – hoefling Oct 09 '18 at 13:47
  • 2
    This can result in various installation errors because `--install-option` is propagated to extras (example: `pip install --install-option="--extras-require=dmypy" git+https://github.com/hoefling/mypy.git#egg=mypy` will fail with an error `Running setup.py install for typed-ast ... error: option --extras-require not recognized`), or to a situation where you are unable to uninstall dependencies because of the "old-and-unmanageable" install performed and `pip` refusing to uninstall with the message `It is a distutils installed project ...`. – hoefling Oct 09 '18 at 13:50