Skip to content

Commit 58cb93c

Browse files
encountermkst
authored andcommitted
Use Python inline script metadata for template.py
1 parent 00d1460 commit 58cb93c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ The values that are used to populate the templates are found in values.yaml.
1313

1414
Rather than modifying the Dockerfiles directly, the `.j2` template should be changed and the Dockerfiles regenerated.
1515

16+
```sh
17+
uv run template.py
18+
```
19+
20+
Or, if you don't have `uv` installed:
21+
1622
```sh
1723
python3 -m pip install Jinja2 pyyaml
18-
python3 template.py values.yaml
24+
python3 template.py
1925
```
2026

2127
## Notes:

template.py

100644100755
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#!/usr/bin/env -S uv run --script
2+
# /// script
3+
# requires-python = ">=3.12"
4+
# dependencies = [
5+
# "jinja2",
6+
# "pyyaml",
7+
# ]
8+
# ///
19
import argparse
210
from pathlib import Path
311

@@ -10,7 +18,9 @@ def main():
1018
parser = argparse.ArgumentParser()
1119
parser.add_argument(
1220
"filename",
13-
type=argparse.FileType("r"),
21+
type=Path,
22+
nargs="?",
23+
default=Path("values.yaml"),
1424
help="Configuration file, e.g. `values.yaml`",
1525
)
1626
parser.add_argument(
@@ -33,7 +43,8 @@ def main():
3343
loader=FileSystemLoader(args.template_dir), autoescape=select_autoescape()
3444
)
3545

36-
values = yaml.safe_load(args.filename)
46+
with args.filename.open("r") as f:
47+
values = yaml.safe_load(f)
3748
for compiler in values.get("compilers", []):
3849
if "arch" in compiler:
3950
target_path = (

0 commit comments

Comments
 (0)