Skip to content

Commit 98eec5d

Browse files
author
Release Manager
committedFeb 21, 2025
sagemathgh-39494: Fix more doctests in meson_editable install Fix more bugs uncovered by sagemath#39369 . Add a feature flag `meson_editable`, and put doctests behind this flag accordingly. ### 📝 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. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39494 Reported by: user202729 Reviewer(s): Tobias Diez
2 parents cfbaaf1 + b6cb2f4 commit 98eec5d

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed
 

‎src/sage/doctest/external.py

+4
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ def external_features():
366366
r"""
367367
Generate the features that are only to be tested if ``--optional=external`` is used.
368368
369+
.. SEEALSO::
370+
371+
:func:`sage.features.all.all_features`
372+
369373
EXAMPLES::
370374
371375
sage: from sage.doctest.external import external_features

‎src/sage/doctest/sources.py

+10
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,18 @@ def get_basename(path):
8787
sage: import os
8888
sage: get_basename(sage.doctest.sources.__file__)
8989
'sage.doctest.sources'
90+
91+
::
92+
93+
sage: # optional - !meson_editable
9094
sage: get_basename(os.path.join(sage.structure.__path__[0], 'element.pxd'))
9195
'sage.structure.element.pxd'
96+
97+
TESTS::
98+
99+
sage: # optional - meson_editable
100+
sage: get_basename(os.path.join(os.path.dirname(sage.structure.__file__), 'element.pxd'))
101+
'sage.structure.element.pxd'
92102
"""
93103
if path is None:
94104
return None

‎src/sage/env.py

+4
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ def sage_include_directories(use_sources=False):
319319
sage: dirs = sage.env.sage_include_directories(use_sources=True)
320320
sage: any(os.path.isfile(os.path.join(d, file)) for d in dirs)
321321
True
322+
323+
::
324+
325+
sage: # optional - !meson_editable (no need, see :issue:`39275`)
322326
sage: dirs = sage.env.sage_include_directories(use_sources=False)
323327
sage: any(os.path.isfile(os.path.join(d, file)) for d in dirs)
324328
True

‎src/sage/features/meson_editable.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
r"""
2+
Feature for testing if Meson editable install is used.
3+
"""
4+
5+
import sys
6+
from . import Feature, FeatureTestResult
7+
8+
9+
class MesonEditable(Feature):
10+
r"""
11+
A :class:`~sage.features.Feature` describing if Meson editable install is used.
12+
13+
EXAMPLES::
14+
15+
sage: from sage.features.meson_editable import MesonEditable
16+
sage: MesonEditable()
17+
Feature('meson_editable')
18+
"""
19+
def __init__(self):
20+
r"""
21+
TESTS::
22+
23+
sage: from sage.features.meson_editable import MesonEditable
24+
sage: MesonEditable() is MesonEditable()
25+
True
26+
"""
27+
Feature.__init__(self, 'meson_editable')
28+
29+
def _is_present(self):
30+
r"""
31+
Test whether Meson editable install is used.
32+
33+
EXAMPLES::
34+
35+
sage: from sage.features.meson_editable import MesonEditable
36+
sage: MesonEditable()._is_present() # random
37+
FeatureTestResult('meson_editable', True)
38+
"""
39+
import sage
40+
result = type(sage.__loader__).__module__ == '_sagemath_editable_loader'
41+
return FeatureTestResult(self, result)
42+
43+
44+
def all_features():
45+
return [MesonEditable()]

‎src/sage/misc/package_dir.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def is_package_or_sage_namespace_package_dir(path, *, distribution_filter=None):
261261
262262
:mod:`sage.cpython` is an ordinary package::
263263
264+
sage: # optional - !meson_editable
264265
sage: from sage.misc.package_dir import is_package_or_sage_namespace_package_dir
265266
sage: directory = sage.cpython.__path__[0]; directory
266267
'.../sage/cpython'
@@ -270,24 +271,48 @@ def is_package_or_sage_namespace_package_dir(path, *, distribution_filter=None):
270271
:mod:`sage.libs.mpfr` only has an ``__init__.pxd`` file, but we consider
271272
it a package directory for consistency with Cython::
272273
274+
sage: # optional - !meson_editable
273275
sage: directory = os.path.join(sage.libs.__path__[0], 'mpfr'); directory
274276
'.../sage/libs/mpfr'
275277
sage: is_package_or_sage_namespace_package_dir(directory) # known bug (seen in build.yml)
276278
True
277279
278280
:mod:`sage` is designated to become an implicit namespace package::
279281
282+
sage: # optional - !meson_editable
280283
sage: directory = sage.__path__[0]; directory
281284
'.../sage'
282-
sage: is_package_or_sage_namespace_package_dir(directory) # known bug (seen in build.yml)
285+
sage: is_package_or_sage_namespace_package_dir(directory)
283286
True
284287
285288
Not a package::
286289
290+
sage: # optional - !meson_editable
287291
sage: directory = os.path.join(sage.symbolic.__path__[0], 'ginac'); directory # needs sage.symbolic
288292
'.../sage/symbolic/ginac'
289293
sage: is_package_or_sage_namespace_package_dir(directory) # needs sage.symbolic
290294
False
295+
296+
TESTS::
297+
298+
sage: # optional - meson_editable
299+
sage: from sage.misc.package_dir import is_package_or_sage_namespace_package_dir
300+
sage: directory = os.path.dirname(sage.cpython.__file__); directory
301+
'.../sage/cpython'
302+
sage: is_package_or_sage_namespace_package_dir(directory)
303+
True
304+
305+
sage: # optional - meson_editable
306+
sage: directory = os.path.join(os.path.dirname(sage.libs.__file__), 'mpfr'); directory
307+
'.../sage/libs/mpfr'
308+
sage: is_package_or_sage_namespace_package_dir(directory)
309+
True
310+
311+
sage: # optional - meson_editable, sage.symbolic
312+
sage: directory = os.path.join(os.path.dirname(sage.symbolic.__file__), 'ginac'); directory
313+
'.../sage/symbolic/ginac'
314+
sage: is_package_or_sage_namespace_package_dir(directory)
315+
False
291316
"""
292317
if os.path.exists(os.path.join(path, '__init__.py')): # ordinary package
293318
return True
@@ -345,8 +370,15 @@ def walk_packages(path=None, prefix='', onerror=None):
345370
346371
EXAMPLES::
347372
373+
sage: # optional - !meson_editable
348374
sage: sorted(sage.misc.package_dir.walk_packages(sage.misc.__path__)) # a namespace package
349375
[..., ModuleInfo(module_finder=FileFinder('.../sage/misc'), name='package_dir', ispkg=False), ...]
376+
377+
TESTS::
378+
379+
sage: # optional - meson_editable
380+
sage: sorted(sage.misc.package_dir.walk_packages(sage.misc.__path__))
381+
[..., ModuleInfo(module_finder=<...MesonpyPathFinder object...>, name='package_dir', ispkg=False), ...]
350382
"""
351383
# Adapted from https://github.com/python/cpython/blob/3.11/Lib/pkgutil.py
352384

0 commit comments

Comments
 (0)