Skip to content

Commit 3245de2

Browse files
committed
fix: take past quarters into account for updates
1 parent c9ba4f0 commit 3245de2

6 files changed

Lines changed: 65 additions & 49 deletions

File tree

spec0_action/__init__.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from packaging.specifiers import SpecifierSet
2-
from typing import Sequence, cast
2+
from typing import Sequence, Dict
33
import datetime
44

55
from spec0_action.versions import repr_spec_set, tighten_lower_bound
@@ -15,20 +15,18 @@
1515
)
1616
from packaging.version import Version
1717

18-
1918
__all__ = ["read_schedule", "read_toml", "write_toml", "update_pyproject_toml"]
2019

21-
22-
def update_pyproject_dependencies(dependencies: dict, schedule: SupportSchedule):
20+
def update_pyproject_dependencies(dependencies: dict, schedule: Dict[str, str]):
2321
# Iterate by idx because we want to update it inplace
2422
for i in range(len(dependencies)):
2523
dep_str = dependencies[i]
2624
pkg, extras, spec, env = parse_pep_dependency(dep_str)
2725

28-
if isinstance(spec, Url) or pkg not in schedule["packages"]:
26+
if isinstance(spec, Url) or pkg not in schedule:
2927
continue
3028

31-
new_lower_bound = Version(schedule["packages"][pkg])
29+
new_lower_bound = Version(schedule[pkg])
3230
try:
3331
spec = tighten_lower_bound(spec or SpecifierSet(), new_lower_bound)
3432
# Will raise a value error if bound is already tighter, in this case we just do nothing and continue
@@ -75,42 +73,43 @@ def update_dependency_table(dep_table: dict, new_versions: dict):
7573
pkg_data["version"] = repr_spec_set(spec)
7674

7775

78-
def update_pixi_dependencies(pixi_tables: dict, schedule: SupportSchedule):
79-
if "pypi-dependencies" in pixi_tables:
80-
update_dependency_table(pixi_tables["pypi-dependencies"], schedule["packages"])
81-
if "dependencies" in pixi_tables:
82-
update_dependency_table(pixi_tables["dependencies"], schedule["packages"])
76+
def update_pixi_dependencies(pixi_tables: dict, schedule: Dict[str, str]):
77+
if "pypi-dependencies" in pixi_tables:
78+
update_dependency_table(pixi_tables["pypi-dependencies"], schedule)
79+
if "dependencies" in pixi_tables:
80+
update_dependency_table(pixi_tables["dependencies"], schedule)
8381

8482
if "feature" in pixi_tables:
8583
for _, feature_data in pixi_tables["feature"].items():
8684
if "dependencies" in feature_data:
87-
update_dependency_table(
88-
feature_data["dependencies"], schedule["packages"]
89-
)
85+
update_dependency_table(feature_data["dependencies"], schedule)
9086

9187

9288
def update_pyproject_toml(
9389
pyproject_data: dict, schedule_data: Sequence[SupportSchedule]
9490
):
9591
now = datetime.datetime.now(datetime.UTC)
96-
try:
97-
new_version = cast(
98-
SupportSchedule,
99-
next(
100-
filter(
101-
lambda s: now >= datetime.datetime.fromisoformat(s["start_date"]),
102-
schedule_data,
103-
)
104-
),
105-
)
106-
except StopIteration:
92+
applicable = sorted(
93+
filter(
94+
lambda s: now >= datetime.datetime.fromisoformat(s["start_date"]),
95+
schedule_data,
96+
),
97+
key=lambda s: datetime.datetime.fromisoformat(s["start_date"]),
98+
)
99+
new_version = {}
100+
for schedule in applicable:
101+
# Fill in the latest known requirement (schedule is sorted, newer entries overwrite older)
102+
for pkg, version in schedule["packages"].items():
103+
new_version[pkg] = version
104+
105+
if not new_version:
107106
raise RuntimeError(
108107
"Could not find schedule that applies to current time, perhaps your schedule is outdated."
109108
)
110109

