From f79f2282c77096878164d0d09ac265344de6b454 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 27 Nov 2026 17:07:55 +0100 Subject: [PATCH 1/7] Remove stubbed-out discussion "Deploying Python applications" This was marked as incomplete in 2021, contains almost nothing except a few tool descriptions. It overlaps with the "Overview of Python Packaging" page as well, which covers this topic reasonably well in its overview of deployment modes. --- .../deploying-python-applications.rst | 139 ------------------ source/discussions/index.rst | 1 - source/index.rst | 4 +- 3 files changed, 1 insertion(+), 143 deletions(-) delete mode 100644 source/discussions/deploying-python-applications.rst diff --git a/source/discussions/deploying-python-applications.rst b/source/discussions/deploying-python-applications.rst deleted file mode 100644 index 8e3e5d66ea..0000000000 --- a/source/discussions/deploying-python-applications.rst +++ /dev/null @@ -1,139 +0,0 @@ - -============================= -Deploying Python applications -============================= - -:Page Status: Incomplete -:Last Reviewed: 2021-8-24 - - -Overview -======== - - -Supporting multiple hardware platforms --------------------------------------- - -:: - - FIXME - - Meaning: x86, x64, ARM, others? - - For Python-only distributions, it *should* be straightforward to deploy on all - platforms where Python can run. - - For distributions with binary extensions, deployment is a major headache. Not only - must the extensions be built on all the combinations of operating system and - hardware platform, but they must also be tested, preferably on continuous - integration platforms. The issues are similar to the "multiple Python - versions" section above, not sure whether this should be a separate section. - Even on Windows x64, both the 32 bit and 64 bit versions of Python enjoy - significant usage. - - - -OS packaging & installers -========================= - -:: - - FIXME - - - Building rpm/debs for projects - - Building rpms/debs for whole virtualenvs - - Building macOS installers for Python projects - - Building Android APKs with Kivy+P4A or P4A & Buildozer - -Windows -------- - -:: - - FIXME - - - Building Windows installers for Python projects - -Pynsist -^^^^^^^ - -:pypi:`Pynsist ` is a tool that bundles Python -programs together with the Python-interpreter into a single installer based on -NSIS. In most cases, packaging only requires the user to choose a version of -the Python-interpreter and declare the dependencies of the program. The tool -downloads the specified Python-interpreter for Windows and packages it with all -the dependencies in a single Windows-executable installer. - -The installed program can be started from a shortcut that the installer adds to -the start-menu. It uses a Python interpreter installed within its application -directory, independent of any other Python installation on the computer. - -A big advantage of Pynsist is that the Windows packages can be built on Linux. -There are several examples for different kinds of programs (console, GUI) in -the :any:`documentation `. The tool is released -under the MIT-licence. - -Application bundles -=================== - -:: - - FIXME - - - wheels kinda/sorta - -Windows -------- - -py2exe -^^^^^^ - -:pypi:`py2exe` is a distutils extension which -allows to build standalone Windows executable programs (32-bit and 64-bit) -from Python scripts. Python versions included in the official development -cycle are supported (refers to `Status of Python branches`__). py2exe can -build console executables and windows (GUI) executables. Building windows -services, and DLL/EXE COM servers might work but it is not actively supported. -The distutils extension is released under the MIT-licence and Mozilla -Public License 2.0. - -.. __: https://devguide.python.org/versions/ - -macOS ------ - -py2app -^^^^^^ - -:pypi:`py2app` is a Python setuptools -command which will allow you to make standalone macOS application -bundles and plugins from Python scripts. Note that py2app MUST be used -on macOS to build applications, it cannot create Mac applications on other -platforms. py2app is released under the MIT-license. - -Unix (including Linux and macOS) ------------------------------------ - -pex -^^^ - -:pypi:`pex` is a library for generating .pex -(Python EXecutable) files which are executable Python environments in the -spirit of virtualenvs. pex is an expansion upon the ideas outlined in :pep:`441` -and makes the deployment of Python applications as simple as cp. pex files may -even include multiple platform-specific Python distributions, meaning that a -single pex file can be portable across Linux and macOS. pex is released under the -Apache License 2.0. - -Configuration management -======================== - -:: - - FIXME - - puppet - salt - chef - ansible - fabric diff --git a/source/discussions/index.rst b/source/discussions/index.rst index a62af08e68..b1e6905fa6 100644 --- a/source/discussions/index.rst +++ b/source/discussions/index.rst @@ -9,7 +9,6 @@ specific topic. If you're just trying to get stuff done, see :maxdepth: 1 versioning - deploying-python-applications install-requires-vs-requirements distribution-package-vs-import-package package-formats diff --git a/source/index.rst b/source/index.rst index 08351016ba..3046b03914 100644 --- a/source/index.rst +++ b/source/index.rst @@ -79,9 +79,7 @@ Explanations and Discussions ============================ The :doc:`discussions/index` section provides in-depth explanations and discussion -about topics, such as: - -* :doc:`discussions/deploying-python-applications` +about Python packaging topics. Reference ========= From 68bd9d8f9b0779e2104d2732579650ce058a1377 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 27 Nov 2026 17:19:30 +0100 Subject: [PATCH 2/7] Make the discussion "Is setup.py deprecated?" an orphan page This is by now outdated setuptools-specific content, which is best left to the setuptools docs rather than the Packaging Guide (xref issue 2170). This may have enough incoming links that it's useful to leave as an orphan page for now. --- source/discussions/index.rst | 1 - source/discussions/setup-py-deprecated.rst | 207 +-------------------- 2 files changed, 6 insertions(+), 202 deletions(-) diff --git a/source/discussions/index.rst b/source/discussions/index.rst index b1e6905fa6..ad729b8c75 100644 --- a/source/discussions/index.rst +++ b/source/discussions/index.rst @@ -13,6 +13,5 @@ specific topic. If you're just trying to get stuff done, see distribution-package-vs-import-package package-formats src-layout-vs-flat-layout - setup-py-deprecated single-source-version downstream-packaging diff --git a/source/discussions/setup-py-deprecated.rst b/source/discussions/setup-py-deprecated.rst index 26d88f2bb6..783a98401d 100644 --- a/source/discussions/setup-py-deprecated.rst +++ b/source/discussions/setup-py-deprecated.rst @@ -1,3 +1,5 @@ +:orphan: + .. _setup-py-deprecated: @@ -9,207 +11,10 @@ No, :term:`setup.py` and :ref:`setuptools` are not deprecated. Setuptools is perfectly usable as a :term:`build backend` for packaging Python projects. -And :file:`setup.py` is a valid configuration file for :ref:`setuptools` -that happens to be written in Python, instead of in *TOML* for example -(a similar practice is used by other tools -like *nox* and its :file:`noxfile.py` configuration file, -or *pytest* and :file:`conftest.py`). - -However, ``python setup.py`` and the use of :file:`setup.py` -as a command line tool are deprecated. - -This means that commands such as the following **MUST NOT** be run anymore: - -* ``python setup.py install`` -* ``python setup.py develop`` -* ``python setup.py sdist`` -* ``python setup.py bdist_wheel`` - - -What commands should be used instead? -===================================== - -+---------------------------------+----------------------------------------+ -| Deprecated | Recommendation | -+=================================+========================================+ -| ``python setup.py install`` | ``python -m pip install .`` | -+---------------------------------+----------------------------------------+ -| ``python setup.py develop`` | ``python -m pip install --editable .`` | -+---------------------------------+----------------------------------------+ -| ``python setup.py sdist`` | ``python -m build`` [#needs-build]_ | -+---------------------------------+ | -| ``python setup.py bdist_wheel`` | | -+---------------------------------+----------------------------------------+ - - -.. [#needs-build] This requires the :ref:`build` dependency. - It is recommended to always build and publish both the source distribution - and wheel of a project, which is what ``python -m build`` does. - If necessary the ``--sdist`` and ``--wheel`` options can be used - to generate only one or the other. - - -In order to install a setuptools based project, -it was common to run :file:`setup.py`'s ``install`` command such as: -``python setup.py install``. -Nowadays, the recommended method is to use :ref:`pip` directly -with a command like this one: ``python -m pip install .``. -Where the dot ``.`` is actually a file system path, -it is the path notation for the current directory. -Indeed, *pip* accepts a path to -a project's source tree directory on the local filesystem -as argument to its ``install`` sub-command. -So this would also be a valid command: -``python -m pip install path/to/project``. - -As for the installation in *develop* mode aka *editable* mode, -instead of ``python setup.py develop`` -one can use the ``--editable`` option of pip's *install* sub-command: -``python -m pip install --editable .``. - -One recommended, simple, and straightforward method of building -:term:`source distributions ` -and :term:`wheels ` -is to use the :ref:`build` tool with a command like -``python -m build`` -which triggers the generation of both distribution formats. -If necessary the ``--sdist`` and ``--wheel`` options can be used -to generate only one or the other. -Note that the build tool needs to be installed separately. - -The command ``python setup.py install`` was deprecated -in setuptools version *58.3.0*. - - -What about other commands? -========================== - -What are some replacements for the other ``python setup.py`` commands? - - -``python setup.py test`` ------------------------- - -The recommendation is to use a test runner such as pytest_. - -.. _pytest: https://docs.pytest.org/ - - -``python setup.py check``, ``python setup.py register``, and ``python setup.py upload`` ---------------------------------------------------------------------------------------- - -A trusted replacement is :ref:`twine`: - -* ``python -m twine check --strict dist/*`` -* ``python -m twine register dist/*.whl`` [#not-pypi]_ -* ``python -m twine upload dist/*`` - -.. [#not-pypi] Not necessary, nor supported on :term:`PyPI `. - But might be necessary on other :term:`package indexes ` (for example :ref:`devpi`). - - -``python setup.py --version`` ------------------------------ - -A possible replacement solution (among others) is to rely on setuptools-scm_: - -* ``python -m setuptools_scm`` - -.. _setuptools-scm: https://setuptools-scm.readthedocs.io/latest/usage/#as-cli-tool - - -Remaining commands ------------------- - -This guide does not make suggestions of replacement solutions for those commands: - -.. hlist:: - :columns: 4 - - * ``alias`` - * ``bdist`` - * ``bdist_dumb`` - * ``bdist_egg`` - * ``bdist_rpm`` - * ``build`` - * ``build_clib`` - * ``build_ext`` - * ``build_py`` - * ``build_scripts`` - * ``clean`` - * ``dist_info`` - * ``easy_install`` - * ``editable_wheel`` - * ``egg_info`` - * ``install_data`` - * ``install_egg_info`` - * ``install_headers`` - * ``install_lib`` - * ``install_scripts`` - * ``rotate`` - * ``saveopts`` - * ``setopt`` - * ``upload_docs`` - - -What about custom commands? -=========================== - -Likewise, custom :file:`setup.py` commands are deprecated. -The recommendation is to migrate those custom commands -to a task runner tool or any other similar tool. -Some examples of such tools are: -chuy, make, nox or tox, pydoit, pyinvoke, taskipy, and thx. - - -What about custom build steps? -============================== - -Custom build steps that for example -either overwrite existing steps such as ``build_py``, ``build_ext``, and ``bdist_wheel`` -or add new build steps are not deprecated. -Those will be automatically called as expected. - - -Should ``setup.py`` be deleted? -=============================== - -Although the usage of :file:`setup.py` as an executable script is deprecated, -its usage as a configuration file for setuptools is absolutely fine. -There is likely no modification needed in :file:`setup.py`. - - -Is ``pyproject.toml`` mandatory? -================================ - -While it is not technically necessary yet, -it is **STRONGLY RECOMMENDED** for a project to have a :file:`pyproject.toml` file -at the root of its source tree with a content like this: - -.. code:: toml - - [build-system] - requires = ["setuptools"] - build-backend = "setuptools.build_meta" - - -The guide :ref:`modernize-setup-py-project` has more details about this. - -The standard fallback behavior for a :term:`build frontend ` -in the absence of a :file:`pyproject.toml` file and its ``[build-system]`` table -is to assume that the :term:`build backend ` is setuptools. - - -Why? What does it all mean? -=========================== - -One way to look at it is that the scope of setuptools -has now been reduced to the role of a build backend. - - -Where to read more about this? -============================== -* `Why you shouldn't invoke setup.py directly `__ by Paul Ganssle +Only invoking ``python setup.py `` directly is deprecated. For more +details on that topic, please see: +* `Why you shouldn't invoke setup.py directly `__ + by Paul Ganssle * :doc:`setuptools:deprecated/commands` From 561bce43862e8bd73b06340c5dd5ad8ff4bacd0f Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 27 Nov 2026 17:30:20 +0100 Subject: [PATCH 3/7] Clean up section on eggs from discussion page "Package Formats" --- source/discussions/package-formats.rst | 48 -------------------------- source/glossary.rst | 6 ++-- 2 files changed, 4 insertions(+), 50 deletions(-) diff --git a/source/discussions/package-formats.rst b/source/discussions/package-formats.rst index f5aeb1e10f..f5443b453a 100644 --- a/source/discussions/package-formats.rst +++ b/source/discussions/package-formats.rst @@ -131,47 +131,6 @@ All technical details on the wheel format can be found in the :ref:`wheel specification `. -.. _egg-format: -.. _`Wheel vs Egg`: - -What about eggs? -================ - -"Egg" is an old package format that has been replaced with the wheel format. It -should not be used anymore. Since August 2023, PyPI `rejects egg uploads -`_. - -Here's a breakdown of the important differences between wheel and egg. - -* The egg format was introduced by :ref:`setuptools` in 2004, whereas the wheel - format was introduced by :pep:`427` in 2012. - -* Wheel has an :doc:`official standard specification - `. Egg did not. - -* Wheel is a :term:`distribution ` format, i.e a packaging - format. [#wheel-importable]_ Egg was both a distribution format and a runtime - installation format (if left zipped), and was designed to be importable. - -* Wheel archives do not include ``.pyc`` files. Therefore, when the distribution - only contains Python files (i.e. no compiled extensions), and is compatible - with Python 2 and 3, it's possible for a wheel to be "universal", similar to - an :term:`sdist `. - -* Wheel uses standard :ref:`.dist-info directories - `. Egg used ``.egg-info``. - -* Wheel has a :ref:`richer file naming convention `. A - single wheel archive can indicate its compatibility with a number of Python - language versions and implementations, ABIs, and system architectures. - -* Wheel is versioned. Every wheel file contains the version of the wheel - specification and the implementation that packaged it. - -* Wheel is internally organized by `sysconfig path type - `_, - therefore making it easier to convert to other formats. - -------------------------------------------------------------------------------- .. [#core-metadata-format] This format is email-based. Although this would @@ -181,13 +140,6 @@ Here's a breakdown of the important differences between wheel and egg. understood by the build backend, typically ``[project]`` in ``pyproject.toml``, and translated by the build backend into ``PKG-INFO``. -.. [#wheel-importable] Circumstantially, in some cases, wheels can be used - as an importable runtime format, although :ref:`this is not officially supported - at this time `. - - - .. _pip-pypi: https://pypi.org/project/pip/23.3.1/#files .. _pypi: https://pypi.org -.. _pypi-eggs-deprecation: https://blog.pypi.org/posts/2023-06-26-deprecate-egg-uploads/ .. _pypy: https://pypy.org diff --git a/source/glossary.rst b/source/glossary.rst index aac96b1015..94de2b871e 100644 --- a/source/glossary.rst +++ b/source/glossary.rst @@ -106,8 +106,10 @@ Glossary Egg A :term:`Built Distribution` format introduced by :ref:`setuptools`, - which has been replaced by :term:`Wheel`. For details, see - :ref:`egg-format`. + which has been replaced by :term:`Wheel`. See :pep:`715` for the removal + of egg uploads from PyPI, and + :doc:`The Internal Structure of Python Eggs ` + for details of the format. Extension Module From 10a5c5dcabad9ae296571ca284b8b434a5bc6403 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 27 Nov 2026 17:48:07 +0100 Subject: [PATCH 4/7] Clean up discussion page "install_requires vs requirements files" This is outdated content that we decided to clean up, see issue 2170. It's referenced regularly as noted on that issue, so keep a stub with forward links to replacement content as an orphan page. --- source/contribute.rst | 2 +- source/discussions/index.rst | 1 - .../install-requires-vs-requirements.rst | 91 +++---------------- 3 files changed, 12 insertions(+), 82 deletions(-) diff --git a/source/contribute.rst b/source/contribute.rst index 112643d98c..4d4628fe50 100644 --- a/source/contribute.rst +++ b/source/contribute.rst @@ -61,7 +61,7 @@ Discussions Discussions are focused on understanding and information. These explore a specific topic without a specific goal in mind. :doc:`example discussion-style -document `. +document `. Specifications -------------- diff --git a/source/discussions/index.rst b/source/discussions/index.rst index ad729b8c75..424283af21 100644 --- a/source/discussions/index.rst +++ b/source/discussions/index.rst @@ -9,7 +9,6 @@ specific topic. If you're just trying to get stuff done, see :maxdepth: 1 versioning - install-requires-vs-requirements distribution-package-vs-import-package package-formats src-layout-vs-flat-layout diff --git a/source/discussions/install-requires-vs-requirements.rst b/source/discussions/install-requires-vs-requirements.rst index 99e1552b8b..821886c0bf 100644 --- a/source/discussions/install-requires-vs-requirements.rst +++ b/source/discussions/install-requires-vs-requirements.rst @@ -1,89 +1,20 @@ +:orphan: + .. _`install_requires vs requirements files`: ====================================== install_requires vs requirements files ====================================== +For documentation on these topics, see: -install_requires ----------------- - -``install_requires`` is a :ref:`setuptools` :file:`setup.py` keyword that -should be used to specify what a project **minimally** needs to run correctly. -When the project is installed by :ref:`pip`, this is the specification that is -used to install its dependencies. - -For example, if the project requires A and B, your ``install_requires`` would be -like so: - -:: - - install_requires=[ - 'A', - 'B' - ] - -Additionally, it's best practice to indicate any known lower or upper bounds. - -For example, it may be known, that your project requires at least v1 of 'A', and -v2 of 'B', so it would be like so: - -:: - - install_requires=[ - 'A>=1', - 'B>=2' - ] - -It may also be known that project 'A' introduced a change in its v2 -that breaks the compatibility of your project with v2 of 'A' and later, -so it makes sense to not allow v2: - -:: - - install_requires=[ - 'A>=1,<2', - 'B>=2' - ] - -It is not considered best practice to use ``install_requires`` to pin -dependencies to specific versions, or to specify sub-dependencies -(i.e. dependencies of your dependencies). This is overly-restrictive, and -prevents the user from gaining the benefit of dependency upgrades. - -Lastly, it's important to understand that ``install_requires`` is a listing of -"Abstract" requirements, i.e just names and version restrictions that don't -determine where the dependencies will be fulfilled from (i.e. from what -index or source). The where (i.e. how they are to be made "Concrete") is to -be determined at install time using :ref:`pip` options. [1]_ - - -Requirements files ------------------- - -:ref:`Requirements Files ` described most simply, are -just a list of :ref:`pip:pip install` arguments placed into a file. - -Whereas ``install_requires`` defines the dependencies for a single project, -:ref:`Requirements Files ` are often used to define -the requirements for a complete Python environment. - -Whereas ``install_requires`` requirements are minimal, requirements files -often contain an exhaustive listing of pinned versions for the purpose of -achieving :ref:`repeatable installations ` of a complete -environment. - -Whereas ``install_requires`` requirements are "Abstract", i.e. not associated -with any particular index, requirements files often contain pip -options like ``--index-url`` or ``--find-links`` to make requirements -"Concrete", i.e. associated with a particular index or directory of -packages. [1]_ - -Whereas ``install_requires`` metadata is automatically analyzed by pip during an -install, requirements files are not, and only are used when a user specifically -installs them using ``python -m pip install -r``. +* ``install_requires``: `Declaring required dependency`_ in the setuptools documentation. +* :file:`requirements.txt`: `Requirements File Format`_ in the pip documentation. ----- +This page previously explained abstract versus concrete requirements. For an +explanation of that distinction, see `setup.py vs requirements.txt`_ by Donald +Stufft. -.. [1] For more on "Abstract" vs "Concrete" requirements, see - https://caremad.io/posts/2013/07/setup-vs-requirement/. +.. _Declaring required dependency: https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#declaring-required-dependency +.. _Requirements File Format: https://pip.pypa.io/en/stable/reference/requirements-file-format/ +.. _setup.py vs requirements.txt: https://caremad.io/posts/2013/07/setup-vs-requirement/ From 793fca19fcd8c1c71bc3a91a56dce888604b10ef Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 27 Nov 2026 18:19:40 +0100 Subject: [PATCH 5/7] Remove page status and date from "Supporting downstream packaging" This is not-very-useful boilerplate, and it's incomplete at that. This page was done, and is still up to date. --- source/discussions/downstream-packaging.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/discussions/downstream-packaging.rst b/source/discussions/downstream-packaging.rst index 18b02c232f..128db9a1be 100644 --- a/source/discussions/downstream-packaging.rst +++ b/source/discussions/downstream-packaging.rst @@ -4,9 +4,6 @@ Supporting downstream packaging =============================== -:Page Status: Draft -:Last Reviewed: 2025-? - While PyPI and the Python packaging tools such as :ref:`pip` are the primary means of distributing Python packages, they are also often made available as part of other packaging ecosystems. These repackaging efforts are collectively called From c5de15c4bd592c7b1f372446142b2e875e1f1830 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 27 Nov 2026 18:24:53 +0100 Subject: [PATCH 6/7] Remove guide "Dropping support for older Python versions" This content was all obsolete, this is now a single `requires-python` one-liner which is covered in the "Writing your pyproject.toml" guide. --- source/conf.py | 1 + .../guides/dropping-older-python-versions.rst | 137 ------------------ source/guides/section-build-and-publish.rst | 1 - 3 files changed, 1 insertion(+), 138 deletions(-) delete mode 100644 source/guides/dropping-older-python-versions.rst diff --git a/source/conf.py b/source/conf.py index 24f7a5b7bb..84057d853b 100644 --- a/source/conf.py +++ b/source/conf.py @@ -287,6 +287,7 @@ def fix_notfound_links(app, doctree, docname): # Internal redirects, made relative for the current builder (html or dirhtml) internal_redirects = { + "guides/dropping-older-python-versions": "guides/writing-pyproject-toml", "guides/single-sourcing-package-version": "discussions/single-source-version", } diff --git a/source/guides/dropping-older-python-versions.rst b/source/guides/dropping-older-python-versions.rst deleted file mode 100644 index bf1bb02396..0000000000 --- a/source/guides/dropping-older-python-versions.rst +++ /dev/null @@ -1,137 +0,0 @@ -.. _`Dropping support for older Python versions`: - -========================================== -Dropping support for older Python versions -========================================== - -The ability to drop support for older Python versions is enabled by the standard :ref:`core-metadata` 1.2 specification via the :ref:`"Requires-Python" ` attribute. - -Metadata 1.2+ installers, such as Pip, will adhere to this specification by matching the current Python runtime and comparing it with the required version -in the package metadata. If they do not match, it will attempt to install the last package distribution that supported that Python runtime. - -This mechanism can be used to drop support for older Python versions, by amending the ``Requires-Python`` attribute in the package metadata. - -Requirements ------------- - -This workflow requires that the user installing the package uses Pip [#]_, or another installer that supports the Metadata 1.2 specification. - -Dealing with the universal wheels ---------------------------------- - -Traditionally, :ref:`setuptools` projects providing Python code that is semantically -compatible with both Python 2 and Python 3, produce :term:`wheels -` that have a ``py2.py3`` tag in their names. When dropping -support for Python 2, it is important not to forget to change this tag -to just ``py3``. It is often configured within :file:`setup.cfg` under -the ``[bdist_wheel]`` section by setting ``universal = 1``. - -If you use this method, either remove this option or section, or -explicitly set ``universal`` to ``0``: - -.. code-block:: ini - - # setup.cfg - - [bdist_wheel] - universal = 0 # Make the generated wheels have "py3" tag - -.. hint:: - - Regarding :ref:`deprecated ` direct ``setup.py`` invocations, - passing the ``--universal`` flag on the command line could override this setting. - -Defining the Python version required ------------------------------------- - -1. Install twine -~~~~~~~~~~~~~~~~ - -Ensure that you have twine available at its latest version. -Steps: - -.. tab:: Unix/macOS - - .. code-block:: bash - - python3 -m pip install --upgrade twine - -.. tab:: Windows - - .. code-block:: bat - - py -m pip install --upgrade twine - -2. Specify the version ranges for supported Python distributions -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Set the version ranges declaring which Python distributions are supported -within your project's :file:`pyproject.toml`. The :ref:`requires-python` configuration field -corresponds to the :ref:`Requires-Python ` core metadata field: - -.. code-block:: toml - - [build-system] - ... - - [project] - requires-python = ">= 3.8" # At least Python 3.8 - -You can specify version ranges and exclusion rules (complying with the :ref:`version-specifiers` specification), -such as at least Python 3.9. Or, at least Python 3.7 and beyond, skipping the 3.7.0 and 3.7.1 point releases: - -.. code-block:: toml - - requires-python = ">= 3.9" - requires-python = ">= 3.7, != 3.7.0, != 3.7.1" - - -If using the :ref:`setuptools` build backend, consult the `dependency-management`_ documentation for more options. - -.. caution:: - Avoid adding upper bounds to the version ranges, e.g. ``">= 3.8, < 3.10"``. Doing so can cause different errors - and version conflicts. See the `discourse-discussion`_ for more information. - -3. Validating the Metadata before publishing -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Within a Python source package (the zip or the tar-gz file you download) is a text file called PKG-INFO. - -This file is generated by the :term:`build backend ` when it generates the source package. -The file contains a set of keys and values defined by the :ref:`Core Metadata specification `. - -You can see the contents of the generated file like this: - -.. code-block:: bash - - tar xfO dist/my-package-1.0.0.tar.gz my-package-1.0.0/PKG-INFO - -Validate that the following is in place, before publishing the package: - -- If you have upgraded correctly, the ``Metadata-Version`` value should be 1.2 or higher. -- The ``Requires-Python`` field is set and matches your specification in the configuration file. - -4. Publishing the package -~~~~~~~~~~~~~~~~~~~~~~~~~ - -Proceed as suggested in the :doc:`packaging tutorial `. - -Dropping a Python version -------------------------- - -In principle, at least metadata support for Python versions should be kept as long as possible, because -once that has been dropped, people still depending on a version will be forced to downgrade. -If however supporting a specific version becomes a blocker for a new feature or other issues occur, the metadata -``Requires-Python`` should be amended. Of course this also depends on whether the project needs to be stable and -well-covered for a wider range of users. - -Each version compatibility change should have its own release. - -.. tip:: - - When dropping a Python version, it might also be rewarding to upgrade the project's code syntax generally, apart from updating the versions used in visible places (like the testing environment). Tools like :pypi:`pyupgrade` or `ruff `_ can automate some of this work. - -.. _discourse-discussion: https://discuss.python.org/t/requires-python-upper-limits/12663 -.. _dependency-management: https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#python-requirement - -.. [#] Support for the Metadata 1.2 specification has been added in Pip 9.0. diff --git a/source/guides/section-build-and-publish.rst b/source/guides/section-build-and-publish.rst index 6bbd776717..250171b603 100644 --- a/source/guides/section-build-and-publish.rst +++ b/source/guides/section-build-and-publish.rst @@ -6,7 +6,6 @@ Building and Publishing :titlesonly: writing-pyproject-toml - dropping-older-python-versions packaging-binary-extensions packaging-namespace-packages creating-command-line-tools From c7beebc5c29b0b67b527729791cdf8af32e20efc Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 27 Nov 2026 18:34:34 +0100 Subject: [PATCH 7/7] Clean up "How to modernize a setup.py based project?" page See issue 2170. Leave as an orphan and redirect to the relevant setuptools documentation page. --- source/guides/modernize-setup-py-project.rst | 245 +------------------ source/guides/section-build-and-publish.rst | 1 - 2 files changed, 5 insertions(+), 241 deletions(-) diff --git a/source/guides/modernize-setup-py-project.rst b/source/guides/modernize-setup-py-project.rst index a1a8ff0556..e73ebfbdaf 100644 --- a/source/guides/modernize-setup-py-project.rst +++ b/source/guides/modernize-setup-py-project.rst @@ -1,3 +1,5 @@ +:orphan: + .. _modernize-setup-py-project: @@ -5,244 +7,7 @@ How to modernize a ``setup.py`` based project? ============================================== +See `Transitioning from setup.py to declarative config`_ in the setuptools +documentation. -Should ``pyproject.toml`` be added? -=================================== - -A :term:`pyproject.toml` file is strongly recommended. -The presence of a :file:`pyproject.toml` file itself does not bring much. [#]_ -What is actually strongly recommended is the ``[build-system]`` table in :file:`pyproject.toml`. - -.. [#] Note that it has influence on the build isolation feature of pip, - see below. - - -Should ``setup.py`` be deleted? -=============================== - -No, :file:`setup.py` can exist in a modern :ref:`setuptools` based project. -The :term:`setup.py` file is a valid configuration file for setuptools -that happens to be written in Python. -However, the following commands are deprecated and **MUST NOT** be run anymore, -and their recommended replacement commands should be used instead: - -+---------------------------------+----------------------------------------+ -| Deprecated | Recommendation | -+=================================+========================================+ -| ``python setup.py install`` | ``python -m pip install .`` | -+---------------------------------+----------------------------------------+ -| ``python setup.py develop`` | ``python -m pip install --editable .`` | -+---------------------------------+----------------------------------------+ -| ``python setup.py sdist`` | ``python -m build`` | -+---------------------------------+ | -| ``python setup.py bdist_wheel`` | | -+---------------------------------+----------------------------------------+ - - -For more details: - -* :ref:`setup-py-deprecated` - - -Where to start? -=============== - -The :term:`project` must contain a :file:`pyproject.toml` file at the root of its source tree -that contains a ``[build-system]`` table like so: - -.. code:: toml - - [build-system] - requires = ["setuptools"] - build-backend = "setuptools.build_meta" - - -This is the standardized method of letting :term:`build frontends ` know -that :ref:`setuptools` is the :term:`build backend ` for this project. - -Note that the presence of a :file:`pyproject.toml` file (even if empty) -triggers :ref:`pip` to change its default behavior to use *build isolation*. - -For more details: - -* :ref:`pyproject-guide-build-system-table` -* :ref:`pyproject-build-system-table` -* :doc:`pip:reference/build-system` - - -How to handle additional build-time dependencies? -================================================= - -On top of setuptools itself, -if :file:`setup.py` depends on other third-party libraries (outside of Python's standard library), -those must be listed in the ``requires`` list of the ``[build-system]`` table, -so that the build frontend knows to install them -when building the :term:`distributions `. - -For example, a :file:`setup.py` file such as this: - -.. code:: python - - import setuptools - import some_build_toolkit # comes from the `some-build-toolkit` library - - def get_version(): - version = some_build_toolkit.compute_version() - return version - - setuptools.setup( - name="my-project", - version=get_version(), - ) - - -requires a :file:`pyproject.toml` file like this (:file:`setup.py` stays unchanged): - -.. code:: toml - - [build-system] - requires = [ - "setuptools", - "some-build-toolkit", - ] - build-backend = "setuptools.build_meta" - - -For more details: - -* :ref:`pyproject-build-system-table` - - -What is the build isolation feature? -==================================== - -Build frontends typically create an ephemeral virtual environment -where they install only the build dependencies (and their dependencies) -that are listed under ``build-system.requires`` -and trigger the build in that environment. - -For some projects this isolation is unwanted and it can be deactivated as follows: - -* ``python -m build --no-isolation`` -* ``python -m pip install --no-build-isolation`` - -For more details: - -* :doc:`pip:reference/build-system` - - -How to handle packaging metadata? -================================= - -All static metadata can optionally be moved to a ``[project]`` table in :file:`pyproject.toml`. - -For example, a :file:`setup.py` file such as this: - -.. code:: python - - import setuptools - - setuptools.setup( - name="my-project", - version="1.2.3", - ) - - -can be entirely replaced by a :file:`pyproject.toml` file like this: - -.. code:: toml - - [build-system] - requires = ["setuptools"] - build-backend = "setuptools.build_meta" - - [project] - name = "my-project" - version = "1.2.3" - - -Read :ref:`pyproject-project-table` for the full specification -of the content allowed in the ``[project]`` table. - - -How to handle dynamic metadata? -=============================== - -If some packaging metadata fields are not static -they need to be listed as ``dynamic`` in this ``[project]`` table. - -For example, a :file:`setup.py` file such as this: - -.. code:: python - - import setuptools - import some_build_toolkit - - def get_version(): - version = some_build_toolkit.compute_version() - return version - - setuptools.setup( - name="my-project", - version=get_version(), - ) - - -can be modernized as follows: - -.. code:: toml - - [build-system] - requires = [ - "setuptools", - "some-build-toolkit", - ] - build-backend = "setuptools.build_meta" - - [project] - name = "my-project" - dynamic = ["version"] - - -.. code:: python - - import setuptools - import some_build_toolkit - - def get_version(): - version = some_build_toolkit.compute_version() - return version - - setuptools.setup( - version=get_version(), - ) - - -For more details: - -* :ref:`declaring-project-metadata-dynamic` - - -What if something that can not be changed expects a ``setup.py`` file? -====================================================================== - -For example, a process exists that can not be changed easily -and it needs to execute a command such as ``python setup.py --name``. - -It is perfectly fine to leave a :file:`setup.py` file in the project source tree -even after all its content has been moved to :file:`pyproject.toml`. -This file can be as minimalistic as this: - -.. code:: python - - import setuptools - - setuptools.setup() - - -Where to read more about this? -============================== - -* :ref:`pyproject-toml-spec` -* :doc:`pip:reference/build-system` -* :doc:`setuptools:build_meta` +.. _Transitioning from setup.py to declarative config: https://setuptools.pypa.io/en/latest/userguide/quickstart.html#transitioning-from-setup-py-to-declarative-config diff --git a/source/guides/section-build-and-publish.rst b/source/guides/section-build-and-publish.rst index 250171b603..4eeee90d68 100644 --- a/source/guides/section-build-and-publish.rst +++ b/source/guides/section-build-and-publish.rst @@ -13,5 +13,4 @@ Building and Publishing using-testpypi making-a-pypi-friendly-readme publishing-package-distribution-releases-using-github-actions-ci-cd-workflows - modernize-setup-py-project licensing-examples-and-user-scenarios