Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Cython 3 implicit namespace package support #36228

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sage/algebras/quatalg/quaternion_algebra_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ from sage.matrix.matrix_space import MatrixSpace
from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense
from sage.matrix.matrix_rational_dense cimport Matrix_rational_dense

from .quaternion_algebra_element cimport QuaternionAlgebraElement_rational_field
from sage.algebras.quatalg.quaternion_algebra_element cimport QuaternionAlgebraElement_rational_field

from sage.libs.gmp.mpz cimport mpz_t, mpz_lcm, mpz_init, mpz_set, mpz_clear, mpz_init_set, mpz_mul, mpz_fdiv_q, mpz_cmp_si

Expand Down
2 changes: 1 addition & 1 deletion src/sage/arith/power.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ square-and-multiply algorithm.

from cysignals.signals cimport sig_check

from .long cimport integer_check_long
from sage.arith.long cimport integer_check_long


cpdef generic_power(a, n) noexcept:
Expand Down
6 changes: 3 additions & 3 deletions src/sage/categories/action.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sage.structure.element cimport Element
from .morphism cimport Morphism
from .map cimport Map
from .functor cimport Functor
from sage.categories.morphism cimport Morphism
from sage.categories.map cimport Map
from sage.categories.functor cimport Functor

cdef class Action(Functor):
cdef readonly G
Expand Down
10 changes: 5 additions & 5 deletions src/sage/categories/action.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ AUTHOR:

from cpython.tuple cimport PyTuple_GET_ITEM

from .functor cimport Functor
from .morphism cimport Morphism
from .map cimport Map
from sage.categories.functor cimport Functor
from sage.categories.morphism cimport Morphism
from sage.categories.map cimport Map
from sage.structure.element cimport parent
from sage.structure.parent cimport Parent

from . import homset
from sage.categories import homset
from weakref import ref


Expand Down Expand Up @@ -91,7 +91,7 @@ cdef class Action(Functor):
:class:`Action` itself, but other classes may use it
"""
def __init__(self, G, S, is_left=True, op=None):
from .groupoid import Groupoid
from sage.categories.groupoid import Groupoid
Functor.__init__(self, Groupoid(G), category(S))
self.G = G
self.US = ref(S)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/functor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AUTHORS:
# https://www.gnu.org/licenses/
# ****************************************************************************

from . import category
from sage.categories import category


def _Functor_unpickle(Cl, D, domain, codomain):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/map.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AUTHORS:
# https://www.gnu.org/licenses/
# ****************************************************************************

from . import homset
from sage.categories import homset
import weakref
from sage.ext.stdsage cimport HAS_DICTIONARY
from sage.arith.power cimport generic_power
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/morphism.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sage.structure.element cimport Element
from .map cimport Map
from sage.categories.map cimport Map


cdef class Morphism(Map):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/morphism.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ cdef class CallMorphism(Morphism):
cdef class IdentityMorphism(Morphism):

def __init__(self, parent):
from .homset import Homset, Hom
from sage.categories.homset import Homset, Hom
if not isinstance(parent, Homset):
parent = Hom(parent, parent)
Morphism.__init__(self, parent)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/cpython/debug.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cdef extern from "Python.h":
cdef extern from "sage/cpython/debugimpl.c":
void _type_debug(PyTypeObject*)

from .getattr cimport AttributeErrorMessage
from sage.cpython.getattr cimport AttributeErrorMessage


# Determine subtype_traverse, subtype_clear, subtype_dealloc functions
Expand Down
2 changes: 1 addition & 1 deletion src/sage/cpython/getattr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Variants of getattr()

from cpython.object cimport PyObject, PyTypeObject, Py_TYPE, descrgetfunc

from .string cimport bytes_to_str
from sage.cpython.string cimport bytes_to_str

cdef extern from "Python.h":
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/cpython/wrapperdescr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Pure Python classes have normal methods, not slot wrappers::
# https://www.gnu.org/licenses/
# ****************************************************************************

from .string import bytes_to_str
from sage.cpython.string import bytes_to_str


def wrapperdescr_call(slotwrapper, self, *args, **kwds):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/data_structures/bitset.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from .bitset_base cimport bitset_t
from sage.data_structures.bitset_base cimport bitset_t

# Python layer over bitset_t
cdef class FrozenBitset:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/data_structures/bitset.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ linear in ``capacity``.
# http://www.gnu.org/licenses/
#*****************************************************************************

from .bitset_base cimport *
from sage.data_structures.bitset_base cimport *
from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE


Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_mod2_dense.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .matrix_dense cimport Matrix_dense
from sage.matrix.matrix_dense cimport Matrix_dense
from sage.libs.m4ri cimport *

cdef class Matrix_mod2_dense(Matrix_dense):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_sparse.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .matrix cimport Matrix
from sage.matrix.matrix cimport Matrix

cdef class Matrix_sparse(Matrix):
pass
2 changes: 1 addition & 1 deletion src/sage/misc/cachefunc.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .function_mangling cimport ArgumentFixer
from sage.misc.function_mangling cimport ArgumentFixer

cpdef dict_key(o) noexcept
cpdef cache_key(o) noexcept
Expand Down
6 changes: 3 additions & 3 deletions src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import os
import pickle
from warnings import warn
import inspect
from . import sageinspect
from sage.misc import sageinspect


# LazyImport.__repr__ uses try... except FeatureNotPresentError.
Expand Down Expand Up @@ -1137,7 +1137,7 @@ def save_cache_file():
sage: sage.misc.lazy_import.save_cache_file()
"""
from sage.misc.temporary_file import atomic_write
from .lazy_import_cache import get_cache_file
from sage.misc.lazy_import_cache import get_cache_file

