|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 |
|
| 3 | +import argparse |
3 | 4 | import shlex
|
4 | 5 | import shutil
|
5 | 6 | import subprocess
|
@@ -38,6 +39,16 @@ class WorkingDirectoryPaths(NamedTuple):
|
38 | 39 |
|
39 | 40 |
|
40 | 41 | 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 | + |
41 | 52 | # Check if pixi is installed
|
42 | 53 | if not shutil.which("pixi"):
|
43 | 54 | print("pixi is not installed. See <https://pixi.sh/latest/#installation>") # noqa: T201
|
@@ -105,10 +116,29 @@ def main():
|
105 | 116 |
|
106 | 117 | # Generate the pixi.toml content
|
107 | 118 | pixi_toml_content = tomlkit.dumps(pixi_toml_data)
|
108 |
| - (project_root / "pixi.toml").write_text(pixi_toml_content) |
109 | 119 |
|
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) |
112 | 142 |
|
113 | 143 |
|
114 | 144 | def cleanup_working_directory(working_paths: WorkingDirectoryPaths):
|
|
0 commit comments