[7.4.x] Fix --import-mode=importlib when root contains __init__.py file (#11426)

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
github-actions[bot]
2023-09-10 13:27:53 +00:00
committed by GitHub
parent 946634c84c
commit 1944dc06d3
2 changed files with 24 additions and 2 deletions

View File

@@ -623,8 +623,9 @@ def module_name_from_path(path: Path, root: Path) -> str:
# Use the parts for the relative path to the root path.
path_parts = relative_path.parts
# Module name for packages do not contain the __init__ file.
if path_parts[-1] == "__init__":
# Module name for packages do not contain the __init__ file, unless
# the `__init__.py` file is at the root.
if len(path_parts) >= 2 and path_parts[-1] == "__init__":
path_parts = path_parts[:-1]
return ".".join(path_parts)