Skip to content

Commit ec48c2c

Browse files
authored
Run conda env updates in parallel
1 parent 9647a82 commit ec48c2c

File tree

1 file changed

+59
-50
lines changed

1 file changed

+59
-50
lines changed

tools/update-conda.py

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import argparse
55
import subprocess
6+
from concurrent.futures import ThreadPoolExecutor
67
from pathlib import Path
78

89
import toml as tomllib
@@ -62,56 +63,64 @@ def update_conda(source_dir: Path) -> None:
6263
print(f"pyproject.toml not found in {pyproject_toml}")
6364
return
6465

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()
115124

116125

117126
def get_dependencies(pyproject_toml: Path, python: str) -> list[str]:

0 commit comments

Comments
 (0)