Skip to content

Commit

Permalink
Trac #33011: Remove __init__.py files for subpackages designated to b…
Browse files Browse the repository at this point in the history
…e namespace packages

This ticket changes the following packages to namespace packages (by
removing `__init__.py`):
  - `sage.matrix` (this allows the new distribution `sage-meataxe`
introduced in #30151 to add the module `sage.matrix.matrix_gfpn_dense`)
to the package)
  - `sage.libs` (for `.meataxe` - #30151, `.sirocco`, `.coexter3`,
`.fes`)
  - `sage.interfaces` (for `.primecount`)
  - `sage.graphs` (for `.bliss`, `.mcqd`)
  - `sage.graphs.graph_decompositions` (for `.tdlib` -> `sage-tdlib`,
#29864.)
  - `sage.numerical`, `sage.numerical.backends`. (This is preparation
for later work, in #30152.)

A complication lies in the behavior of the Python import machinery:
`setup.py` puts the source path in front of `setup.py` because
`sage_setup` uses `sage.env` and
`is_package_or_sage_namespace_package_dir` (#33033).
But when an old version of `sage` that is an ordinary package is
installed already, the source will not shadow it.

To avoid this complication, in this ticket we do not yet remove
`src/sage/__init__.py`. That is done in #34187.

URL: https://trac.sagemath.org/33011
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Jul 18, 2022
2 parents 5fc17fd + 39aa2f1 commit ea11a51
Show file tree
Hide file tree
Showing 16 changed files with 10 additions and 3 deletions.
Empty file removed src/sage/ext/__init__.py
Empty file.
Empty file removed src/sage/graphs/__init__.py
Empty file.
Empty file.
File renamed without changes.
Empty file removed src/sage/interfaces/__init__.py
Empty file.
Empty file removed src/sage/libs/__init__.py
Empty file.
Empty file removed src/sage/matrix/__init__.py
Empty file.
Empty file removed src/sage/misc/__init__.py
Empty file.
Empty file removed src/sage/numerical/__init__.py
Empty file.
Empty file.
File renamed without changes.
Empty file removed src/sage/rings/__init__.py
Empty file.
Empty file removed src/sage/sets/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions src/sage_docbuild/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,10 @@ def get_new_and_updated_modules(self):
raise

module_filename = sys.modules[module_name].__file__
if module_filename is None:
# Namespace package
old_modules.append(module_name)
continue
if (module_filename.endswith('.pyc') or module_filename.endswith('.pyo')):
source_filename = module_filename[:-1]
if (os.path.exists(source_filename)):
Expand Down
7 changes: 5 additions & 2 deletions src/sage_setup/command/sage_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ def clean_stale_files(self):

# Determine all Python modules inside all packages
py_modules = []
ordinary_packages = []
for package in dist.packages:
package_dir = cmd_build_py.get_package_dir(package)
py_modules += cmd_build_py.find_package_modules(package, package_dir)
if os.path.exists(os.path.join(package_dir, '__init__.py')):
ordinary_packages.append(package)
py_modules.extend(cmd_build_py.find_package_modules(package, package_dir))
# modules is a list of triples (package, module, module_file).
# Construct the complete module name from this.
py_modules = ["{0}.{1}".format(*m) for m in py_modules]
Expand All @@ -97,7 +100,7 @@ def clean_stale_files(self):
for output_dir in set(output_dirs):
log.info('- cleaning {0}'.format(output_dir))
clean_install_dir(output_dir,
dist.packages,
ordinary_packages,
py_modules,
dist.ext_modules,
data_files,
Expand Down
2 changes: 1 addition & 1 deletion src/sage_setup/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def installed_files_by_module(site_packages, modules=('sage',)):
Namespace packages::
sage: files_by_module['sage.graphs.graph_decompositions']
{...'sage/graphs/graph_decompositions/__init__.py'...}
set()
This takes about 30ms with warm cache::
Expand Down

0 comments on commit ea11a51

Please sign in to comment.