111-
if "python" in new_version["packages"]:
110+
if "python" in new_version:
112111
pyproject_data["project"]["requires-python"] = repr_spec_set(
113-
parse_version_spec(new_version["packages"]["python"])
112+
parse_version_spec(new_version["python"])
114113
)
115114
update_pyproject_dependencies(
116115
pyproject_data["project"]["dependencies"], new_version

tests/test_data/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ requires-python = ">=3.11"
1313
dependencies = [
1414
'pandas>=1.0.0,<3',
1515
'xarray>=2021.1.0',
16-
"ipython>=8.7.0,<4",
17-
"numpy[foo,bar]>=1.10.0,<2",
18-
"scikit-learn>1.2,<1.4;sys_platform=='win32'",
16+
"ipython>=8.7.0",
17+
"numpy[foo,bar]>=1.10.0",
18+
"scikit-learn>1.3,<1.5;sys_platform=='win32'",
1919
"scikit-learn>1.2;sys_platform!='win32'"
2020
]

tests/test_data/pyproject_pixi.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ description = "This is just a dummy package for testing the spec 0 update gi
55
requires-python = ">=3.10"
66
version = "0.1.0"
77
dependencies = [
8-
"ipython>=8.7.0,<4",
9-
"numpy[foo,bar]>=1.10.0,<2",
10-
"scikit-learn>1.2,<1.4;sys_platform=='win32'",
8+
"ipython>=8.7.0",
9+
"numpy[foo,bar]>=1.10.0",
10+
"scikit-learn>1.2,<1.5;sys_platform=='win32'",
1111
"scikit-learn>1.2;sys_platform!='win32'"
1212
]
1313

tests/test_data/pyproject_pixi_updated.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
authors = [{ name = "Scientific Python Developers"}]
33
name = "tests"
44
description = "This is just a dummy package for testing the spec 0 update github action and should not be used"
5-
requires-python = ">=3.11"
5+
requires-python = ">=3.12"
66
version = "0.1.0"
77
dependencies = [
8-
"ipython>=8.8.0,<4",
9-
"numpy[foo,bar]>=1.25.0,<2",
10-
"scikit-learn>=1.3.0,<1.4;sys_platform=='win32'",
11-
"scikit-learn>=1.3.0;sys_platform!='win32'"
8+
"ipython>=8.20.0",
9+
"numpy[foo,bar]>=2.0.0",
10+
"scikit-learn>=1.4.0,<1.5;sys_platform=='win32'",
11+
"scikit-learn>=1.4.0;sys_platform!='win32'"
1212
]
1313
[build-system]
1414
build-backend = "hatchling.build"
@@ -20,15 +20,15 @@ platforms = ["linux-64"]
2020

2121
[tool.pixi.pypi-dependencies]
2222
tests = { path = ".", editable = true }
23-
scikit-learn = ">=1.3.0"
23+
scikit-learn = ">=1.4.0"
2424

2525
[tool.pixi.tasks]
2626

2727
[tool.pixi.feature.foo.dependencies]
28-
xarray = ">=2023.1.0"
28+
xarray = ">=2024.1.0"
2929

3030
[tool.pixi.environments]
3131
bar = ["foo"]
3232

3333
[tool.pixi.dependencies]
34-
numpy = ">=1.25.0,<2"
34+
numpy = ">=2.0.0,<2"

tests/test_data/pyproject_updated.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ build-backend = "setuptools.build_meta"
99
[project]
1010
name = "setuptools_test"
1111
version = "0.1.0"
12-
requires-python = ">=3.11"
12+
requires-python = ">=3.12"
1313
dependencies = [
14-
'pandas>=1.0.0,<3',
15-
'xarray>=2023.1.0',
16-
"ipython>=8.8.0,<4",
17-
"numpy[foo,bar]>=1.25.0,<2",
18-
"scikit-learn>=1.3.0,<1.4;sys_platform=='win32'",
19-
"scikit-learn>=1.3.0;sys_platform!='win32'"
14+
'pandas>=2.2.0,<3',
15+
'xarray>=2024.1.0',
16+
"ipython>=8.20.0",
17+
"numpy[foo,bar]>=2.0.0",
18+
"scikit-learn>=1.4.0,<1.5;sys_platform=='win32'",
19+
"scikit-learn>=1.4.0;sys_platform!='win32'"
2020
]

tests/test_update_pyproject_toml.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
import datetime
2+
3+
import pytest
4+
15
from spec0_action.parsing import read_schedule, read_toml
26
from spec0_action import update_pyproject_toml
37

8+
# Fixed time to avoid test results changing over time...
9+
FAKE_TIME = datetime.datetime(2025, 10, 30, 0, 0, 0, tzinfo=datetime.UTC)
10+
11+
@pytest.fixture
12+
def patch_datetime_now(monkeypatch):
13+
14+
class mydatetime(datetime.datetime):
15+
@classmethod
16+
def now(cls, *args, **kwds):
17+
return FAKE_TIME
18+
19+
monkeypatch.setattr(datetime, 'datetime', mydatetime)
20+
421

5-
def test_update_pyproject_toml():
22+
def test_update_pyproject_toml(patch_datetime_now):
623
expected = read_toml("tests/test_data/pyproject_updated.toml")
724
pyproject_data = read_toml("tests/test_data/pyproject.toml")
825
test_schedule = read_schedule("tests/test_data/test_schedule.json")

0 commit comments

Comments
 (0)