|
3 | 3 |
|
4 | 4 | import argparse |
5 | 5 | import subprocess |
| 6 | +from concurrent.futures import ThreadPoolExecutor |
6 | 7 | from pathlib import Path |
7 | 8 |
|
8 | 9 | import toml as tomllib |
@@ -62,56 +63,64 @@ def update_conda(source_dir: Path) -> None: |
62 | 63 | print(f"pyproject.toml not found in {pyproject_toml}") |
63 | 64 | return |
64 | 65 |
|
65 | | - for platform_key, platform_value in platforms.items(): |
66 | | - for python in pythons: |
67 | | - dependencies = get_dependencies(pyproject_toml, python) |
68 | | - for tag in tags: |
69 | | - # Pin Python version |
70 | | - pinned_dependencies = { |
71 | | - f"python={python}" if dep == "python" else dep |
72 | | - for dep in dependencies |
73 | | - } |
74 | | - |
75 | | - dev_dependencies = get_dev_dependencies(pyproject_toml) |
76 | | - print(f"Adding dev dependencies: {dev_dependencies}") |
77 | | - pinned_dependencies = pinned_dependencies.union(dev_dependencies) |
78 | | - |
79 | | - pinned_dependencies = sorted(pinned_dependencies) |
80 | | - |
81 | | - env_file = source_dir / f"environment{tag}-{python}.yml" |
82 | | - write_env_file(env_file, pinned_dependencies) |
83 | | - lock_file = source_dir / f"environment{tag}-{python}-{platform_value}" |
84 | | - lock_file_gen = ( |
85 | | - source_dir / f"environment{tag}-{python}-{platform_value}.yml" |
86 | | - ) |
87 | | - print( |
88 | | - f"Updating lock file for {env_file} at {lock_file_gen}", flush=True |
89 | | - ) |
90 | | - subprocess.run( |
91 | | - [ |
92 | | - "conda-lock", |
93 | | - "--mamba", |
94 | | - "--channel", |
95 | | - "conda-forge", |
96 | | - "--kind", |
97 | | - "env", |
98 | | - "--platform", |
99 | | - platform_key, |
100 | | - "--file", |
101 | | - str(env_file), |
102 | | - "--lockfile", |
103 | | - str(lock_file), |
104 | | - "--filename-template", |
105 | | - str(lock_file), |
106 | | - ], |
107 | | - check=True, |
108 | | - ) |
109 | | - |
110 | | - # Add conda env name to lock file at beginning |
111 | | - with open(lock_file_gen, "r+") as f: |
112 | | - content = f.read() |
113 | | - f.seek(0, 0) |
114 | | - f.write(f"name: sage{tag or '-dev'}\n{content}") |
| 66 | + def process_platform_python(platform_key, platform_value, python): |
| 67 | + dependencies = get_dependencies(pyproject_toml, python) |
| 68 | + for tag in tags: |
| 69 | + # Pin Python version |
| 70 | + pinned_dependencies = { |
| 71 | + f"python={python}" if dep == "python" else dep |
| 72 | + for dep in dependencies |
| 73 | + } |
| 74 | + |
| 75 | + dev_dependencies = get_dev_dependencies(pyproject_toml) |
| 76 | + print(f"Adding dev dependencies: {dev_dependencies}") |
| 77 | + pinned_dependencies = pinned_dependencies.union(dev_dependencies) |
| 78 | + |
| 79 | + pinned_dependencies = sorted(pinned_dependencies) |
| 80 | + |
| 81 | + env_file = source_dir / f"environment{tag}-{python}.yml" |
| 82 | + write_env_file(env_file, pinned_dependencies) |
| 83 | + lock_file = source_dir / f"environment{tag}-{python}-{platform_value}" |
| 84 | + lock_file_gen = ( |
| 85 | + source_dir / f"environment{tag}-{python}-{platform_value}.yml" |
| 86 | + ) |
| 87 | + print( |
| 88 | + f"Updating lock file for {env_file} at {lock_file_gen}", flush=True |
| 89 | + ) |
| 90 | + subprocess.run( |
| 91 | + [ |
| 92 | + "conda-lock", |
| 93 | + "--mamba", |
| 94 | + "--channel", |
| 95 | + "conda-forge", |
| 96 | + "--kind", |
| 97 | + "env", |
| 98 | + "--platform", |
| 99 | + platform_key, |
| 100 | + "--file", |
| 101 | + str(env_file), |
| 102 | + "--lockfile", |
| 103 | + str(lock_file), |
| 104 | + "--filename-template", |
| 105 | + str(lock_file), |
| 106 | + ], |
| 107 | + check=True, |
| 108 | + ) |
| 109 | + |
| 110 | + # Add conda env name to lock file at beginning |
| 111 | + with open(lock_file_gen, "r+") as f: |
| 112 | + content = f.read() |
| 113 | + f.seek(0, 0) |
| 114 | + f.write(f"name: sage{tag or '-dev'}\n{content}") |
| 115 | + |
| 116 | + with ThreadPoolExecutor() as executor: |
| 117 | + futures = [ |
| 118 | + executor.submit(process_platform_python, platform_key, platform_value, python) |
| 119 | + for platform_key, platform_value in platforms.items() |
| 120 | + for python in pythons |
| 121 | + ] |
| 122 | + for future in futures: |
| 123 | + future.result() |
115 | 124 |
|
116 | 125 |
|
117 | 126 | def get_dependencies(pyproject_toml: Path, python: str) -> list[str]: |
|
0 commit comments