Return the Python package path by looking for the last directory upwards which still contains an __init__.py. Returns None if it can not be determined.
(path: Path)
| 611 | |
| 612 | |
| 613 | def resolve_package_path(path: Path) -> Optional[Path]: |
| 614 | """Return the Python package path by looking for the last |
| 615 | directory upwards which still contains an __init__.py. |
| 616 | |
| 617 | Returns None if it can not be determined. |
| 618 | """ |
| 619 | result = None |
| 620 | for parent in itertools.chain((path,), path.parents): |
| 621 | if parent.is_dir(): |
| 622 | if not parent.joinpath("__init__.py").is_file(): |
| 623 | break |
| 624 | if not parent.name.isidentifier(): |
| 625 | break |
| 626 | result = parent |
| 627 | return result |
| 628 | |
| 629 | |
| 630 | def visit( |
no outgoing calls