global star_imports
if star_imports is None:
Expand Down Expand Up @@ -1180,7 +1180,7 @@ def get_star_imports(module_name):
"""
global star_imports
if star_imports is None:
from .lazy_import_cache import get_cache_file
from sage.misc.lazy_import_cache import get_cache_file
star_imports = {}
try:
with open(get_cache_file(), "rb") as cache_file:
Expand Down
20 changes: 12 additions & 8 deletions src/sage/misc/package_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,19 @@ def cython_namespace_package_support():

See https://github.com/cython/cython/issues/2918#issuecomment-991799049
"""
import Cython.Build.Dependencies
import Cython.Build.Cythonize
import Cython.Utils
orig_is_package_dir = Cython.Utils.is_package_dir
Cython.Utils.is_package_dir = Cython.Build.Cythonize.is_package_dir = Cython.Build.Dependencies.is_package_dir = Cython.Utils.cached_function(is_package_or_sage_namespace_package_dir)
try:
from Cython import __version__
if __version__[0] >= '3':
yield
finally:
Cython.Utils.is_package_dir = Cython.Build.Cythonize.is_package_dir = Cython.Build.Dependencies.is_package_dir = orig_is_package_dir
else:
import Cython.Build.Dependencies
import Cython.Build.Cythonize
import Cython.Utils
orig_is_package_dir = Cython.Utils.is_package_dir
Cython.Utils.is_package_dir = Cython.Build.Cythonize.is_package_dir = Cython.Build.Dependencies.is_package_dir = Cython.Utils.cached_function(is_package_or_sage_namespace_package_dir)
try:
yield
finally:
Cython.Utils.is_package_dir = Cython.Build.Cythonize.is_package_dir = Cython.Build.Dependencies.is_package_dir = orig_is_package_dir


def walk_packages(path=None, prefix='', onerror=None):
Expand Down
6 changes: 3 additions & 3 deletions src/sage/misc/persist.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import bz2
comp = zlib
comp_other = bz2

from .sage_unittest import TestSuite
from sage.misc.sage_unittest import TestSuite


# We define two global dictionaries `already_pickled` and
Expand Down Expand Up @@ -1237,7 +1237,7 @@ def db(name):

The database directory is ``$HOME/.sage/db``.
"""
from .misc import SAGE_DB
from sage.misc.misc import SAGE_DB
return load('%s/%s'%(SAGE_DB,name))


Expand All @@ -1250,5 +1250,5 @@ def db_save(x, name=None):
try:
x.db(name)
except AttributeError:
from .misc import SAGE_DB
from sage.misc.misc import SAGE_DB
save(x, '%s/%s'%(SAGE_DB,name))
2 changes: 1 addition & 1 deletion src/sage/misc/sage_timeit_class.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The ``timeit`` command
This uses the function :func:`~sage.misc.sage_timeit.sage_timeit`.
"""

from . import sage_timeit
from sage.misc import sage_timeit


class SageTimeit:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modular/modsym/heilbronn.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ cdef extern from "<math.h>":
float roundf(float x)

cimport sage.modular.modsym.p1list as p1list
from . import p1list
from sage.modular.modsym import p1list
cdef p1list.export export
export = p1list.export()

from .apply cimport Apply
from sage.modular.modsym.apply cimport Apply
cdef Apply PolyApply= Apply()

from sage.matrix.matrix_rational_dense cimport Matrix_rational_dense
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/pollack_stevens/dist.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ from sage.rings.infinity import Infinity

#from sage.libs.flint.ulong_extras cimport *

from .sigma0 import Sigma0
from sage.modular.pollack_stevens.sigma0 import Sigma0

cdef long overflow = 1 << (4 * sizeof(long) - 1)
cdef long underflow = -overflow
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/vector_mod2_dense.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .free_module_element cimport FreeModuleElement
from sage.modules.free_module_element cimport FreeModuleElement
from sage.libs.m4ri cimport mzd_t


Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/abc.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .ring cimport CommutativeRing, Field
from sage.rings.ring cimport CommutativeRing, Field

cdef class RealField(Field):

Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/complex_conversion.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .complex_double cimport ComplexDoubleElement
from .complex_mpfr cimport ComplexNumber
from sage.rings.complex_double cimport ComplexDoubleElement
from sage.rings.complex_mpfr cimport ComplexNumber
from sage.libs.mpfr cimport mpfr_get_d, MPFR_RNDN
from sage.libs.gsl.complex cimport GSL_SET_COMPLEX

Expand Down
Loading
Loading