Skip to content

Commit 905d3c2

Browse files
author
Release Manager
committed
gh-36238: `sage -t`: Distinguish .pxd from .pyx in doctest basenames <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> These basenames are used in the stats file, recording test failures and running times in `~/.sage/timings2.json`. Currently, `element.pyx` and `element.pxd` have the same basename, and so they clobber each other in the stats file. It depends on the order of execution which of the two wins. This affects `sage -t --failed` and the sort order according to running times. Here we disambiguate them by adding a suffix for .pxd and .pxi files. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> Cherry-picked from #35095, where the stats are used for creating records of known test failures of the modularized distributions. <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36238 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
2 parents b6b50a8 + d3a00b7 commit 905d3c2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/sage/doctest/control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def skipfile(filename, tested_optional_tags=False, *,
289289
if log:
290290
log(f"Skipping '{filename}' because it is created by the jupyter-sphinx extension for internal use and should not be tested")
291291
return True
292-
if if_installed and ext in ('.py', '.pyx', '.pxd'):
292+
if if_installed:
293293
module_name = get_basename(filename)
294294
try:
295295
if not importlib.util.find_spec(module_name): # tries to import the containing package

src/sage/doctest/sources.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ def get_basename(path):
8484
sage: from sage.doctest.sources import get_basename
8585
sage: from sage.env import SAGE_SRC
8686
sage: import os
87-
sage: get_basename(os.path.join(SAGE_SRC,'sage','doctest','sources.py'))
87+
sage: get_basename(os.path.join(SAGE_SRC, 'sage', 'doctest', 'sources.py'))
8888
'sage.doctest.sources'
89+
sage: get_basename(os.path.join(SAGE_SRC, 'sage', 'structure', 'element.pxd'))
90+
'sage.structure.element.pxd'
8991
"""
9092
if path is None:
9193
return None
@@ -111,10 +113,14 @@ def get_basename(path):
111113
# it goes.
112114
while is_package_or_sage_namespace_package_dir(root):
113115
root = os.path.dirname(root)
114-
fully_qualified_path = os.path.splitext(path[len(root) + 1:])[0]
116+
fully_qualified_path, ext = os.path.splitext(path[len(root) + 1:])
115117
if os.path.split(path)[1] == '__init__.py':
116118
fully_qualified_path = fully_qualified_path[:-9]
117-
return fully_qualified_path.replace(os.path.sep, '.')
119+
basename = fully_qualified_path.replace(os.path.sep, '.')
120+
if ext in ['.pxd', '.pxi']:
121+
# disambiguate from .pyx with the same basename
122+
basename += ext
123+
return basename
118124

119125

120126
class DocTestSource():

0 commit comments

Comments
 (0)