Frage

Is there a way to tell the tox test automation tool to use the PyPI mirrors while installing all packages (explicit testing dependencies in tox.ini and dependencies from setup.py)?

For example, pip install has a very useful --use-mirrors option that adds mirrors to the list of package servers.

War es hilfreich?

Lösung

Pip also can be configured using environment variables, which tox lets you set in the configuration:

setenv =
    PIP_USE_MIRRORS=...

Note that --use-mirrors has been deprecated; instead, you can set the PIP_INDEX_URL or PIP_EXTRA_INDEX_URL environment variables, representing the --index-url and --extra-index-url command-line options.

For example:

setenv = 
    PIP_EXTRA_INDEX_URL=http://example.org/index

would add http://example.org/index as an alternative index server, used if the main index doesn't have a package.

Andere Tipps

Since indexserver is deprecated and would be removed and --use-mirrors is deprecated as well, you can use install_command (in your environment section):

[testenv:my_env]
install_command=pip install --index-url=https://my.index-mirror.com --trusted-host=my.index-mirror.com {opts} {packages}

Tox can be configured to install dependencies and packages from a different default PyPI server:

  • as tox command line argument

    tox -i http://pypi.my-alternative-index.org
    
  • using tox.ini

    [tox]
    indexserver =
        default = http://pypi.my-alternative-index.org
    

Link to Tox documentation on using a different default PyPI url

From the pip docs:

pip’s command line options can be set with environment variables using the format PIP_<UPPER_LONG_NAME> . Dashes (-) have to be replaced with underscores (_).

Source: https://pip.pypa.io/en/stable/user_guide/#environment-variables

This translates into setting the following environment variables:

PIP_INDEX_URL=https://server1/pypi/simple
PIP_EXTRA_INDEX_URL=https://server2/pypi/simple

So, with tox, you can e.g. set:

[testenv]
setenv = 
    PIP_INDEX_URL=https://server1/pypi/simple
    PIP_EXTRA_INDEX_URL=https://server2/pypi/simple

However, you can only specify one extra index url with PIP_EXTRA_INDEX_URL. If you need multiple ones, pip recommends appending multiple --extra-index-url <URL> after the pip command so if you need more than one extra index URL, you could possibly utilize tox's install_command:

[testenv]
install_command =
    python -m pip install {opts} {packages} --extra-index-url <URL1> --extra-index-url <URL2>

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top