Skip to content

Commit d10d38b

Browse files
committed
Rearrange args
1 parent b99b18e commit d10d38b

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

.pre-commit-hooks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
types: [toml]
77

88
- id: check-eol-cached
9-
name: Check supported Python EOL (cached)
10-
entry: checkeol --cached
9+
name: Check supported Python EOL (cache only)
10+
entry: checkeol --cache_only
1111
language: python
1212
files: '^pyproject.toml$'
1313
types: [toml]

pre_commit_python_eol/check_eol.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,17 @@ def from_json(cls, ver: str, metadata: dict[str, t.Any]) -> PythonRelease:
8181
end_of_life=_parse_eol_date(metadata["end_of_life"]),
8282
)
8383

84-
def is_eol(self, cached: bool) -> bool:
85-
"""Check if this version is end-of-life."""
84+
def is_eol(self, use_system_date: bool) -> bool:
85+
"""
86+
Check if this version is end-of-life.
87+
88+
If `use_system_date` is `True`, an additional date-based check is performed for versions
89+
that are not explicitly EOL.
90+
"""
8691
if self.status == ReleasePhase.EOL:
8792
return True
8893

89-
# When running cached, don't use the current date, and trust .status
90-
if not cached:
94+
if use_system_date:
9195
utc_today = dt.datetime.now(dt.timezone.utc).date()
9296
if self.end_of_life <= utc_today:
9397
return True
@@ -114,13 +118,16 @@ def _get_cached_release_cycle(cache_json: Path) -> list[PythonRelease]:
114118

115119

116120
def check_python_support(
117-
toml_file: Path, *, cached: bool = False, cache_json: Path = CACHED_RELEASE_CYCLE
121+
toml_file: Path, cache_json: Path = CACHED_RELEASE_CYCLE, use_system_date: bool = True
118122
) -> None:
119123
"""
120124
Check the input TOML's `requires-python` for overlap with EOL Python version(s).
121125
122126
If overlap(s) are present, an exception is raised whose message enumerates all EOL Python
123127
versions supported by the TOML file.
128+
129+
If `use_system_date` is `True`, an additional date-based check is performed for versions that
130+
are not explicitly EOL.
124131
"""
125132
with toml_file.open("rb") as f:
126133
contents = tomllib.load(f)
@@ -132,7 +139,9 @@ def check_python_support(
132139
package_spec = specifiers.SpecifierSet(requires_python)
133140
release_cycle = _get_cached_release_cycle(cache_json)
134141

135-
eol_supported = [r for r in release_cycle if r.python_ver in package_spec and r.is_eol(cached)]
142+
eol_supported = [
143+
r for r in release_cycle if ((r.python_ver in package_spec) and r.is_eol(use_system_date))
144+
]
136145

137146
if eol_supported:
138147
eol_supported.sort(key=attrgetter("python_ver")) # Sort ascending for error msg generation
@@ -143,13 +152,13 @@ def check_python_support(
143152
def main(argv: abc.Sequence[str] | None = None) -> int: # noqa: D103
144153
parser = argparse.ArgumentParser()
145154
parser.add_argument("filenames", nargs="*", type=Path)
146-
parser.add_argument("--cached", action="store_true")
155+
parser.add_argument("--cache_only", action="store_true")
147156
args = parser.parse_args(argv)
148157

149158
ec = 0
150159
for file in args.filenames:
151160
try:
152-
check_python_support(file, cached=args.cached)
161+
check_python_support(file, use_system_date=(not args.cache_only))
153162
except EOLPythonError as e:
154163
print(f"{file}: {e}")
155164
ec = 1

tests/test_check_eol.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ def test_check_python_support_multi_eol_raises(path_with_cache: tuple[Path, Path
215215
assert str(e.value).endswith("3.7, 3.8")
216216

217217

218+
def test_check_cached_python_support_single_eol_no_raises_by_date(
219+
path_with_cache: tuple[Path, Path],
220+
) -> None:
221+
base_path, cache_path = path_with_cache
222+
pyproject = base_path / "pyproject.toml"
223+
pyproject.write_text(SAMPLE_PYPROJECT_SINGLE_EOL_BY_DATE)
224+
225+
with time_machine.travel(dt.date(year=2031, month=11, day=1)):
226+
check_python_support(
227+
pyproject,
228+
cache_json=cache_path,
229+
use_system_date=False,
230+
)
231+
232+
218233
def test_check_cached_python_support_no_eol(path_with_cache: tuple[Path, Path]) -> None:
219234
base_path, cache_path = path_with_cache
220235
pyproject = base_path / "pyproject.toml"
@@ -223,7 +238,7 @@ def test_check_cached_python_support_no_eol(path_with_cache: tuple[Path, Path])
223238
check_python_support(
224239
pyproject,
225240
cache_json=cache_path,
226-
cached=True,
241+
use_system_date=False,
227242
)
228243

229244

@@ -236,22 +251,7 @@ def test_check_cached_python_support_single_eol_raises(path_with_cache: tuple[Pa
236251
check_python_support(
237252
pyproject,
238253
cache_json=cache_path,
239-
cached=True,
254+
use_system_date=False,
240255
)
241256

242257
assert str(e.value).endswith("3.8")
243-
244-
245-
def test_check_cached_python_support_single_eol_no_raises_by_date(
246-
path_with_cache: tuple[Path, Path],
247-
) -> None:
248-
base_path, cache_path = path_with_cache
249-
pyproject = base_path / "pyproject.toml"
250-
pyproject.write_text(SAMPLE_PYPROJECT_SINGLE_EOL_BY_DATE)
251-
252-
with time_machine.travel(dt.date(year=2031, month=11, day=1)):
253-
check_python_support(
254-
pyproject,
255-
cache_json=cache_path,
256-
cached=True,
257-
)

0 commit comments

Comments
 (0)