sagemath/sage

Prepare sage.doctest for namespace packages

Closed this issue · 30 comments

The Sage doctester decides whether a Python file is part of a package based on the presence of __init__.py files. This is no longer appropriate because PEP 420 implicit namespace packages do not have __init__.py files; see #32501.

We implement a new function sage.misc.package_dir.is_package_or_sage_namespace_package_dir, which we will also use in #28925.

This change also removes a runtime dependency of the doctester on Cython, see #33029.

CC: @tobiasdiez @kwankyu @kiwifb @antonio-rojas @seblabbe

Component: doctest framework

Author: Matthias Koeppe

Branch/Commit: 5adae47

Reviewer: Tobias Diez, Kwankyu Lee

Issue created by migration from https://trac.sagemath.org/ticket/33033

Description changed:

--- 
+++ 
@@ -1,2 +1,2 @@
-The behavior of the Sage doctester decides whether a Python file is part of package based on the presence of `__init__.py` files. This is no longer appropriate because PEP 420 implicit namespace packages do not have `__init__.py` files.
+The Sage doctester decides whether a Python file is part of package based on the presence of `__init__.py` files. This is no longer appropriate because PEP 420 implicit namespace packages do not have `__init__.py` files.
 

Description changed:

--- 
+++ 
@@ -1,2 +1,2 @@
-The Sage doctester decides whether a Python file is part of package based on the presence of `__init__.py` files. This is no longer appropriate because PEP 420 implicit namespace packages do not have `__init__.py` files.
+The Sage doctester decides whether a Python file is part of a package based on the presence of `__init__.py` files. This is no longer appropriate because PEP 420 implicit namespace packages do not have `__init__.py` files.
 

Branch pushed to git repo; I updated commit sha1. New commits:

ab23a14src/sage/doctest/sources.py: Use is_package_or_sage_namespace_package_dir

Author: Matthias Koeppe

Description changed:

--- 
+++ 
@@ -1,2 +1,4 @@
-The Sage doctester decides whether a Python file is part of a package based on the presence of `__init__.py` files. This is no longer appropriate because PEP 420 implicit namespace packages do not have `__init__.py` files.
+The Sage doctester decides whether a Python file is part of a package based on the presence of `__init__.py` files. This is no longer appropriate because PEP 420 implicit namespace packages do not have `__init__.py` files; see #32501.
 
+This change also removes a runtime dependency of the doctester on Cython, see #33029.
+
comment:6

A few nitpicks from my side, otherwise looks good (codewise, didn't try it locally).

The explicit bool in sagemath/sagetrac-mirror@develop...u/mkoeppe/prepare_sage_doctest_for_namespace_packages#diff-944be831a2285f89611252d94988abde763acd41fd84353c5b46c01df443dc82L680-L683 can probably be removed (at least according to the comment that had been there).

sage: d = os.path.dirname(sage.cpython.file); d

For readability, I would propose to use dir or directory instead of the single-letter variable name.

Changed commit from ab23a14 to d8aa37c

Branch pushed to git repo; I updated commit sha1. New commits:

0f05856src/sage/doctest/sources.py: Remove unnecessary conversion to bool
d8aa37csrc/sage/misc/namespace_package.py: In doctests, use 'directory' instead of the single-letter variable name
comment:8

Thanks, the changes look good to me!

Reviewer: Tobias Diez, ...

Changed commit from d8aa37c to 19e93f0

Branch pushed to git repo; I updated commit sha1. New commits:

19e93f0is_package_or_sage_namespace_package_dir: Make directories with __init__.pxd package directories

Description changed:

--- 
+++ 
@@ -1,4 +1,7 @@
 The Sage doctester decides whether a Python file is part of a package based on the presence of `__init__.py` files. This is no longer appropriate because PEP 420 implicit namespace packages do not have `__init__.py` files; see #32501.
+
+We implement a new function `sage.misc.namespace_package.is_package_or_sage_namespace_package_dir`, which we will also use in #28925.
 
 This change also removes a runtime dependency of the doctester on Cython, see #33029.
 
+
comment:12

Turns out that this module is not the best place for the new function because the function will need to be packaged in the distribution sagemath-environment.

Branch pushed to git repo; I updated commit sha1. New commits:

5808f3dsrc/sage/misc/package_dir.py: New file for is_package_or_sage_namespace_package_dir

Changed commit from 19e93f0 to 5808f3d

Description changed:

--- 
+++ 
@@ -1,6 +1,6 @@
 The Sage doctester decides whether a Python file is part of a package based on the presence of `__init__.py` files. This is no longer appropriate because PEP 420 implicit namespace packages do not have `__init__.py` files; see #32501.
 
-We implement a new function `sage.misc.namespace_package.is_package_or_sage_namespace_package_dir`, which we will also use in #28925.
+We implement a new function `sage.misc.package_dir.is_package_or_sage_namespace_package_dir`, which we will also use in #28925.
 
 This change also removes a runtime dependency of the doctester on Cython, see #33029.
 
comment:15

Ready for review

Branch pushed to git repo; I updated commit sha1. New commits:

3939af7Merge tag '9.5.rc3' into t/33033/prepare_sage_doctest_for_namespace_packages

Changed commit from 5808f3d to 3939af7

Branch pushed to git repo; I updated commit sha1. New commits:

cf40d61Merge tag '9.5' into t/33033/prepare_sage_doctest_for_namespace_packages

Changed commit from 3939af7 to cf40d61

Changed commit from cf40d61 to 5adae47

Branch pushed to git repo; I updated commit sha1. New commits:

5adae47src/sage/misc/package_dir.py: Fix pycodestyle warning
comment:21

LGTM.

Changed reviewer from Tobias Diez, ... to Tobias Diez, Kwankyu Lee

comment:22

Thank you!