MCPcopy Index your code
hub / github.com/python/mypy / process_package_roots

Function process_package_roots

mypy/main.py:1632–1664  ·  view source on GitHub ↗

Validate and normalize package_root.

(
    fscache: FileSystemCache | None, parser: argparse.ArgumentParser, options: Options
)

Source from the content-addressed store, hash-verified

1630
1631
1632def 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
1667def process_cache_map(

Callers 1

process_optionsFunction · 0.85

Calls 5

appendMethod · 0.80
set_package_rootMethod · 0.80
errorMethod · 0.45
endswithMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…