Skip to content

Commit f4d0f63

Browse files
committed
Refactor cleanup
1 parent 7022f41 commit f4d0f63

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

scripts/generate-pixi-toml.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@
55
import subprocess
66
import sys
77
from pathlib import Path
8+
from typing import NamedTuple
89

910
import tomlkit
1011
import tomlkit.items
1112

1213

14+
class WorkingDirectoryPaths(NamedTuple):
15+
"""Paths within the temporary working directory"""
16+
17+
working_path: Path
18+
working_pyproject_file: Path
19+
working_environment_file: Path
20+
working_environment_blas_file: Path
21+
pixi_toml_raw_file: Path
22+
gitignore_file: Path
23+
24+
1325
RAW_COMMAND = """
1426
pixi exec conda-lock render-lock-spec \
1527
--channel=conda-forge \
@@ -82,17 +94,32 @@ def main():
8294

8395
pixi_toml_data = postprocess_pixi_toml_data(pixi_toml_raw_data)
8496

85-
# Write the pixi.toml file to the project root
86-
(project_root / "pixi.toml").write_text(tomlkit.dumps(pixi_toml_data))
97+
working_directory_paths = WorkingDirectoryPaths(
98+
working_path=working_path,
99+
working_pyproject_file=working_pyproject_file,
100+
working_environment_file=working_environment_file,
101+
working_environment_blas_file=working_environment_blas_file,
102+
pixi_toml_raw_file=pixi_toml_raw_file,
103+
gitignore_file=gitignore_file,
104+
)
105+
106+
# Generate the pixi.toml content
107+
pixi_toml_content = tomlkit.dumps(pixi_toml_data)
108+
(project_root / "pixi.toml").write_text(pixi_toml_content)
87109

88110
# Clean up
89-
working_pyproject_file.unlink()
90-
working_environment_file.unlink()
91-
working_environment_blas_file.unlink()
92-
working_environment_blas_file.parent.rmdir()
93-
pixi_toml_raw_file.unlink()
94-
gitignore_file.unlink()
95-
working_path.rmdir()
111+
cleanup_working_directory(working_directory_paths)
112+
113+
114+
def cleanup_working_directory(working_paths: WorkingDirectoryPaths):
115+
"""Clean up the temporary working directory and files"""
116+
working_paths.working_pyproject_file.unlink()
117+
working_paths.working_environment_file.unlink()
118+
working_paths.working_environment_blas_file.unlink()
119+
working_paths.working_environment_blas_file.parent.rmdir()
120+
working_paths.pixi_toml_raw_file.unlink()
121+
working_paths.gitignore_file.unlink()
122+
working_paths.working_path.rmdir()
96123

97124

98125
def preprocess_pyproject_data(

0 commit comments

Comments
 (0)