Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
src/doc/en/developer/python_packaging.rst: Add remarks on reducing de…
Browse files Browse the repository at this point in the history
…pendencies
  • Loading branch information
mkoeppe committed Nov 22, 2021
1 parent ba0e4a8 commit 6c97779
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/doc/en/developer/python_packaging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ Cython module that must be linked with ``tdlib``,
can start to create these distributions. This is quite a mechanical
task.

*Reducing build-time dependencies:* Sometimes it is possible to
replace build-time dependencies of a Cython module on a library by a
runtime dependency. In other cases, it may be possible to split a
module that simultaneously depends on several libraries into smaller
modules, each of which has narrower dependencies.


Module-level runtime dependencies
---------------------------------

Expand All @@ -206,6 +213,23 @@ distribution -- which then must be declared as a run-time dependency.
*Declaring run-time dependencies:* These dependencies are declared in
``setup.cfg`` (generated from ``setup.cfg.m4``) as ``install_requires``.

*Reducing module-level run-time dependencies:*

- Avoid importing from ``sage.PAC.KAGE.all`` modules when
``sage.PAC.KAGE`` is a namespace package. For example, no Sage
library code should import from ``sage.rings.all``.

- Replace module-level imports by method-level imports. Note that
this comes with a small runtime overhead, which can become
noticeable if the method is called in tight inner loops.

- Sage provides the ``lazy_import`` mechanism. Lazy imports can be
declared at the module level, but the actual importing is only done
on demand. It is a runtime error at that time if the imported module
is not present. This can be convenient compared to local imports in
methods when the same imports are needed in several methods.


Other runtime dependencies
--------------------------

Expand All @@ -231,14 +255,6 @@ allows users to write, for example, ``pip install
sagemath-polyhedra[normaliz]`` instead of ``pip install
sagemath-polyhedra pynormaliz``.

Lazy module-level imports
-------------------------

Sage provides the ``lazy_import`` mechanism. Lazy imports can be
declared at the module level, but the actual importing is only done on
demand. It is a runtime error at that time if the imported module is
not present. This can be convenient compared to local imports in
methods when the same imports are needed in several methods.

Doctest-only dependencies
-------------------------
Expand Down

0 comments on commit 6c97779

Please sign in to comment.