Skip to content

Commit 42c83fb

Browse files
rd4398claude
andcommitted
refactor(bootstrap): make --max-release-age optional with IntRange(min=1)
Change --max-release-age to default=None with IntRange(min=1) so that 0 is rejected by Click and the flag is no longer required with --multiple-versions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Rohan Devasthale <rdevasth@redhat.com>
1 parent e0fa9e5 commit 42c83fb

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

src/fromager/commands/bootstrap.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ def _get_requirements_from_args(
113113
@click.option(
114114
"--max-release-age",
115115
"max_release_age",
116-
type=click.IntRange(min=0),
117-
default=0,
118-
help="Reject package versions published more than this many days ago (0 disables the check). Required with --multiple-versions.",
116+
type=click.IntRange(min=1),
117+
default=None,
118+
help="Reject package versions published more than this many days ago.",
119119
)
120120
@click.argument("toplevel", nargs=-1)
121121
@click.pass_obj
@@ -128,7 +128,7 @@ def bootstrap(
128128
skip_constraints: bool,
129129
test_mode: bool,
130130
multiple_versions: bool,
131-
max_release_age: int,
131+
max_release_age: int | None,
132132
toplevel: list[str],
133133
) -> None:
134134
"""Compute and build the dependencies of a set of requirements recursively
@@ -164,10 +164,6 @@ def bootstrap(
164164
)
165165

166166
if multiple_versions:
167-
if max_release_age <= 0:
168-
raise click.UsageError(
169-
"--max-release-age is required when using --multiple-versions"
170-
)
171167
logger.info(
172168
"multiple versions mode enabled: will bootstrap all matching versions"
173169
)
@@ -180,7 +176,7 @@ def bootstrap(
180176
)
181177
skip_constraints = True
182178

183-
if max_release_age > 0:
179+
if max_release_age is not None:
184180
wkctx.set_max_release_age(max_release_age)
185181
logger.info(
186182
"max release age: rejecting versions older than %d days",
@@ -514,9 +510,9 @@ def write_constraints_file(
514510
@click.option(
515511
"--max-release-age",
516512
"max_release_age",
517-
type=click.IntRange(min=0),
518-
default=0,
519-
help="Reject package versions published more than this many days ago (0 disables the check). Required with --multiple-versions.",
513+
type=click.IntRange(min=1),
514+
default=None,
515+
help="Reject package versions published more than this many days ago.",
520516
)
521517
@click.argument("toplevel", nargs=-1)
522518
@click.pass_obj
@@ -532,7 +528,7 @@ def bootstrap_parallel(
532528
force: bool,
533529
max_workers: int | None,
534530
multiple_versions: bool,
535-
max_release_age: int,
531+
max_release_age: int | None,
536532
toplevel: list[str],
537533
) -> None:
538534
"""Bootstrap and build-parallel

tests/test_bootstrap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,10 @@ def test_without_multiple_versions_constraints_not_disabled(
684684
assert mock_write_constraints.called
685685

686686

687-
def test_multiple_versions_requires_max_release_age(
687+
def test_max_release_age_rejects_zero(
688688
tmp_context: context.WorkContext,
689689
) -> None:
690-
"""Test that --multiple-versions without --max-release-age fails."""
690+
"""Test that --max-release-age 0 is rejected by Click's IntRange(min=1)."""
691691
runner = CliRunner()
692692
with runner.isolated_filesystem():
693693
pathlib.Path("req.txt").write_text("setuptools>=60\n")
@@ -696,12 +696,12 @@ def test_multiple_versions_requires_max_release_age(
696696
[
697697
"-r",
698698
"req.txt",
699-
"--multiple-versions",
699+
"--max-release-age",
700+
"0",
700701
],
701702
obj=tmp_context,
702703
)
703704
assert result.exit_code == 2
704-
assert "--max-release-age is required" in result.output
705705

706706

707707
@patch("fromager.commands.bootstrap.bootstrapper.Bootstrapper")

0 commit comments

Comments
 (0)