Skip to content

Commit

Permalink
sagemathgh-36238: sage -t: Distinguish .pxd from .pyx in doctest ba…
Browse files Browse the repository at this point in the history
…senames

    
<!-- ^^^^^
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 sagemath#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 sagemath#12345". -->
Cherry-picked from sagemath#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
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36238
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Sep 13, 2023
2 parents acc905f + d3a00b7 commit ca0eab2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/sage/doctest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def skipfile(filename, tested_optional_tags=False, *,
if log:
log(f"Skipping '{filename}' because it is created by the jupyter-sphinx extension for internal use and should not be tested")
return True
if if_installed and ext in ('.py', '.pyx', '.pxd'):
if if_installed:
module_name = get_basename(filename)
try:
if not importlib.util.find_spec(module_name): # tries to import the containing package
Expand Down
12 changes: 9 additions & 3 deletions src/sage/doctest/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def get_basename(path):
sage: from sage.doctest.sources import get_basename
sage: from sage.env import SAGE_SRC
sage: import os
sage: get_basename(os.path.join(SAGE_SRC,'sage','doctest','sources.py'))
sage: get_basename(os.path.join(SAGE_SRC, 'sage', 'doctest', 'sources.py'))
'sage.doctest.sources'
sage: get_basename(os.path.join(SAGE_SRC, 'sage', 'structure', 'element.pxd'))
'sage.structure.element.pxd'
"""
if path is None:
return None
Expand All @@ -111,10 +113,14 @@ def get_basename(path):
# it goes.
while is_package_or_sage_namespace_package_dir(root):
root = os.path.dirname(root)
fully_qualified_path = os.path.splitext(path[len(root) + 1:])[0]
fully_qualified_path, ext = os.path.splitext(path[len(root) + 1:])
if os.path.split(path)[1] == '__init__.py':
fully_qualified_path = fully_qualified_path[:-9]
return fully_qualified_path.replace(os.path.sep, '.')
basename = fully_qualified_path.replace(os.path.sep, '.')
if ext in ['.pxd', '.pxi']:
# disambiguate from .pyx with the same basename
basename += ext
return basename


class DocTestSource():
Expand Down

0 comments on commit ca0eab2

Please sign in to comment.