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

Commit

Permalink
Merge #28925
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Dec 17, 2021
2 parents 7f9c9b0 + f5addb3 commit 464b0a5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/sage/doctest/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from sage.cpython.string import bytes_to_str
from sage.repl.load import load
from sage.misc.lazy_attribute import lazy_attribute
from sage.misc.namespace_package import is_package_or_sage_namespace_package_dir
from sage.misc.package_dir import is_package_or_sage_namespace_package_dir
from .parsing import SageDocTestParser
from .util import NestedName
from sage.structure.dynamic_class import dynamic_class
Expand Down Expand Up @@ -652,7 +652,7 @@ def in_lib(self):
Such files aren't loaded before running tests.
This uses :func:`~sage.misc.namespace_package.is_package_or_sage_namespace_package_dir`
This uses :func:`~sage.misc.package_dir.is_package_or_sage_namespace_package_dir`
but can be overridden via :class:`~sage.doctest.control.DocTestDefaults`.
EXAMPLES::
Expand Down
55 changes: 0 additions & 55 deletions src/sage/misc/namespace_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Utility functions for namespace packages in Sage
"""
from importlib import import_module
import os, glob

def install_doc(package, doc):
"""
Expand All @@ -19,57 +18,3 @@ def install_doc(package, doc):
pkg = import_module(package)
pkg.__doc__ = doc # enable sage.package?
pkg.getdoc = lambda: doc # enable help(sage.package)


def is_package_or_sage_namespace_package_dir(path):
"""
Return whether ``path`` is a directory that contains a Python package.
Ordinary Python packages are recognized by the presence of `__init__.py`.
Implicit namespace packages (PEP 420) are only recognized if they
follow the conventions of the Sage library, i.e., the directory contains
a file ``all.py`` or a file matching the pattern ``all__*.py``
such as ``all__sagemath_categories.py``.
EXAMPLES:
:mod:`sage.cpython` is an ordinary package::
sage: from sage.misc.namespace_package import is_package_or_sage_namespace_package_dir
sage: directory = os.path.dirname(sage.cpython.__file__); directory
'.../sage/cpython'
sage: is_package_or_sage_namespace_package_dir(directory)
True
:mod:`sage.libs.mpfr` only has an ``__init__.pxd`` file, but we consider
it a package directory for consistency with Cython::
sage: directory = os.path.join(os.path.dirname(sage.libs.all.__file__), 'mpfr'); directory
'.../sage/libs/mpfr'
sage: is_package_or_sage_namespace_package_dir(directory)
True
:mod:`sage` is designated to become an implicit namespace package::
sage: directory = os.path.dirname(sage.env.__file__); directory
'.../sage'
sage: is_package_or_sage_namespace_package_dir(directory)
True
Not a package::
sage: directory = os.path.join(os.path.dirname(sage.symbolic.__file__), 'ginac'); directory
'.../sage/symbolic/ginac'
sage: is_package_or_sage_namespace_package_dir(directory)
False
"""
if os.path.exists(os.path.join(path, '__init__.py')): # ordinary package
return True
if os.path.exists(os.path.join(path, '__init__.pxd')): # for consistency with Cython
return True
if os.path.exists(os.path.join(path, 'all.py')): # complete namespace package
return True
for _ in glob.iglob(os.path.join(path, 'all__*.py')):
return True # partial namespace package
return False
57 changes: 57 additions & 0 deletions src/sage/misc/package_dir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Recognizing package directories
"""
import os, glob

def is_package_or_sage_namespace_package_dir(path):
"""
Return whether ``path`` is a directory that contains a Python package.
Ordinary Python packages are recognized by the presence of `__init__.py`.
Implicit namespace packages (PEP 420) are only recognized if they
follow the conventions of the Sage library, i.e., the directory contains
a file ``all.py`` or a file matching the pattern ``all__*.py``
such as ``all__sagemath_categories.py``.
EXAMPLES:
:mod:`sage.cpython` is an ordinary package::
sage: from sage.misc.package_dir import is_package_or_sage_namespace_package_dir
sage: directory = os.path.dirname(sage.cpython.__file__); directory
'.../sage/cpython'
sage: is_package_or_sage_namespace_package_dir(directory)
True
:mod:`sage.libs.mpfr` only has an ``__init__.pxd`` file, but we consider
it a package directory for consistency with Cython::
sage: directory = os.path.join(os.path.dirname(sage.libs.all.__file__), 'mpfr'); directory
'.../sage/libs/mpfr'
sage: is_package_or_sage_namespace_package_dir(directory)
True
:mod:`sage` is designated to become an implicit namespace package::
sage: directory = os.path.dirname(sage.env.__file__); directory
'.../sage'
sage: is_package_or_sage_namespace_package_dir(directory)
True
Not a package::
sage: directory = os.path.join(os.path.dirname(sage.symbolic.__file__), 'ginac'); directory
'.../sage/symbolic/ginac'
sage: is_package_or_sage_namespace_package_dir(directory)
False
"""
if os.path.exists(os.path.join(path, '__init__.py')): # ordinary package
return True
if os.path.exists(os.path.join(path, '__init__.pxd')): # for consistency with Cython
return True
if os.path.exists(os.path.join(path, 'all.py')): # complete namespace package
return True
for _ in glob.iglob(os.path.join(path, 'all__*.py')):
return True # partial namespace package
return False
2 changes: 1 addition & 1 deletion src/sage_setup/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from collections import defaultdict

from sage.misc.namespace_package import is_package_or_sage_namespace_package_dir as is_package_or_namespace_package_dir
from sage.misc.package_dir import is_package_or_sage_namespace_package_dir as is_package_or_namespace_package_dir


def read_distribution(src_file):
Expand Down

0 comments on commit 464b0a5

Please sign in to comment.