Skip to content

Commit

Permalink
gh-37650: src/sage/features/sagemath.py: Add feature SAGE_SRC
Browse files Browse the repository at this point in the history
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes #12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes #12345". -->

This feature is for conditionalizing some doctests.

Fixes doctest failure reported in
#37645.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - #12345: short description why this is a dependency -->
<!-- - #34567: ... -->
    
URL: #37650
Reported by: Matthias Köppe
Reviewer(s): François Bissey, Gonzalo Tornaría, Matthias Köppe
  • Loading branch information
Release Manager committed May 1, 2024
2 parents 721fc79 + 576d8bf commit 0a75254
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
28 changes: 27 additions & 1 deletion src/sage/features/sagemath.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@
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
# We check the file bin/sage-src-env-config.in, which by design is:
# - never installed,
# - not included in the sagemath-standard sdist,
# - included only in one modularized sdist, of pkgs/sage-conf_pypi,
# where it appears in a subdirectory (sage_root/src/bin/)
StaticFile.__init__(self, 'SAGE_SRC',
filename='bin/sage-src-env-config.in',
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 +1120,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 0a75254

Please sign in to comment.