Skip to content

Commit b655ecd

Browse files
authored
Merge pull request #173 from NeurodataWithoutBorders/add-old-version-util
2 parents 43b7d7a + 7ee632a commit b655ecd

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
Extract dependencies from pyproject.toml, resolve versions at a specific date,
3+
and creates a new environment.yaml with version constraints.
4+
Use for testing historical versions of packages before benchmarks results
5+
database and automated publishing was finalized.
6+
"""
7+
8+
import subprocess
9+
import tempfile
10+
11+
12+
def create_older_environment_yaml(
13+
packages_to_restrict: tuple[str],
14+
exclude_newer_date: str = "2025-06-30",
15+
output_file_base: str = "nwb_benchmarks",
16+
):
17+
# create temporary input requirements file
18+
with tempfile.NamedTemporaryFile(mode="w", suffix=".txt") as tmp_file:
19+
tmp_file.write("\n".join(packages_to_restrict))
20+
tmp_file.flush()
21+
tmp_path = tmp_file.name
22+
23+
with tempfile.NamedTemporaryFile(mode="w", suffix=".txt") as tmp_out:
24+
tmp_out_path = tmp_out.name
25+
26+
# run uv pip compile to get versions from a specific date
27+
cmd = ["uv", "pip", "compile", tmp_path, "--exclude-newer", exclude_newer_date, "-o", tmp_out_path]
28+
subprocess.run(cmd)
29+
30+
# parse the output to get pinned versions based on date
31+
pinned_requirements = {}
32+
with open(tmp_out_path, "r") as f:
33+
for line in f:
34+
if "==" in line:
35+
pkg_name = line.split("==")[0].strip()
36+
version = line.split("==")[1].split()[0].strip()
37+
pinned_requirements[pkg_name] = version
38+
39+
# save to new output file
40+
# NOTE: will create very minimal environment file, rest of dependencies will be installed with -e ..
41+
with open(f"environments/{output_file_base}_{exclude_newer_date}.yaml", "w") as f:
42+
f.write(
43+
f"name: nwb_benchmarks_{exclude_newer_date}\n"
44+
f"dependencies:\n"
45+
f" - python == 3.11\n" # use for consistency
46+
f" - git\n"
47+
f" - conda-forge::h5py <={pinned_requirements['h5py']}\n"
48+
f" - pip\n"
49+
f" - pip:\n"
50+
)
51+
for pkg, version in sorted(pinned_requirements.items()):
52+
if pkg in packages_to_restrict and pkg not in ["h5py"]:
53+
f.write(f" - {pkg}<={version}\n")
54+
f.write(f" - -e ..\n")
55+
56+
57+
if __name__ == "__main__":
58+
# restrict key packages of interest to specific dates
59+
# no versions of lindi pre 2024-03 and other more difficult dependency resolution issues, so stop at 2024-06-30
60+
packages_to_restrict = ["h5py", "dandi", "zarr", "fsspec", "lindi", "s3fs", "aiohttp", "boto3"]
61+
create_older_environment_yaml(exclude_newer_date="2025-06-30", packages_to_restrict=packages_to_restrict)
62+
create_older_environment_yaml(exclude_newer_date="2024-06-30", packages_to_restrict=packages_to_restrict)

0 commit comments

Comments
 (0)