Skip to content

Commit

Permalink
Trac #34187: Remove src/sage/__init__.py
Browse files Browse the repository at this point in the history
Follow-up from #33011.

Because of the complication described in #33011, we not only remove the
file from the source tree but also remove it from site-packages before
building sagelib.

Follow-up:
- make sagemath-standard, sage-setup depend on sagemath-environment

URL: https://trac.sagemath.org/34187
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Jul 28, 2022
2 parents 5bfd77d + a77b971 commit aae8d2d
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 61 deletions.
4 changes: 4 additions & 0 deletions build/pkgs/sagelib/spkg-install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
34 changes: 0 additions & 34 deletions src/sage/__init__.py

This file was deleted.

5 changes: 5 additions & 0 deletions src/sage/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/functions/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
Expand Down
5 changes: 2 additions & 3 deletions src/sage/groups/matrix_gps/homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/edit_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`::
Expand Down
11 changes: 6 additions & 5 deletions src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/sage/misc/sageinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,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)::
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modular/modform/find_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions src/sage/rings/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
...
"""
Expand Down
12 changes: 8 additions & 4 deletions src/sage/schemes/hyperelliptic_curves/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
...
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/sage_setup/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aae8d2d

Please sign in to comment.