diff options
Diffstat (limited to 'scripts/dev.py')
| -rw-r--r-- | scripts/dev.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/scripts/dev.py b/scripts/dev.py index f0761d0c3..ffe2a0d9f 100644 --- a/scripts/dev.py +++ b/scripts/dev.py | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | import argparse | 4 | import argparse |
| 5 | import json | 5 | import json |
| 6 | import os | ||
| 7 | import shlex | ||
| 6 | import subprocess | 8 | import subprocess |
| 7 | import sys | 9 | import sys |
| 8 | from pathlib import Path | 10 | from pathlib import Path |
| @@ -38,7 +40,7 @@ def discover() -> dict: | |||
| 38 | "id": name, | 40 | "id": name, |
| 39 | "path": path, | 41 | "path": path, |
| 40 | "present": present, | 42 | "present": present, |
| 41 | "help_argv": ["python", "-I", path, "--help"] if present else None, | 43 | "help_argv": [sys.executable, "-I", path, "--help"] if present else None, |
| 42 | "requirements": requirements, | 44 | "requirements": requirements, |
| 43 | }) | 45 | }) |
| 44 | return { | 46 | return { |
| @@ -51,6 +53,13 @@ def discover() -> dict: | |||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | 55 | ||
| 56 | def format_help_command(argv: list[str]) -> str: | ||
| 57 | if os.name == "nt": | ||
| 58 | quoted = ("'" + arg.replace("'", "''") + "'" for arg in argv) | ||
| 59 | return "& " + " ".join(quoted) | ||
| 60 | return shlex.join(argv) | ||
| 61 | |||
| 62 | |||
| 54 | def run_producer(relative_path: str, args: list[str]) -> int: | 63 | def run_producer(relative_path: str, args: list[str]) -> int: |
| 55 | producer = ROOT / relative_path | 64 | producer = ROOT / relative_path |
| 56 | if not producer.is_file(): | 65 | if not producer.is_file(): |
| @@ -98,12 +107,13 @@ def main() -> int: | |||
| 98 | if args.json: | 107 | if args.json: |
| 99 | print(json.dumps(result, indent=2)) | 108 | print(json.dumps(result, indent=2)) |
| 100 | else: | 109 | else: |
| 110 | sys.stdout.reconfigure(encoding="utf-8") | ||
| 101 | print("Paths and help commands are relative to the Leonida checkout root.") | 111 | print("Paths and help commands are relative to the Leonida checkout root.") |
| 102 | for tool in result["tools"]: | 112 | for tool in result["tools"]: |
| 103 | status = "present" if tool["present"] else "missing" | 113 | status = "present" if tool["present"] else "missing" |
| 104 | print(f"{tool['id']}: {tool['path']} ({status})") | 114 | print(f"{tool['id']}: {tool['path']} ({status})") |
| 105 | if tool["help_argv"]: | 115 | if tool["help_argv"]: |
| 106 | print(f" Help: {' '.join(tool['help_argv'])}") | 116 | print(f" Help: {format_help_command(tool['help_argv'])}") |
| 107 | print(" Requirements (not checked):") | 117 | print(" Requirements (not checked):") |
| 108 | for requirement in tool["requirements"]: | 118 | for requirement in tool["requirements"]: |
| 109 | print(f" - {requirement}") | 119 | print(f" - {requirement}") |