Skip to content

Commit 9a02aab

Browse files
committed
Add a script to pin the oldest versions of dependencies
1 parent 4298960 commit 9a02aab

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ requires = ["poetry>=1.2"]
5454
build-backend = "poetry.masonry.api"
5555

5656
[tool.mypy]
57-
files = "examples/,src/,tests/"
57+
files = "examples/,scripts/,src/,tests/"
5858
plugins = "numpy.typing.mypy_plugin"
5959
namespace_packages = true
6060
strict = true
@@ -65,4 +65,4 @@ skips = [
6565
]
6666

6767
[tool.pyright]
68-
include = ["src/", "tests/"]
68+
include = ["examples/", "scripts/", "src/", "tests/"]

scripts/pin_oldest_deps.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Pin dependencies to the oldest compatible version for testing."""
2+
3+
from __future__ import annotations
4+
5+
import sys
6+
from pathlib import Path
7+
8+
import tomlkit
9+
from tomlkit.items import AbstractTable, Array
10+
11+
12+
def main(args: list[str]) -> int | str | None:
13+
"""Pin dependencies to the oldest compatible version for testing."""
14+
pyproject_path = Path(args.pop())
15+
if args:
16+
return f"Unsupported arguments: {args!r}"
17+
pyproject = tomlkit.loads(pyproject_path.read_text())
18+
poetry_deps = pyproject["tool"]["poetry"]["dependencies"] # type: ignore[index]
19+
assert isinstance(poetry_deps, AbstractTable)
20+
21+
for dep, value in poetry_deps.items():
22+
if dep == "python":
23+
continue
24+
if isinstance(value, str) and (
25+
value.startswith("^") or value.startswith("~") or value.startswith(">=")
26+
):
27+
poetry_deps[dep] = "==" + value.lstrip("^~>=")
28+
elif isinstance(value, Array):
29+
for constraint in value:
30+
if "version" in constraint and (
31+
constraint["version"].startswith("^")
32+
or constraint["version"].startswith("~")
33+
or constraint["version"].startswith(">=")
34+
):
35+
constraint["version"] = "==" + constraint["version"].lstrip("^~>=")
36+
37+
pyproject_path.write_text(tomlkit.dumps(pyproject))
38+
print("Updated pyproject.toml with pinned dependencies.")
39+
return None
40+
41+
42+
if __name__ == "__main__":
43+
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)