-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdev-cli.py
More file actions
executable file
·73 lines (54 loc) · 1.78 KB
/
dev-cli.py
File metadata and controls
executable file
·73 lines (54 loc) · 1.78 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
`./dev-cli.py` is a development bootstrap script and CLI entry point.
Just call this file, and the magic happens ;)
The `uv` tool is required to run the development CLI.
e.g.: Install `uv` via `pipx`
apt-get install pipx
pipx install uv
"""
import os
import shlex
import shutil
import subprocess
import sys
from pathlib import Path
assert sys.version_info >= (3, 12), f'Python version {sys.version_info} is too old!'
# Create and use "/.venv/" for virtualenv:
VIRTUAL_ENV = '.venv'
def print_uv_error_and_exit():
print('\nError: "uv" command not found in PATH. Please install "uv" first!\n')
print('Hint:')
print('\tapt-get install pipx\n')
print('\tpipx install uv\n')
sys.exit(1)
def verbose_check_call(*popen_args):
print(f'\n+ {shlex.join(str(arg) for arg in popen_args)}\n')
env = {
'VIRTUAL_ENV': VIRTUAL_ENV,
'UV_VENV': VIRTUAL_ENV,
**os.environ,
}
return subprocess.check_call(
popen_args,
env=env,
cwd=Path(__file__).parent, # Needed if called from other working directory
)
def main(argv):
uv_bin = shutil.which('uv') # Ensure 'uv' is available in PATH
if not uv_bin:
print_uv_error_and_exit()
if not Path(VIRTUAL_ENV).is_dir():
verbose_check_call(uv_bin, 'venv', VIRTUAL_ENV)
# Activate git pre-commit hooks:
verbose_check_call(uv_bin, 'run', '--active', '-m', 'pre_commit', 'install')
# Call our entry point CLI:
try:
verbose_check_call(uv_bin, 'run', '--active', '-m', 'dragonpy.cli_dev', *argv[1:])
except subprocess.CalledProcessError as err:
sys.exit(err.returncode)
except KeyboardInterrupt:
print('Bye!')
sys.exit(130)
if __name__ == '__main__':
main(sys.argv)