Skip to content

Commit 2a9f0ea

Browse files
committed
Change name to uploaded prior to
1 parent 8ea6f77 commit 2a9f0ea

File tree

15 files changed

+152
-113
lines changed

15 files changed

+152
-113
lines changed

news/13520.feature.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Add ``--exclude-newer-than`` option to exclude packages uploaded after a given date,
2-
only effective with indexes that provide upload-time metadata.
1+
Add ``--uploaded-prior-to`` option to only consider packages uploaded prior to
2+
a given datetime when the ``upload-time`` field is available from an index.

src/pip/_internal/build_env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ def install(
230230
# in the isolated build environment
231231
extra_environ = {"extra_environ": {"_PIP_IN_BUILD_IGNORE_CONSTRAINTS": "1"}}
232232

233-
if finder.exclude_newer_than:
234-
args.extend(["--exclude-newer-than", finder.exclude_newer_than.isoformat()])
233+
if finder.uploaded_prior_to:
234+
args.extend(["--uploaded-prior-to", finder.uploaded_prior_to.isoformat()])
235235
args.append("--")
236236
args.extend(requirements)
237237

src/pip/_internal/cli/cmdoptions.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -836,13 +836,11 @@ def _handle_dependency_group(
836836
)
837837

838838

839-
def _handle_exclude_newer_than(
839+
def _handle_uploaded_prior_to(
840840
option: Option, opt: str, value: str, parser: OptionParser
841841
) -> None:
842842
"""
843-
Process a value provided for the --exclude-newer-than option.
844-
845-
This is an optparse.Option callback for the --exclude-newer-than option.
843+
This is an optparse.Option callback for the --uploaded-prior-to option.
846844
847845
Parses an ISO 8601 datetime string. If no timezone is specified in the string,
848846
local timezone is used.
@@ -855,32 +853,33 @@ def _handle_exclude_newer_than(
855853
return None
856854

857855
try:
858-
exclude_newer_than = parse_iso_datetime(value)
856+
uploaded_prior_to = parse_iso_datetime(value)
859857
# Use local timezone if no offset is given in the ISO string.
860-
if exclude_newer_than.tzinfo is None:
861-
exclude_newer_than = exclude_newer_than.astimezone()
862-
parser.values.exclude_newer_than = exclude_newer_than
858+
if uploaded_prior_to.tzinfo is None:
859+
uploaded_prior_to = uploaded_prior_to.astimezone()
860+
parser.values.uploaded_prior_to = uploaded_prior_to
863861
except ValueError as exc:
864862
msg = (
865-
f"invalid --exclude-newer-than value: {value!r}: {exc}. "
863+
f"invalid --uploaded-prior-to value: {value!r}: {exc}. "
866864
f"Expected an ISO 8601 datetime string, "
867865
f"e.g '2023-01-01' or '2023-01-01T00:00:00Z'"
868866
)
869867
raise_option_error(parser, option=option, msg=msg)
870868

871869

872-
exclude_newer_than: Callable[..., Option] = partial(
870+
uploaded_prior_to: Callable[..., Option] = partial(
873871
Option,
874-
"--exclude-newer-than",
875-
dest="exclude_newer_than",
872+
"--uploaded-prior-to",
873+
dest="uploaded_prior_to",
876874
metavar="datetime",
877875
action="callback",
878-
callback=_handle_exclude_newer_than,
876+
callback=_handle_uploaded_prior_to,
879877
type="str",
880878
help=(
881-
"Exclude packages newer than given time. Accepts ISO 8601 strings "
882-
"(e.g., '2023-01-01T00:00:00Z'). Uses local timezone if none specified. "
883-
"Only effective when installing from indexes that provide upload-time metadata."
879+
"Only consider packages uploaded prior to the given date time. "
880+
"Accepts ISO 8601 strings (e.g., '2023-01-01T00:00:00Z'). "
881+
"Uses local timezone if none specified. Only effective when "
882+
"installing from indexes that provide upload-time metadata."
884883
),
885884
)
886885

src/pip/_internal/cli/req_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,5 +371,5 @@ def _build_package_finder(
371371
link_collector=link_collector,
372372
selection_prefs=selection_prefs,
373373
target_python=target_python,
374-
exclude_newer_than=options.exclude_newer_than,
374+
uploaded_prior_to=options.uploaded_prior_to,
375375
)

src/pip/_internal/commands/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def add_options(self) -> None:
5252
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
5353
self.cmd_opts.add_option(cmdoptions.check_build_deps())
5454
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
55-
self.cmd_opts.add_option(cmdoptions.exclude_newer_than())
55+
self.cmd_opts.add_option(cmdoptions.uploaded_prior_to())
5656

5757
self.cmd_opts.add_option(
5858
"-d",

src/pip/_internal/commands/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def add_options(self) -> None:
4040
cmdoptions.add_target_python_options(self.cmd_opts)
4141

4242
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
43-
self.cmd_opts.add_option(cmdoptions.exclude_newer_than())
43+
self.cmd_opts.add_option(cmdoptions.uploaded_prior_to())
4444
self.cmd_opts.add_option(cmdoptions.pre())
4545
self.cmd_opts.add_option(cmdoptions.json())
4646
self.cmd_opts.add_option(cmdoptions.no_binary())
@@ -104,7 +104,7 @@ def _build_package_finder(
104104
link_collector=link_collector,
105105
selection_prefs=selection_prefs,
106106
target_python=target_python,
107-
exclude_newer_than=options.exclude_newer_than,
107+
uploaded_prior_to=options.uploaded_prior_to,
108108
)
109109

110110
def get_available_package_versions(self, options: Values, args: list[Any]) -> None:

src/pip/_internal/commands/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def add_options(self) -> None:
208208
),
209209
)
210210

211-
self.cmd_opts.add_option(cmdoptions.exclude_newer_than())
211+
self.cmd_opts.add_option(cmdoptions.uploaded_prior_to())
212212
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
213213
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
214214
self.cmd_opts.add_option(cmdoptions.use_pep517())

src/pip/_internal/commands/lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def add_options(self) -> None:
6868
self.cmd_opts.add_option(cmdoptions.src())
6969

7070
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
71-
self.cmd_opts.add_option(cmdoptions.exclude_newer_than())
71+
self.cmd_opts.add_option(cmdoptions.uploaded_prior_to())
7272
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
7373
self.cmd_opts.add_option(cmdoptions.use_pep517())
7474
self.cmd_opts.add_option(cmdoptions.no_use_pep517())

src/pip/_internal/commands/wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def add_options(self) -> None:
6565
self.cmd_opts.add_option(cmdoptions.requirements())
6666
self.cmd_opts.add_option(cmdoptions.src())
6767
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
68-
self.cmd_opts.add_option(cmdoptions.exclude_newer_than())
68+
self.cmd_opts.add_option(cmdoptions.uploaded_prior_to())
6969
self.cmd_opts.add_option(cmdoptions.no_deps())
7070
self.cmd_opts.add_option(cmdoptions.progress_bar())
7171

src/pip/_internal/index/package_finder.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init__(
134134
target_python: TargetPython,
135135
allow_yanked: bool,
136136
ignore_requires_python: bool | None = None,
137-
exclude_newer_than: datetime.datetime | None = None,
137+
uploaded_prior_to: datetime.datetime | None = None,
138138
) -> None:
139139
"""
140140
:param project_name: The user supplied package name.
@@ -152,7 +152,8 @@ def __init__(
152152
:param ignore_requires_python: Whether to ignore incompatible
153153
PEP 503 "data-requires-python" values in HTML links. Defaults
154154
to False.
155-
:param exclude_newer_than: If set, only allow links prior to the given date.
155+
:param uploaded_prior_to: If set, only allow links uploaded prior to
156+
the given datetime.
156157
"""
157158
if ignore_requires_python is None:
158159
ignore_requires_python = False
@@ -162,7 +163,7 @@ def __init__(
162163
self._ignore_requires_python = ignore_requires_python
163164
self._formats = formats
164165
self._target_python = target_python
165-
self._exclude_newer_than = exclude_newer_than
166+
self._uploaded_prior_to = uploaded_prior_to
166167

167168
self.project_name = project_name
168169

@@ -181,10 +182,11 @@ def evaluate_link(self, link: Link) -> tuple[LinkType, str]:
181182
reason = link.yanked_reason or "<none given>"
182183
return (LinkType.yanked, f"yanked for reason: {reason}")
183184

184-
if link.upload_time is not None and self._exclude_newer_than is not None:
185-
if link.upload_time > self._exclude_newer_than:
185+
if link.upload_time is not None and self._uploaded_prior_to is not None:
186+
if link.upload_time >= self._uploaded_prior_to:
186187
reason = (
187-
f"Upload time {link.upload_time} after {self._exclude_newer_than}"
188+
f"Upload time {link.upload_time} not "
189+
f"prior to {self._uploaded_prior_to}"
188190
)
189191
return (LinkType.upload_too_late, reason)
190192

@@ -605,7 +607,7 @@ def __init__(
605607
format_control: FormatControl | None = None,
606608
candidate_prefs: CandidatePreferences | None = None,
607609
ignore_requires_python: bool | None = None,
608-
exclude_newer_than: datetime.datetime | None = None,
610+
uploaded_prior_to: datetime.datetime | None = None,
609611
) -> None:
610612
"""
611613
This constructor is primarily meant to be used by the create() class
@@ -627,7 +629,7 @@ def __init__(
627629
self._ignore_requires_python = ignore_requires_python
628630
self._link_collector = link_collector
629631
self._target_python = target_python
630-
self._exclude_newer_than = exclude_newer_than
632+
self._uploaded_prior_to = uploaded_prior_to
631633

632634
self.format_control = format_control
633635

@@ -651,7 +653,7 @@ def create(
651653
link_collector: LinkCollector,
652654
selection_prefs: SelectionPreferences,
653655
target_python: TargetPython | None = None,
654-
exclude_newer_than: datetime.datetime | None = None,
656+
uploaded_prior_to: datetime.datetime | None = None,
655657
) -> PackageFinder:
656658
"""Create a PackageFinder.
657659
@@ -660,7 +662,8 @@ def create(
660662
:param target_python: The target Python interpreter to use when
661663
checking compatibility. If None (the default), a TargetPython
662664
object will be constructed from the running Python.
663-
:param exclude_newer_than: If set, only find links prior to the given date.
665+
:param uploaded_prior_to: If set, only find links uploaded prior
666+
to the given datetime.
664667
"""
665668
if target_python is None:
666669
target_python = TargetPython()
@@ -677,7 +680,7 @@ def create(
677680
allow_yanked=selection_prefs.allow_yanked,
678681
format_control=selection_prefs.format_control,
679682
ignore_requires_python=selection_prefs.ignore_requires_python,
680-
exclude_newer_than=exclude_newer_than,
683+
uploaded_prior_to=uploaded_prior_to,
681684
)
682685

683686
@property
@@ -738,8 +741,8 @@ def set_prefer_binary(self) -> None:
738741
self._candidate_prefs.prefer_binary = True
739742

740743
@property
741-
def exclude_newer_than(self) -> datetime.datetime | None:
742-
return self._exclude_newer_than
744+
def uploaded_prior_to(self) -> datetime.datetime | None:
745+
return self._uploaded_prior_to
743746

744747
def requires_python_skipped_reasons(self) -> list[str]:
745748
reasons = {
@@ -760,7 +763,7 @@ def make_link_evaluator(self, project_name: str) -> LinkEvaluator:
760763
target_python=self._target_python,
761764
allow_yanked=self._allow_yanked,
762765
ignore_requires_python=self._ignore_requires_python,
763-
exclude_newer_than=self._exclude_newer_than,
766+
uploaded_prior_to=self._uploaded_prior_to,
764767
)
765768

766769
def _sort_links(self, links: Iterable[Link]) -> list[Link]:

0 commit comments

Comments
 (0)