Skip to content

Commit fa6fa72

Browse files
committed
Add --verify-only option
1 parent f4d0f63 commit fa6fa72

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

scripts/generate-pixi-toml.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import argparse
34
import shlex
45
import shutil
56
import subprocess
@@ -38,6 +39,16 @@ class WorkingDirectoryPaths(NamedTuple):
3839

3940

4041
def main():
42+
parser = argparse.ArgumentParser(
43+
description="Generate pixi.toml from environment files"
44+
)
45+
parser.add_argument(
46+
"--verify-only",
47+
action="store_true",
48+
help="Only verify that pixi.toml is consistent with environment files, don't write",
49+
)
50+
args = parser.parse_args()
51+
4152
# Check if pixi is installed
4253
if not shutil.which("pixi"):
4354
print("pixi is not installed. See <https://pixi.sh/latest/#installation>") # noqa: T201
@@ -105,10 +116,29 @@ def main():
105116

106117
# Generate the pixi.toml content
107118
pixi_toml_content = tomlkit.dumps(pixi_toml_data)
108-
(project_root / "pixi.toml").write_text(pixi_toml_content)
109119

110-
# Clean up
111-
cleanup_working_directory(working_directory_paths)
120+
if args.verify_only:
121+
# Compare with existing pixi.toml
122+
pixi_toml_file = project_root / "pixi.toml"
123+
if not pixi_toml_file.exists():
124+
print("ERROR: pixi.toml does not exist") # noqa: T201
125+
cleanup_working_directory(working_directory_paths)
126+
sys.exit(1)
127+
128+
existing_content = pixi_toml_file.read_text()
129+
if existing_content != pixi_toml_content:
130+
print("ERROR: pixi.toml is not consistent with environment files") # noqa: T201
131+
print("Run 'python scripts/generate-pixi-toml.py' to update it") # noqa: T201
132+
cleanup_working_directory(working_directory_paths)
133+
sys.exit(1)
134+
135+
print("SUCCESS: pixi.toml is consistent with environment files") # noqa: T201
136+
cleanup_working_directory(working_directory_paths)
137+
sys.exit(0)
138+
else:
139+
# Write the pixi.toml file to the project root
140+
(project_root / "pixi.toml").write_text(pixi_toml_content)
141+
cleanup_working_directory(working_directory_paths)
112142

113143

114144
def cleanup_working_directory(working_paths: WorkingDirectoryPaths):

0 commit comments

Comments
 (0)