Skip to content

Commit

Permalink
src/sage/features/sagemath.py: Add feature SAGE_SRC
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Apr 27, 2024
1 parent c4363fc commit 7cd5a23
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/sage/features/sagemath.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@
from .join_feature import JoinFeature


class SAGE_SRC(StaticFile):
r"""
A :class:`~sage.features.Feature` which describes the presence of the
monolithic source tree of the Sage library.
"""
def __init__(self):
r"""
TESTS::
sage: from sage.features.sagemath import SAGE_SRC
sage: isinstance(SAGE_SRC(), SAGE_SRC)
True
"""
from sage.env import SAGE_SRC
StaticFile.__init__(self, 'SAGE_SRC',
filename='VERSION.txt', # a file that is never installed
search_path=(SAGE_SRC,) if SAGE_SRC else ())


class sagemath_doc_html(StaticFile):
r"""
A :class:`~sage.features.Feature` which describes the presence of the documentation
Expand Down Expand Up @@ -1095,7 +1115,8 @@ def all_features():
sage: list(all_features())
[...Feature('sage.combinat'), ...]
"""
return [sagemath_doc_html(),
return [SAGE_SRC(),
sagemath_doc_html(),
sage__combinat(),
sage__geometry__polyhedron(),
sage__graphs(),
Expand Down
1 change: 1 addition & 0 deletions src/sage/misc/package_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def read_distribution(src_file):
EXAMPLES::
sage: # needs SAGE_SRC
sage: from sage.env import SAGE_SRC
sage: from sage.misc.package_dir import read_distribution
sage: read_distribution(os.path.join(SAGE_SRC, 'sage', 'graphs', 'graph_decompositions', 'tdlib.pyx'))
Expand Down
7 changes: 5 additions & 2 deletions src/sage/misc/replace_dot_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ def find_replacements(location, package_regex=None, verbose=False):
EXAMPLES::
sage: # needs SAGE_SRC
sage: from sage.misc.replace_dot_all import *
sage: location = os.path.join(sage.env.SAGE_SRC, 'sage/plot/arc.py')
sage: location = os.path.join(sage.env.SAGE_SRC, 'sage', 'plot', 'arc.py')
sage: find_replacements(location, package_regex='sage[.]plot[.]all', verbose=True)
[[..., ..., 'from sage.plot.graphics import Graphics']]
"""
Expand Down Expand Up @@ -295,8 +296,9 @@ def process_line(location, line, replacements, row_index, verbose=False):
Replacing the first line which needs a replacement in the source file with filepath ``src/sage/plot/arc.py``::
sage: # needs SAGE_SRC
sage: from sage.misc.replace_dot_all import *
sage: location = os.path.join(sage.env.SAGE_SRC, 'sage/plot/arc.py')
sage: location = os.path.join(sage.env.SAGE_SRC, 'sage', 'plot', 'arc.py')
sage: replacements = find_replacements(location, package_regex='sage[.]plot[.]all', verbose=True); replacements
[[477, 24, 'from sage.plot.graphics import Graphics']]
sage: with open(location, "r") as file:
Expand Down Expand Up @@ -401,6 +403,7 @@ def walkdir_replace_dot_all(dir, file_regex=r'.*[.](py|pyx|pxi)$', package_regex
EXAMPLES::
sage: # needs SAGE_SRC
sage: from sage.misc.replace_dot_all import *
sage: walkdir_replace_dot_all(os.path.join(sage.env.SAGE_SRC, 'sage')) # not tested
"""
Expand Down
2 changes: 2 additions & 0 deletions src/sage_setup/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def _find_stale_files(site_packages, python_packages, python_modules, ext_module
course. We check that when the doctest is being run, that is,
after installation, there are no stale files::
sage: # needs SAGE_SRC
sage: from sage.env import SAGE_SRC, SAGE_LIB, SAGE_ROOT
sage: from sage_setup.find import _cythonized_dir
sage: cythonized_dir = _cythonized_dir(SAGE_SRC)
Expand All @@ -98,6 +99,7 @@ def _find_stale_files(site_packages, python_packages, python_modules, ext_module
TODO: Also check extension modules::
sage: # needs SAGE_SRC
sage: stale_iter = _find_stale_files(SAGE_LIB, python_packages, python_modules, [], extra_files)
sage: from importlib.machinery import EXTENSION_SUFFIXES
sage: skip_extensions = tuple(EXTENSION_SUFFIXES)
Expand Down
1 change: 1 addition & 0 deletions src/sage_setup/find.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs SAGE_SRC
"""
Recursive Directory Contents
"""
Expand Down

0 comments on commit 7cd5a23

Please sign in to comment.