From de46370b1ea917fc549bda86ad0d027c05e4c373 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 4 Dec 2026 11:55:38 +0100 Subject: [PATCH] Improve Examples section of the Dependency specifiers spec Closes gh-1226 --- .../specifications/dependency-specifiers.rst | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/source/specifications/dependency-specifiers.rst b/source/specifications/dependency-specifiers.rst index 1e930f352..871874e62 100644 --- a/source/specifications/dependency-specifiers.rst +++ b/source/specifications/dependency-specifiers.rst @@ -32,14 +32,40 @@ Specification Examples -------- -All features of the language shown with a name based lookup:: +A dependency specifier showing all grammar features for a name based lookup:: requests [security,tests] >= 2.8.1, == 2.8.* ; python_version < "3.7" -A minimal URL based lookup:: +A dependency specifier with a direct URL reference:: pip @ https://github.com/pypa/pip/archive/1.3.1.zip#sha1=da9234ee9982d4bbb3c72346a6de940a148ea686 +Optional whitespace can improve readability, as in ``pip ~= 23.1`` or +``resolvelib > 0.5, != 0.6.0``. The surrounding syntax depends on where the +dependency specifier is used. + +In Core Metadata, dependency specifiers are values of +:ref:`Requires-Dist ` fields:: + + Requires-Dist: pip ~= 23.1 + Requires-Dist: resolvelib > 0.5, != 0.6.0 + +In :file:`pyproject.toml`, they can be listed as strings, for example in +:ref:`project.dependencies `: + +.. code-block:: toml + + [project] + dependencies = [ + "pip ~= 23.1", + "resolvelib > 0.5, != 0.6.0", + ] + +When passing a dependency specifier containing spaces on the command line, +quote the entire argument to preserve those spaces:: + + python -m pip install "pip ~= 23.1" + Concepts -------- @@ -710,6 +736,8 @@ History inadvertently retained from :pep:`508` - July 2026: Explain that ``extra != "name"`` is not (properly) supported (https://discuss.python.org/t/ban-negative-extras-for-extras-marker/108022/24) +- December 2026: Added examples showing dependency specifiers in metadata, + TOML configuration, and shell commands. References