mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00

As mentioned in #746, instead of just installing the scenario root we will unpack the root dependencies into the install command to allow better coverage of direct user requests with scenarios. I added display of the package tree provided by each scenario. Use a mustache template for iterative replacements.
56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Generates snapshot test cases from packse scenarios.
|
|
#
|
|
# Usage:
|
|
# $ scripts/scenarios/generate.py > crates/puffin-cli/tests/pip_install_scenarios.rs
|
|
|
|
try:
|
|
import packse
|
|
except ImportError:
|
|
print("packse must be installed")
|
|
exit(1)
|
|
|
|
|
|
try:
|
|
import chevron_blue
|
|
except ImportError:
|
|
print("chevron-blue must be installed")
|
|
exit(1)
|
|
|
|
|
|
import sys
|
|
import subprocess
|
|
import json
|
|
from pathlib import Path
|
|
|
|
__dir__ = Path(__file__).parent
|
|
|
|
TEMPLATE = __dir__ / "template.mustache"
|
|
DATA = __dir__ / "data.json"
|
|
|
|
data = json.loads(
|
|
subprocess.check_output(
|
|
[
|
|
"packse",
|
|
"inspect",
|
|
str(packse.__development_base_path__ / "scenarios"),
|
|
],
|
|
)
|
|
)
|
|
|
|
# Add a generated
|
|
data["generated_by"] = f"Generated by `{' '.join(sys.argv)}`"
|
|
|
|
# Add normalized names for tests
|
|
for scenario in data["scenarios"]:
|
|
scenario["normalized_name"] = scenario["name"].replace("-", "_")
|
|
|
|
# Drop the example scenario
|
|
for index, scenario in enumerate(data["scenarios"]):
|
|
if scenario["name"] == "example":
|
|
data["scenarios"].pop(index)
|
|
|
|
output = chevron_blue.render(template=TEMPLATE.read_text(), data=data, no_escape=True)
|
|
|
|
print(output)
|