bootstrap.py python
33 lines 1.2 KB
Raw
sha256:f88ec0083b3bcac6a4b7b99c8cc196194ef376aab2c4f2f63e8dfe26256ac6b7 docs: reconcile v1 prerelease publication and operating guides Human 7 days ago
1 """Isolated source bootstrap; never discover another checkout or a PATH Python."""
2 from pathlib import Path
3 import sys
4
5
6 def run() -> int:
7 if not sys.flags.isolated:
8 print("refused: launch with cli/ok (isolated Python required)", file=sys.stderr)
9 return 2
10 root = Path(__file__).resolve().parent.parent
11 # A normal venv executable may be a symlink. Its prefix, not its inode, binds it.
12 if Path(sys.prefix).resolve() != root / ".venv":
13 print("refused: runtime_environment_mismatch", file=sys.stderr)
14 return 2
15 sys.dont_write_bytecode = True
16 sys.path.insert(0, str(root))
17 import cli
18 if Path(cli.__file__).resolve() != root / "cli/__init__.py":
19 print("refused: import_origin_mismatch", file=sys.stderr)
20 return 2
21 try:
22 from cli.v1 import main
23 except ModuleNotFoundError:
24 print("refused: install requirements-v1.txt into this installation's .venv", file=sys.stderr)
25 return 2
26 if Path(sys.modules["cli.v1"].__file__).resolve() != root / "cli/v1.py":
27 print("refused: import_origin_mismatch", file=sys.stderr)
28 return 2
29 return main()
30
31
32 if __name__ == "__main__":
33 raise SystemExit(run())
File History 1 commit
sha256:f88ec0083b3bcac6a4b7b99c8cc196194ef376aab2c4f2f63e8dfe26256ac6b7 docs: reconcile v1 prerelease publication and operating guides Human 7 days ago