|
5 | 5 | import subprocess
|
6 | 6 | import sys
|
7 | 7 | from pathlib import Path
|
| 8 | +from typing import NamedTuple |
8 | 9 |
|
9 | 10 | import tomlkit
|
10 | 11 | import tomlkit.items
|
11 | 12 |
|
12 | 13 |
|
| 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 | + |
13 | 25 | RAW_COMMAND = """
|
14 | 26 | pixi exec conda-lock render-lock-spec \
|
15 | 27 | --channel=conda-forge \
|
@@ -82,17 +94,32 @@ def main():
|
82 | 94 |
|
83 | 95 | pixi_toml_data = postprocess_pixi_toml_data(pixi_toml_raw_data)
|
84 | 96 |
|
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) |
87 | 109 |
|
88 | 110 | # 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() |
96 | 123 |
|
97 | 124 |
|
98 | 125 | def preprocess_pyproject_data(
|
|
0 commit comments