Reputation: 16231
I have a local GitLab installation that comes with a local PyPI server to store company internal Python packages.
How can I configure my PyPI to search packages in both index servers?
I read about .pypirc
/ pip/pip.ini
and found various settings but no solution so far.
[global]
or [install]
. I assume the latter one is a rule subset for pip install
. (The documentation is here unclear.)-r gitlab
refers to a [gitlab]
section, such a named reference can't be used by pip...So what I want to achieve:
pip
should be able to install and update regular packages from pypi.org like coloramapip
should be able to install and update packages from gitlab.company.com
__token__
) and password (7a3b62342c784d87
) must workExperiment so far:
[global]
[install]
find-links =
https://pypi.org
https://gitlab.company.de/api/v4/projects/2142423/packages/pypi
trusted-host =
https://pypi.org
https://gitlab.company.de/api/v4/projects/2142423/packages/pypi
[distutils]
index-servers =
gitlab
[gitlab]
repository = https://gitlab.company.de/api/v4/projects/2142423/packages/pypi
username = __token__
password = geheim
Upvotes: 12
Views: 9751
Reputation: 2906
It may be simpler to use the PIP_EXTRA_INDEX_URL
environment variable to set multiple indices. As noted here, you can also have more than one extra index by using space delimitation between the indices.
PIP_EXTRA_INDEX_URL="https://__token__:${GITLAB_TOKEN}@gitlab.company.com/api/v4/projects/1/packages/pypi https://__token__:${GITLAB_TOKEN}@gitlab.company.com/api/v4/projects/2/packages/pypi"
Upvotes: 0
Reputation: 3063
Goal
pip install
should install/update packages from GitLab as well as PyPi repo. If same package is present in both, PyPi is preferred.pip install
should support authentication. Preferred, if somehow we can make it read from a config file so that we don't need to specify it repeatatively.Theory
pip install
supports --extra-index-url
to specify additional PyPi indexes. The same can also be provided via pip.conf
file.pip
uses requests
which supports ~/.netrc
as config file (docs).Steps
pip.conf
(pip.ini
if on Windows) in any of the locations suggested by pip config -v list
.pip.conf
.[install]
extra-index-url = https://gitlab.com/api/v4/projects/12345678/packages/pypi/simple
~/.netrc
file and add your auth details for GitLab.machine gitlab.com
login <token-name>
password <token-pass>
pip install <package-name>
. pip
will now look at both indexes to find your packages, with preference provided to the one pointed by index-url
.Additional info
pip search
too, had there been support for multiple indexes. Till then, one needs to manually specify which PyPi index URL should be used. GitLab does not seem to support pip search
since it throws 415 Client Error: Unsupported Media Type when specified as the PyPi index.pip.conf
points to that particular command, [install]
provides configuration for pip install
, [search]
for pip search
and so on. [global]
probably refers to parameters that can be specified for all the commands be it pip install
or pip search
..pypirc
file is made specially for configuring package indexes related to upload (used by twine/flint), where as pip.conf
is associated with configuring pip
which manages python packages on your local system.Upvotes: 11
Reputation: 2370
Try this (based on information from https://github.com/pypa/pip/issues/6797 and Can pip.conf specify two index-url at the same time?):
[global]
index-url = http://pypi.org/simple
trusted-host = pypi.org
gitlab.company.de
extra-index-url= https://username:[email protected]/api/v4/projects/2142423/packages/pypi
Upvotes: 5