-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathda
More file actions
executable file
·46 lines (39 loc) · 1.86 KB
/
Copy pathda
File metadata and controls
executable file
·46 lines (39 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
"""Thin wrapper around ``dacli.main``.
Resolves this file's real location (following symlinks), inserts the
containing directory at the *front* of ``sys.path`` so ``dacli`` is
importable, then delegates to ``dacli.main``.
Why insert at position 0 rather than ``append``: the shim exists
specifically to pick up the repo-local ``dacli.py`` regardless of any
``da-cli`` that might also be installed via ``pip``. Stale checkouts
shading a pip install is the failure mode we accept in exchange.
"""
import os
import sys
# Before anything else. ADR 0001 sets 3.10 as the floor because the code
# uses PEP 604 unions evaluated at runtime, without
# `from __future__ import annotations`. On an older interpreter the
# import below dies with
# `TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'`
# from somewhere deep in the package, which says nothing about the cause.
# macOS still ships 3.9 as /usr/bin/python3, and a launchd or cron job
# with a default PATH finds it.
if sys.version_info < (3, 10): # noqa: UP036 — see above: this must run ON 3.9
sys.stderr.write(
f"da-cli needs Python 3.10 or newer; this is "
f"{sys.version_info.major}.{sys.version_info.minor} "
f"({sys.executable}).\n"
f"Install a newer Python, or point this shim at one:\n"
f" /path/to/python3.12 {os.path.realpath(__file__)} --version\n"
)
raise SystemExit(2)
# PTH120 is suppressed on the next line: os.path, not pathlib, because this
# shim must import nothing that a 3.9 interpreter would choke on before the
# version guard above has had a chance to print a readable error.
_repo_root = os.path.dirname(os.path.realpath(__file__)) # noqa: PTH120
if _repo_root not in sys.path:
sys.path.insert(0, _repo_root)
# Import deliberately after the sys.path setup above.
from dacli import main
if __name__ == "__main__":
main()