Tests für rot_2D und rot_3D
This commit is contained in:
1 parent
70e1a351f3
commit
7753115638
6 files changed
+196
-54
No files matched your search
+77
-23
@@ -20,13 +20,16 @@ Abweichendes Verhalten:
|
||||
python install_dependencies.py --write requirements.txt schreiben statt installieren
|
||||
python install_dependencies.py --write -o reqs.txt
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info < (3, 11):
|
||||
sys.exit("Dieses Skript braucht Python 3.11 oder neuer (tomllib). "
|
||||
f"Aktuell: {sys.version.split()[0]}")
|
||||
sys.exit(
|
||||
"Dieses Skript braucht Python 3.11 oder neuer (tomllib). "
|
||||
f"Aktuell: {sys.version.split()[0]}"
|
||||
)
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
@@ -54,7 +57,9 @@ def resolve_group(groups: dict, name: str, seen: set[str] | None = None) -> list
|
||||
return result
|
||||
|
||||
|
||||
def collect(data: dict, extras: list[str], groups: list[str], no_main: bool) -> list[str]:
|
||||
def collect(
|
||||
data: dict, extras: list[str], groups: list[str], no_main: bool
|
||||
) -> list[str]:
|
||||
project = data.get("project", {})
|
||||
optional = project.get("optional-dependencies", {})
|
||||
dep_groups = data.get("dependency-groups", {})
|
||||
@@ -74,18 +79,44 @@ def collect(data: dict, extras: list[str], groups: list[str], no_main: bool) ->
|
||||
|
||||
|
||||
def main() -> int:
|
||||
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
p.add_argument("-p", "--pyproject", type=Path, default=PROJECT_DIR / "pyproject.toml",
|
||||
help="Pfad zur pyproject.toml (Standard: neben diesem Skript)")
|
||||
p.add_argument("--extra", action="append", default=None,
|
||||
help="nur diese optional-dependencies (mehrfach möglich)")
|
||||
p.add_argument("--group", action="append", default=None,
|
||||
help="nur diese dependency-groups (mehrfach möglich)")
|
||||
p.add_argument("--no-main", action="store_true", help="[project].dependencies weglassen")
|
||||
p = argparse.ArgumentParser(
|
||||
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
|
||||
)
|
||||
p.add_argument(
|
||||
"-p",
|
||||
"--pyproject",
|
||||
type=Path,
|
||||
default=PROJECT_DIR / "pyproject.toml",
|
||||
help="Pfad zur pyproject.toml (Standard: neben diesem Skript)",
|
||||
)
|
||||
p.add_argument(
|
||||
"--extra",
|
||||
action="append",
|
||||
default=None,
|
||||
help="nur diese optional-dependencies (mehrfach möglich)",
|
||||
)
|
||||
p.add_argument(
|
||||
"--group",
|
||||
action="append",
|
||||
default=None,
|
||||
help="nur diese dependency-groups (mehrfach möglich)",
|
||||
)
|
||||
p.add_argument(
|
||||
"--no-main", action="store_true", help="[project].dependencies weglassen"
|
||||
)
|
||||
p.add_argument("--list", action="store_true", help="Abhängigkeiten nur anzeigen")
|
||||
p.add_argument("--write", action="store_true", help="requirements-Datei schreiben statt installieren")
|
||||
p.add_argument("-o", "--output", type=Path, default=PROJECT_DIR / "requirements.txt",
|
||||
help="Zieldatei für --write")
|
||||
p.add_argument(
|
||||
"--write",
|
||||
action="store_true",
|
||||
help="requirements-Datei schreiben statt installieren",
|
||||
)
|
||||
p.add_argument(
|
||||
"-o",
|
||||
"--output",
|
||||
type=Path,
|
||||
default=PROJECT_DIR / "requirements.txt",
|
||||
help="Zieldatei für --write",
|
||||
)
|
||||
args = p.parse_args()
|
||||
|
||||
if not args.pyproject.exists():
|
||||
@@ -104,18 +135,32 @@ def main() -> int:
|
||||
deps = collect(data, extras, groups, args.no_main)
|
||||
except (KeyError, ValueError) as e:
|
||||
print(f"Fehler: {e.args[0]}", file=sys.stderr)
|
||||
print(f" Vorhandene --extra: {', '.join(all_extras) or '(keine)'}", file=sys.stderr)
|
||||
print(f" Vorhandene --group: {', '.join(all_groups) or '(keine)'}", file=sys.stderr)
|
||||
print(
|
||||
f" Vorhandene --extra: {', '.join(all_extras) or '(keine)'}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(
|
||||
f" Vorhandene --group: {', '.join(all_groups) or '(keine)'}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 1
|
||||
|
||||
parts = ([] if args.no_main else ["Basis"]) + [f"extra:{e}" for e in extras] + [f"group:{g}" for g in groups]
|
||||
parts = (
|
||||
([] if args.no_main else ["Basis"])
|
||||
+ [f"extra:{e}" for e in extras]
|
||||
+ [f"group:{g}" for g in groups]
|
||||
)
|
||||
print(f"Auswahl: {', '.join(parts) or '(nichts)'}")
|
||||
|
||||
if args.list:
|
||||
print("\n".join(deps) or "(keine Abhängigkeiten)")
|
||||
return 0
|
||||
|
||||
content = f"# Automatisch erzeugt aus {args.pyproject.name} – nicht von Hand bearbeiten\n" + "\n".join(deps) + "\n"
|
||||
content = (
|
||||
f"# Automatisch erzeugt aus {args.pyproject.name} – nicht von Hand bearbeiten\n"
|
||||
+ "\n".join(deps)
|
||||
+ "\n"
|
||||
)
|
||||
|
||||
if args.write:
|
||||
args.output.write_text(content, encoding="utf-8")
|
||||
@@ -127,17 +172,26 @@ def main() -> int:
|
||||
return 0
|
||||
|
||||
if sys.prefix == sys.base_prefix:
|
||||
print("WARNUNG: Es ist kein virtuelles Environment aktiv – es wird in die globale "
|
||||
f"Python-Installation installiert:\n {sys.prefix}", file=sys.stderr)
|
||||
if sys.stdin.isatty() and input("Trotzdem fortfahren? [j/N] ").strip().lower() not in ("j", "ja", "y", "yes"):
|
||||
print(
|
||||
"WARNUNG: Es ist kein virtuelles Environment aktiv – es wird in die globale "
|
||||
f"Python-Installation installiert:\n {sys.prefix}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
if sys.stdin.isatty() and input(
|
||||
"Trotzdem fortfahren? [j/N] "
|
||||
).strip().lower() not in ("j", "ja", "y", "yes"):
|
||||
return 1
|
||||
|
||||
with tempfile.NamedTemporaryFile("w", suffix=".txt", delete=False, encoding="utf-8") as tmp:
|
||||
with tempfile.NamedTemporaryFile(
|
||||
"w", suffix=".txt", delete=False, encoding="utf-8"
|
||||
) as tmp:
|
||||
tmp.write(content)
|
||||
tmp_path = Path(tmp.name)
|
||||
try:
|
||||
print(f"Installiere {len(deps)} Abhängigkeiten in {sys.prefix}\n")
|
||||
return subprocess.call([sys.executable, "-m", "pip", "install", "-r", str(tmp_path)])
|
||||
return subprocess.call(
|
||||
[sys.executable, "-m", "pip", "install", "-r", str(tmp_path)]
|
||||
)
|
||||
finally:
|
||||
tmp_path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
Reference in new issue
Block a user