Return the Python package path by looking for the last directory upwards which still contains an __init__.py. Returns None if it cannot be determined.
(path: Path)
| 828 | |
| 829 | |
| 830 | def resolve_package_path(path: Path) -> Path | None: |
| 831 | """Return the Python package path by looking for the last |
| 832 | directory upwards which still contains an __init__.py. |
| 833 | |
| 834 | Returns None if it cannot be determined. |
| 835 | """ |
| 836 | result = None |
| 837 | for parent in itertools.chain((path,), path.parents): |
| 838 | if parent.is_dir(): |
| 839 | if not (parent / "__init__.py").is_file(): |
| 840 | break |
| 841 | if not parent.name.isidentifier(): |
| 842 | break |
| 843 | result = parent |
| 844 | return result |
| 845 | |
| 846 | |
| 847 | def resolve_pkg_root_and_module_name( |
no outgoing calls