Validate and normalize package_root.
(
fscache: FileSystemCache | None, parser: argparse.ArgumentParser, options: Options
)
| 1630 | |
| 1631 | |
| 1632 | def process_package_roots( |
| 1633 | fscache: FileSystemCache | None, parser: argparse.ArgumentParser, options: Options |
| 1634 | ) -> None: |
| 1635 | """Validate and normalize package_root.""" |
| 1636 | if fscache is None: |
| 1637 | parser.error("--package-root does not work here (no fscache)") |
| 1638 | assert fscache is not None # Since mypy doesn't know parser.error() raises. |
| 1639 | # Do some stuff with drive letters to make Windows happy (esp. tests). |
| 1640 | current_drive, _ = os.path.splitdrive(os.getcwd()) |
| 1641 | dot = os.curdir |
| 1642 | dotslash = os.curdir + os.sep |
| 1643 | dotdotslash = os.pardir + os.sep |
| 1644 | trivial_paths = {dot, dotslash} |
| 1645 | package_root = [] |
| 1646 | for root in options.package_root: |
| 1647 | if os.path.isabs(root): |
| 1648 | parser.error(f"Package root cannot be absolute: {root!r}") |
| 1649 | drive, root = os.path.splitdrive(root) |
| 1650 | if drive and drive != current_drive: |
| 1651 | parser.error(f"Package root must be on current drive: {drive + root!r}") |
| 1652 | # Empty package root is always okay. |
| 1653 | if root: |
| 1654 | root = os.path.relpath(root) # Normalize the heck out of it. |
| 1655 | if not root.endswith(os.sep): |
| 1656 | root = root + os.sep |
| 1657 | if root.startswith(dotdotslash): |
| 1658 | parser.error(f"Package root cannot be above current directory: {root!r}") |
| 1659 | if root in trivial_paths: |
| 1660 | root = "" |
| 1661 | package_root.append(root) |
| 1662 | options.package_root = package_root |
| 1663 | # Pass the package root on the filesystem cache. |
| 1664 | fscache.set_package_root(package_root) |
| 1665 | |
| 1666 | |
| 1667 | def process_cache_map( |
no test coverage detected
searching dependent graphs…