Skip to content

Commit 77249fd

Browse files
committed
Run diff between original and new pixi.toml on verification failure
1 parent 67fc58d commit 77249fd

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

scripts/generate-pixi-toml.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ class WorkingDirectoryPaths(NamedTuple):
110110
pyproject_file: Path # ./pixi-working/pyproject.toml
111111
environment_file: Path # ./pixi-working/environment.yml
112112
environment_blas_file: Path # ./pixi-working/scripts/environment-blas.yml
113-
pixi_toml_file: Path # ./pixi-working/pixi.toml
113+
raw_generated_pixi_toml: Path # ./pixi-working/pixi-raw.toml
114+
processed_generated_pixi_toml: Path # ./pixi-working/pixi-processed.toml
114115
gitignore_file: Path # ./pixi-working/.gitignore
115116

116117

@@ -173,21 +174,34 @@ def main():
173174
# Write the unprocessed pixi.toml data to the working directory
174175
pixi_toml_raw_data = tomlkit.loads(result.stdout.decode("utf-8"))
175176
pixi_toml_raw_content = tomlkit.dumps(pixi_toml_raw_data)
176-
working_directory_paths.pixi_toml_file.write_text(pixi_toml_raw_content)
177+
working_directory_paths.raw_generated_pixi_toml.write_text(pixi_toml_raw_content)
177178

178179
# Generate the pixi.toml content
179180
pixi_toml_data = postprocess_pixi_toml_data(pixi_toml_raw_data)
180181
pixi_toml_content = tomlkit.dumps(pixi_toml_data)
182+
working_directory_paths.processed_generated_pixi_toml.write_text(pixi_toml_content)
181183

182184
if args.verify_only:
183185
# Compare with existing pixi.toml
184186
existing_pixi_toml_content = original_paths.pixi_toml_file.read_text()
185187
if existing_pixi_toml_content != pixi_toml_content:
188+
# Run diff command to show the differences
189+
cmd = [
190+
"diff",
191+
"-u",
192+
str(original_paths.pixi_toml_file),
193+
str(working_directory_paths.processed_generated_pixi_toml),
194+
]
195+
diff_result = subprocess.run(cmd, capture_output=True, text=True)
196+
186197
message = dedent("""\
187198
Mismatch detected between existing and new pixi.toml content.
188199
189-
New pixi.toml content:
190-
{pixi_toml_content}
200+
Diff command:
201+
{diff_command}
202+
203+
Diff output:
204+
{diff_output}
191205
192206
Run 'python scripts/generate-pixi-toml.py' to regenerate it.
193207
After updating `pixi.toml`, it's suggested to run the following commands:
@@ -200,7 +214,7 @@ def main():
200214
201215
ERROR: pixi.toml is not consistent with environment files.
202216
See above for details.
203-
""").format(pixi_toml_content=pixi_toml_content)
217+
""").format(diff_command=shlex.join(cmd), diff_output=diff_result.stdout)
204218
print(message) # noqa: T201
205219
sys.exit(1)
206220

@@ -245,14 +259,16 @@ def initialize_working_directory(
245259
pyproject_file = working_path / "pyproject.toml"
246260
environment_file = working_path / "environment.yml"
247261
environment_blas_file = working_path / "scripts" / "environment-blas.yml"
248-
pixi_toml_file = working_path / "pixi.toml"
262+
raw_generated_pixi_toml = working_path / "pixi-raw.toml"
263+
processed_generated_pixi_toml = working_path / "pixi-processed.toml"
249264

250265
return WorkingDirectoryPaths(
251266
working_path=working_path,
252267
pyproject_file=pyproject_file,
253268
environment_file=environment_file,
254269
environment_blas_file=environment_blas_file,
255-
pixi_toml_file=pixi_toml_file,
270+
raw_generated_pixi_toml=raw_generated_pixi_toml,
271+
processed_generated_pixi_toml=processed_generated_pixi_toml,
256272
gitignore_file=gitignore_file,
257273
)
258274

@@ -263,7 +279,8 @@ def cleanup_working_directory(working_paths: WorkingDirectoryPaths):
263279
working_paths.environment_file.unlink()
264280
working_paths.environment_blas_file.unlink()
265281
working_paths.environment_blas_file.parent.rmdir()
266-
working_paths.pixi_toml_file.unlink()
282+
working_paths.raw_generated_pixi_toml.unlink()
283+
working_paths.processed_generated_pixi_toml.unlink()
267284
working_paths.gitignore_file.unlink()
268285
working_paths.working_path.rmdir()
269286

0 commit comments

Comments
 (0)