From c634a9b5dbb19f27813f083ffcbefdc86e857c25 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 13 Nov 2026 14:56:27 +0000 Subject: [PATCH] Avoid fetching dependencies from TestPyPI Use `--no-deps` and require a wheel to avoid downloading runtime or build dependencies from TestPyPI. Replace mixed-index installation advice with separate dependency installation from PyPI, and explain the risk of unintended or malicious packages. The packaging tutorial already uses `--no-deps` and has similar guidance. Closes gh-1500 --- source/guides/using-testpypi.rst | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/source/guides/using-testpypi.rst b/source/guides/using-testpypi.rst index 1dbc82130a..2e942fae27 100644 --- a/source/guides/using-testpypi.rst +++ b/source/guides/using-testpypi.rst @@ -38,36 +38,32 @@ your project to appear on the site. Using TestPyPI with pip ----------------------- -You can tell :ref:`pip` to download packages from TestPyPI instead of PyPI by -specifying the ``--index-url`` flag: +You can use :ref:`pip` to install a wheel that you uploaded to TestPyPI: .. tab:: Unix/macOS .. code-block:: bash - python3 -m pip install --index-url https://test.pypi.org/simple/ your-package + python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps --only-binary=:all: your-package .. tab:: Windows .. code-block:: bat - py -m pip install --index-url https://test.pypi.org/simple/ your-package + py -m pip install --index-url https://test.pypi.org/simple/ --no-deps --only-binary=:all: your-package -If you want to allow pip to also download packages from PyPI, you can -specify ``--extra-index-url`` to point to PyPI. This is useful when the package -you're testing has dependencies: +The ``--index-url`` flag selects TestPyPI instead of PyPI. The ``--no-deps`` +flag prevents installing runtime dependencies, while ``--only-binary=:all:`` +requires a wheel, avoiding installation of build dependencies. If your package +has dependencies, install them separately from PyPI before running these commands. -.. tab:: Unix/macOS - - .. code-block:: bash - - python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ your-package - -.. tab:: Windows - - .. code-block:: bat +.. warning:: - py -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ your-package + TestPyPI is a separate index, and packages there may be missing or unrelated + to packages with the same name on PyPI. Installing dependencies from TestPyPI + could install unintended or malicious packages. Avoid combining the two + indexes with ``--extra-index-url``: pip does not prioritize one index over + the other, so dependencies could still be downloaded from TestPyPI. Setting up TestPyPI in :file:`.pypirc` --------------------------------------