From 7336e9d1513009d36f64734f4137808dfe84e5fb Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 15 Jul 2022 08:36:59 -0700 Subject: [PATCH 1/8] build/pkgs/sagelib/spkg-install: Remove installed sage/__init__.py --- build/pkgs/sagelib/spkg-install | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/pkgs/sagelib/spkg-install b/build/pkgs/sagelib/spkg-install index 4ae18e5a42f..c4e59541d4d 100755 --- a/build/pkgs/sagelib/spkg-install +++ b/build/pkgs/sagelib/spkg-install @@ -38,6 +38,7 @@ export SAGE_SHARE=/doesnotexist # export SAGE_DOC=/doesnotexist SITEPACKAGESDIR=$(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])') + if [ "$SAGE_EDITABLE" = yes ]; then # In an incremental build, we may need to uninstall old versions installed by distutils # under the old distribution name "sage" (before #30912, which switched to setuptools @@ -46,6 +47,9 @@ if [ "$SAGE_EDITABLE" = yes ]; then (cd "$SITEPACKAGESDIR" && rm -rf sage sage_setup sage-[1-9]*.egg-info sage-[1-9]*.dist-info) time python3 -m pip install --verbose --no-deps --no-index --no-build-isolation --isolated --editable . || exit 1 else + # Make sure that an installed old version of sagelib in which sage is an ordinary package + # does not shadow the namespace package sage during the build. + (cd "$SITEPACKAGESDIR" && rm -f sage/__init__.py) # Likewise, we should remove the egg-link that may have been installed previously. (cd "$SITEPACKAGESDIR" && rm -f sagemath-standard.egg-link) time python3 -u setup.py --no-user-cfg build install || exit 1 From f447a11cd0b3aad3b5b638902a345a92c7723380 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 15 Jul 2022 08:37:10 -0700 Subject: [PATCH 2/8] src/sage/__init__.py: Remove --- src/sage/__init__.py | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 src/sage/__init__.py diff --git a/src/sage/__init__.py b/src/sage/__init__.py deleted file mode 100644 index 6ea8b846de3..00000000000 --- a/src/sage/__init__.py +++ /dev/null @@ -1,34 +0,0 @@ -# Do not add anything to this file. -# It will be removed soon in order to turn 'sage' into a native namespace package. -# See https://trac.sagemath.org/ticket/29705 - - - -# Deprecated leftover of monkey-patching inspect.isfunction() to support Cython functions. -# We cannot use lazy_import for the deprecation here. -def isfunction(obj): - """ - Check whether something is a function. - - This is a variant of ``inspect.isfunction``: - We assume that anything which has a genuine ``__code__`` - attribute (not using ``__getattr__`` overrides) is a function. - This is meant to support Cython functions. - - This function is deprecated. Most uses of ``isfunction`` - can be replaced by ``callable``. - - EXAMPLES:: - - sage: from sage import isfunction - sage: def f(): pass - sage: isfunction(f) - doctest:warning... - DeprecationWarning: sage.isfunction is deprecated; use callable or sage.misc.sageinspect.is_function_or_cython_function instead - See https://trac.sagemath.org/32479 for details. - True - """ - from sage.misc.superseded import deprecation - deprecation(32479, "sage.isfunction is deprecated; use callable or sage.misc.sageinspect.is_function_or_cython_function instead") - from sage.misc.sageinspect import is_function_or_cython_function - return is_function_or_cython_function(obj) From 01f914312302f1ca01aa90a4438e1eb51fdbc239 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 15 Jul 2022 09:29:13 -0700 Subject: [PATCH 3/8] src/sage_setup: Fix for namespace package sage --- src/sage_setup/find.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sage_setup/find.py b/src/sage_setup/find.py index 28467135c12..5cec2c4ee44 100644 --- a/src/sage_setup/find.py +++ b/src/sage_setup/find.py @@ -274,8 +274,9 @@ def _cythonized_dir(src_dir=None, editable_install=None): if src_dir is None: src_dir = SAGE_SRC src_dir = Path(src_dir) - sage = import_module('sage') - d = Path(sage.__file__).resolve().parent.parent + # sage.cpython is an ordinary package, so it has __file__ + sage_cpython = import_module('sage.cpython') + d = Path(sage_cpython.__file__).resolve().parent.parent.parent editable_install = d == src_dir.resolve() if editable_install: # Editable install: Cython generates files in the source tree @@ -390,7 +391,7 @@ def installed_files_by_module(site_packages, modules=('sage',)): EXAMPLES:: - sage: site_packages = os.path.dirname(os.path.dirname(sage.__file__)) + sage: site_packages = os.path.dirname(os.path.dirname(os.path.dirname(sage.cpython.__file__))) sage: from sage_setup.find import installed_files_by_module sage: files_by_module = installed_files_by_module(site_packages) sage: (f,) = files_by_module['sage.structure.sage_object']; f From 9627219b021d4f23ef044091dc7e8115da6dfafe Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 15 Jul 2022 09:34:28 -0700 Subject: [PATCH 4/8] src/sage/misc/edit_module.py: Update doctest --- src/sage/misc/edit_module.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/misc/edit_module.py b/src/sage/misc/edit_module.py index 634af340d88..5c1dfa6d7ae 100644 --- a/src/sage/misc/edit_module.py +++ b/src/sage/misc/edit_module.py @@ -75,8 +75,8 @@ def file_and_line(obj): EXAMPLES:: sage: import sage.misc.edit_module as edit_module - sage: edit_module.file_and_line(sage) - ('...sage/__init__.py', 0) + sage: edit_module.file_and_line(sage.cpython) + ('...sage/cpython/__init__.py', 0) The following tests against a bug that was fixed in :trac:`11298`:: From e884c9efe7c88d07c76e3614d68a647a5d0053cf Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 15 Jul 2022 09:39:47 -0700 Subject: [PATCH 5/8] src/sage/misc/sageinspect.py: Update doctest --- src/sage/misc/sageinspect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index 13f0fc1bec3..9d0c255aff5 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -2599,7 +2599,8 @@ def __internal_tests(): sage: sage_getdoc(None) '' - sage: sage_getsource(sage) + sage: import sage.all__sagemath_objects + sage: sage_getsource(sage.all__sagemath_objects) '...all...' A cython function with default arguments (one of which is a string):: From 7a0ff3f91909d6ca2645497a6af856093650b515 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Jul 2022 08:14:42 -0700 Subject: [PATCH 6/8] src/sage/all.py: Restore sage.isfunction as a LazyImport --- src/sage/all.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sage/all.py b/src/sage/all.py index 8c2514ecd96..a1a740a0018 100644 --- a/src/sage/all.py +++ b/src/sage/all.py @@ -274,6 +274,11 @@ def quit_sage(verbose=True): # sys.settrace(poison_currRing) +# Deprecated leftover of monkey-patching inspect.isfunction() to support Cython functions. +lazy_import('sage.misc.sageinspect', 'is_function_or_cython_function', + as_='isfunction', namespace=sage.__dict__, deprecation=32479) + + # Set a new random number seed as the very last thing # (so that printing initial_seed() and using that seed # in set_random_seed() will result in the same sequence you got at From adb89ffc5793d8491a3915ddb9a4b09b43c4958f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 18 Jul 2022 10:31:13 -0700 Subject: [PATCH 7/8] src/sage/misc/lazy_import.pyx: Improve deprecation message when as_ is in use --- src/sage/misc/lazy_import.pyx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sage/misc/lazy_import.pyx b/src/sage/misc/lazy_import.pyx index 97055afb01a..35f09ba3063 100644 --- a/src/sage/misc/lazy_import.pyx +++ b/src/sage/misc/lazy_import.pyx @@ -255,18 +255,19 @@ cdef class LazyImport(): raise FeatureNotPresentError(self._feature, reason=f'Importing {self._name} failed: {e}') raise - name = self._as_name if self._deprecation is not None: from sage.misc.superseded import deprecation_cython as deprecation try: trac_number, message = self._deprecation except TypeError: trac_number = self._deprecation - message = ('\nImporting {name} from here is deprecated. ' + - 'If you need to use it, please import it directly from' + - ' {module_name}').format(name=name, module_name=self._module) + import_command = f'from {self._module} import {self._name}' + if self._as_name != self._name: + import_command += f' as {self._as_name}' + message = f'\nImporting {self._as_name} from here is deprecated; please use "{import_command}" instead.' deprecation(trac_number, message) # Replace the lazy import in the namespace by the actual object + name = self._as_name if self._namespace is not None: if self._namespace.get(name) is self: self._namespace[name] = self._object @@ -1028,7 +1029,7 @@ def lazy_import(module, names, as_=None, *, sage: lazy_import('sage.all', 'Qp', 'my_Qp', deprecation=14275) sage: my_Qp(5) doctest:...: DeprecationWarning: - Importing my_Qp from here is deprecated. If you need to use it, please import it directly from sage.all + Importing my_Qp from here is deprecated; please use "from sage.all import Qp as my_Qp" instead. See http://trac.sagemath.org/14275 for details. 5-adic Field with capped relative precision 20 From a77b97142827021e5a21d0b1c2b87865c3e24223 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 18 Jul 2022 21:21:36 -0700 Subject: [PATCH 8/8] Update doctest output for changed lazy_import deprecation warnings --- src/sage/functions/other.py | 4 ++-- src/sage/groups/matrix_gps/homset.py | 5 ++--- src/sage/modular/modform/find_generators.py | 4 ++-- src/sage/rings/all.py | 9 ++++++--- src/sage/schemes/hyperelliptic_curves/all.py | 12 ++++++++---- .../graphique_doctest.py | 4 ++-- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/sage/functions/other.py b/src/sage/functions/other.py index 19f95496077..04237301e62 100644 --- a/src/sage/functions/other.py +++ b/src/sage/functions/other.py @@ -7,8 +7,8 @@ sage: from sage.functions.other import beta sage: beta(x, x) - doctest:...: DeprecationWarning: - Importing beta from here is deprecated. If you need to use it, please import it directly from sage.functions.gamma + doctest:warning...: DeprecationWarning: + Importing beta from here is deprecated; please use "from sage.functions.gamma import beta" instead. See http://trac.sagemath.org/24411 for details. beta(x, x) """ diff --git a/src/sage/groups/matrix_gps/homset.py b/src/sage/groups/matrix_gps/homset.py index 274047ad2e4..46d8e225582 100644 --- a/src/sage/groups/matrix_gps/homset.py +++ b/src/sage/groups/matrix_gps/homset.py @@ -30,9 +30,8 @@ def is_MatrixGroupHomset(x): sage: from sage.groups.matrix_gps.homset import is_MatrixGroupHomset sage: is_MatrixGroupHomset(4) doctest:...: DeprecationWarning: - Importing MatrixGroupHomset from here is deprecated. - If you need to use it, please import it directly from - sage.groups.libgap_morphism + Importing MatrixGroupHomset from here is deprecated; please use + "from sage.groups.libgap_morphism import GroupHomset_libgap as MatrixGroupHomset" instead. See https://trac.sagemath.org/25444 for details. False diff --git a/src/sage/modular/modform/find_generators.py b/src/sage/modular/modform/find_generators.py index 637b3520e61..e851bcebfb3 100644 --- a/src/sage/modular/modform/find_generators.py +++ b/src/sage/modular/modform/find_generators.py @@ -21,7 +21,7 @@ sage: find_generators(ModularFormsRing(1)) doctest:warning ... - DeprecationWarning: Importing find_generators from here is deprecated. If you need to use it, please import it directly from sage.modular.modform.ring + DeprecationWarning: Importing find_generators from here is deprecated; please use "from sage.modular.modform.ring import find_generators" instead. See https://trac.sagemath.org/31559 for details. [(4, 1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + 60480*q^6 + 82560*q^7 + 140400*q^8 + 181680*q^9 + O(q^10)), @@ -45,7 +45,7 @@ sage: _span_of_forms_in_weight(forms, 12, prec=5) doctest:warning ... - DeprecationWarning: Importing _span_of_forms_in_weight from here is deprecated. If you need to use it, please import it directly from sage.modular.modform.ring + DeprecationWarning: Importing _span_of_forms_in_weight from here is deprecated; please use "from sage.modular.modform.ring import _span_of_forms_in_weight" instead. See https://trac.sagemath.org/31559 for details. Vector space of degree 5 and dimension 2 over Rational Field Basis matrix: diff --git a/src/sage/rings/all.py b/src/sage/rings/all.py index 6d62ee8f5b5..6e6b81eab7b 100644 --- a/src/sage/rings/all.py +++ b/src/sage/rings/all.py @@ -6,19 +6,22 @@ sage: PowerSeries doctest:warning...: DeprecationWarning: - Importing PowerSeries from here is deprecated. If you need to use it, please import it directly from sage.rings.power_series_ring_element + Importing PowerSeries from here is deprecated; + please use "from sage.rings.power_series_ring_element import PowerSeries" instead. See https://trac.sagemath.org/33602 for details. ... sage: PuiseuxSeries doctest:warning...: DeprecationWarning: - Importing PuiseuxSeries from here is deprecated. If you need to use it, please import it directly from sage.rings.puiseux_series_ring_element + Importing PuiseuxSeries from here is deprecated; + please use "from sage.rings.puiseux_series_ring_element import PuiseuxSeries" instead. See https://trac.sagemath.org/33602 for details. ... sage: LaurentSeries doctest:warning...: DeprecationWarning: - Importing LaurentSeries from here is deprecated. If you need to use it, please import it directly from sage.rings.laurent_series_ring_element + Importing LaurentSeries from here is deprecated; + please use "from sage.rings.laurent_series_ring_element import LaurentSeries" instead. See https://trac.sagemath.org/33602 for details. ... """ diff --git a/src/sage/schemes/hyperelliptic_curves/all.py b/src/sage/schemes/hyperelliptic_curves/all.py index fffc78cd9a4..1228f1a6fad 100644 --- a/src/sage/schemes/hyperelliptic_curves/all.py +++ b/src/sage/schemes/hyperelliptic_curves/all.py @@ -4,28 +4,32 @@ sage: igusa_clebsch_invariants doctest:warning...: DeprecationWarning: - Importing igusa_clebsch_invariants from here is deprecated. If you need to use it, please import it directly from sage.schemes.hyperelliptic_curves.invariants + Importing igusa_clebsch_invariants from here is deprecated; + please use "from sage.schemes.hyperelliptic_curves.invariants import igusa_clebsch_invariants" instead. See https://trac.sagemath.org/28064 for details. ... sage: absolute_igusa_invariants_kohel doctest:warning...: DeprecationWarning: - Importing absolute_igusa_invariants_kohel from here is deprecated. If you need to use it, please import it directly from sage.schemes.hyperelliptic_curves.invariants + Importing absolute_igusa_invariants_kohel from here is deprecated; + please use "from sage.schemes.hyperelliptic_curves.invariants import absolute_igusa_invariants_kohel" instead. See https://trac.sagemath.org/28064 for details. ... sage: absolute_igusa_invariants_wamelen doctest:warning...: DeprecationWarning: - Importing absolute_igusa_invariants_wamelen from here is deprecated. If you need to use it, please import it directly from sage.schemes.hyperelliptic_curves.invariants + Importing absolute_igusa_invariants_wamelen from here is deprecated; + please use "from sage.schemes.hyperelliptic_curves.invariants import absolute_igusa_invariants_wamelen" instead. See https://trac.sagemath.org/28064 for details. ... sage: clebsch_invariants doctest:warning...: DeprecationWarning: - Importing clebsch_invariants from here is deprecated. If you need to use it, please import it directly from sage.schemes.hyperelliptic_curves.invariants + Importing clebsch_invariants from here is deprecated; + please use "from sage.schemes.hyperelliptic_curves.invariants import clebsch_invariants" instead. See https://trac.sagemath.org/28064 for details. ... """ diff --git a/src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py b/src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py index 5d3ff884c86..472b7167ac9 100644 --- a/src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py +++ b/src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py @@ -71,10 +71,10 @@ DeprecationWarning: the package sage.finance is deprecated See https://trac.sagemath.org/32427 for details. doctest:warning... - Importing finance from here is deprecated. If you need to use it, please import it directly from sage.finance + Importing finance from here is deprecated; please use "from sage.finance import all as finance" instead. See https://trac.sagemath.org/32427 for details. doctest:warning... - Importing TimeSeries from here is deprecated. If you need to use it, please import it directly from sage.stats.time_series + Importing TimeSeries from here is deprecated; please use "from sage.stats.time_series import TimeSeries" instead. See https://trac.sagemath.org/32427 for details. Graphics object consisting of 20 graphics primitives