Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
amotl opened this issue Nov 4, 2024 · 1 comment

Comments

@amotl
Copy link
Member

amotl commented Nov 4, 2024

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

@amotl
Copy link
Member Author

amotl commented Nov 4, 2024

Resolved with GH-448.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant