From 106a5a39bd161fa146dfecc5005363538587c08d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 4 Sep 2023 21:11:28 -0700 Subject: [PATCH 1/2] sage.doctest.sources: Distinguish .pxd from .pyx in doctest basenames --- src/sage/doctest/sources.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/sage/doctest/sources.py b/src/sage/doctest/sources.py index d5dc83f0e1a..5064496052b 100644 --- a/src/sage/doctest/sources.py +++ b/src/sage/doctest/sources.py @@ -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 @@ -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(): From d3a00b794fe42b3c0da05dfb4e8f46dfae31b6f8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 11 Sep 2023 22:43:05 -0700 Subject: [PATCH 2/2] src/sage/doctest/control.py (skipfile): Simplify handling of --if-installed --- src/sage/doctest/control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py index 9261c69dd4b..66cedee9b75 100644 --- a/src/sage/doctest/control.py +++ b/src/sage/doctest/control.py @@ -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