Skip to content

Harmonize with crate-1.0.0: ModuleNotFoundError: No module named 'crate.client' #447

@amotl

Description

@amotl

Problem

After upgrading to crate-1.0.0 (dev), running the testsuite using python -m unittest -vvv trips, not able to find crate.client any longer.

Traceback (most recent call last):
  File "/path/to/lib/python3.12/unittest/loader.py", line 396, in _find_test_path
    module = self._get_module_from_name(name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/lib/python3.12/unittest/loader.py", line 339, in _get_module_from_name
    __import__(name)
  File "/path/to/crash/tests/test_sysinfo.py", line 29, in <module>
    from crate.crash.command import CrateShell
  File "/path/to/crash/crate/crash/command.py", line 43, in <module>
    from crate.client import connect
ModuleNotFoundError: No module named 'crate.client'

This is probably coming from the transition to "implicit namespace packages".

Observations

The problem does not happen at runtime, so we are safe on this side at least.

uv pip install --upgrade "crate>=1.0.0.dev2" crash
$ crash --version
0.31.5

Solution

The crash repository currently manages its fragment of the crate namespace package within a top-level folder. It should probably use the "src layout", like crate-python is also doing it, storing the actual module's source under src/crate/.

The “src layout” deviates from the flat layout by moving the code that is intended to be importable into a subdirectory. This subdirectory is typically named src/, hence “src layout”.

The src layout helps prevent accidental usage of the in-development copy of the code.

-- https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/

Evaluation

In previous times of Python packaging, and when using the previous variants of implementing namespace packages, this detail probably didn't play a relevant role. Now, apparently, it does, and needs a minor refactoring of the directory layout.

/cc @surister, @simonprickett, @kneth

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions