Skip to content

Commit 8c5710d

Browse files
author
Matthias Koeppe
committed
src/doc/en/developer/packaging.rst: Add more material on version pinning etc. from sage-devel thread 'allow standard packages to be pip packages'
1 parent c3dfcbe commit 8c5710d

File tree

1 file changed

+79
-11
lines changed

1 file changed

+79
-11
lines changed

src/doc/en/developer/packaging.rst

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ and most Python-based packages will also have ``$(PYTHON_TOOLCHAIN)`` as
579579
an order-only dependency, which will ensure that fundamental packages such
580580
as ``pip`` and ``setuptools`` are available at the time of building the package.
581581
582-
The best way to install a Python-based package is to use ``pip``, in which
582+
The best way to install a ``normal`` Python-based package is to use ``pip``, in which
583583
case the ``spkg-install.in`` script template might just consist of
584584
585585
.. CODE-BLOCK:: bash
@@ -603,12 +603,15 @@ For example, the ``scipy`` ``spkg-check.in`` file contains the line
603603
604604
exec python3 spkg-check.py
605605
606-
Abstract requirements: The install-requires.txt file
607-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
606+
Abstract requirements: The ``install-requires.txt`` file
607+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
608608
609-
All normal Python packages and all wheel packages must have a file ``install-requires.txt``.
610-
If a Python package is available on PyPI, this file must contain the
611-
name of the package as it is known to PyPI.
609+
All ``normal`` Python packages and all ``wheel`` packages must have a file
610+
``install-requires.txt``. For ``pip`` packages, the file is optional; if
611+
it is missing, the ``requirements.txt`` file is used instead.
612+
613+
If a Python package is available on PyPI, the ``install-requires.txt`` file must
614+
contain the name of the package as it is known to PyPI.
612615
613616
Optionally,
614617
``install-requires.txt`` can encode version constraints (such as lower
@@ -660,11 +663,11 @@ Setting upper bounds to guard against incompatible future changes is
660663
a complex topic; see :trac:`33520`.
661664
662665
663-
Concrete (pinned) requirements: The package-version.txt file
664-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
666+
Concrete (pinned) requirements of ``normal``, ``wheel``, ``script`` packages: The ``package-version.txt`` file
667+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
665668
666-
Like normal non-Python packages, all normal Python packages and all wheel packages
667-
must have a file ``package-version.txt``.
669+
Like ``normal`` non-Python packages, all ``normal`` Python packages and all ``wheel`` packages
670+
must have a file ``package-version.txt``. For ``script`` Python packages, the file is optional.
668671
669672
Sage uses this version for two purposes:
670673
@@ -678,6 +681,69 @@ Sage uses this version for two purposes:
678681
the `pip User Guide <https://pip.pypa.io/en/stable/user_guide/#requirements-files>`_.
679682
680683
684+
Concrete requirements of ``pip`` packages: The ``requirements.txt`` file
685+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
686+
687+
In contrast to ``normal``, ``wheel``, and ``script`` packages, the
688+
``pip`` packages do not use a ``package-version.txt`` file.
689+
690+
Instead, the concrete requirements are set in a ``requirements.txt``
691+
file, which is passed directly to ``pip`` at installation time.
692+
693+
The ``requirements.txt`` file uses a very flexible format, defined
694+
in the `pip User Guide
695+
<https://pip.pypa.io/en/stable/user_guide/#requirements-files>`_.
696+
Through this format, the concrete requirements can either be
697+
pinned to a specific version, or set acceptable version ranges, or be
698+
entirely unconstrained. The format is even flexible enough to install
699+
several distribution packages at the same time, and to conditionalize
700+
on the operating system or Python version.
701+
702+
Pinning a version has the potential benefit of stability, as it can
703+
avoid retroactive breakage of the Sage distribution by new,
704+
incompatible versions, and can also help achieve reproducibility
705+
of computations.
706+
707+
The cost is that updating the version requires
708+
work by at least two Sage developers: One who prepares a PR and one
709+
who reviews it. Moreover, when the package does not get the attention of
710+
developers who upgrade it, there is the potential risk of missing out
711+
on bugfixes made in newer versions, or missing out on features in
712+
major new versions.
713+
714+
Not pinning the version has the obvious potential benefit of always
715+
being up to date, as ``pip`` contacts the index server (PyPI) to
716+
obtain and install the package. (Note that ``normal`` and ``wheel``
717+
packages are always pinned and do not even have access to the index
718+
server at the time of building and installing the package.)
719+
720+
But this dynamism also brings a risk
721+
of instability, either by the package itself being affected by bugs in
722+
a new version, or by breaking compatibility with Sage.
723+
724+
What policy is best for a package depends on various factors,
725+
including the development velocity and quality control that the
726+
upstream project uses, the interest by Sage developers in the package,
727+
the depth of integration in Sage, whether it affects the mathematics,
728+
etc.
729+
730+
731+
Note about dependencies of ``pip`` packages
732+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
733+
734+
Dependencies of a ``pip`` package do not need to be available as packages
735+
in the Sage distribution, as the package can pull some of its build-time and
736+
run-time dependencies directly from PyPI. That's a mild convenience for developers,
737+
and can be important if one wants to leave the version range wide open.
738+
739+
However, if a dependency is also a package of the Sage distribution,
740+
then we must declare this dependency. Otherwise, various errors
741+
can occur when building or upgrading. When new versions of ``pip``
742+
packages add dependencies that happen to be Sage packages, there is a
743+
separate source of instability.
744+
745+
746+
681747
.. _section-spkg-SPKG-txt:
682748
683749
The SPKG.rst file
@@ -1143,7 +1209,9 @@ For Python packages available from PyPI, you can use::
11431209
--type optional
11441210
11451211
This automatically downloads the most recent version from PyPI and also
1146-
obtains most of the necessary information by querying PyPI.
1212+
obtains most of the necessary information by querying PyPI. In particular,
1213+
the ``SPKG.rst`` file is created as a copy of the package's README file.
1214+
11471215
11481216
The ``dependencies`` file may need editing (watch out for warnings regarding
11491217
``--no-deps`` that Sage issues during installation of the package!).

0 commit comments

Comments
 (0)