Skip to content

Commit e1f274a

Browse files
committed
Change name to uploaded prior to
1 parent 61ec9b0 commit e1f274a

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
@@ -167,8 +167,8 @@ def install(
167167
args.append("--pre")
168168
if finder.prefer_binary:
169169
args.append("--prefer-binary")
170-
if finder.exclude_newer_than:
171-
args.extend(["--exclude-newer-than", finder.exclude_newer_than.isoformat()])
170+
if finder.uploaded_prior_to:
171+
args.extend(["--uploaded-prior-to", finder.uploaded_prior_to.isoformat()])
172172
args.append("--")
173173
args.extend(requirements)
174174
with open_spinner(f"Installing {kind}") as spinner:

src/pip/_internal/cli/cmdoptions.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -798,13 +798,11 @@ def _handle_dependency_group(
798798
)
799799

800800

801-
def _handle_exclude_newer_than(
801+
def _handle_uploaded_prior_to(
802802
option: Option, opt: str, value: str, parser: OptionParser
803803
) -> None:
804804
"""
805-
Process a value provided for the --exclude-newer-than option.
806-
807-
This is an optparse.Option callback for the --exclude-newer-than option.
805+
This is an optparse.Option callback for the --uploaded-prior-to option.
808806
809807
Parses an ISO 8601 datetime string. If no timezone is specified in the string,
810808
local timezone is used.
@@ -817,32 +815,33 @@ def _handle_exclude_newer_than(
817815
return None
818816

819817
try:
820-
exclude_newer_than = parse_iso_datetime(value)
818+
uploaded_prior_to = parse_iso_datetime(value)
821819
# Use local timezone if no offset is given in the ISO string.
822-
if exclude_newer_than.tzinfo is None:
823-
exclude_newer_than = exclude_newer_than.astimezone()
824-
parser.values.exclude_newer_than = exclude_newer_than
820+
if uploaded_prior_to.tzinfo is None:
821+
uploaded_prior_to = uploaded_prior_to.astimezone()
822+
parser.values.uploaded_prior_to = uploaded_prior_to
825823
except ValueError as exc:
826824
msg = (
827-
f"invalid --exclude-newer-than value: {value!r}: {exc}. "
825+
f"invalid --uploaded-prior-to value: {value!r}: {exc}. "
828826
f"Expected an ISO 8601 datetime string, "
829827
f"e.g '2023-01-01' or '2023-01-01T00:00:00Z'"
830828
)
831829
raise_option_error(parser, option=option, msg=msg)
832830

833831

834-
exclude_newer_than: Callable[..., Option] = partial(
832+
uploaded_prior_to: Callable[..., Option] = partial(
835833
Option,
836-
"--exclude-newer-than",
837-
dest="exclude_newer_than",
834+
"--uploaded-prior-to",
835+
dest="uploaded_prior_to",
838836
metavar="datetime",
839837
action="callback",
840-
callback=_handle_exclude_newer_than,
838+
callback=_handle_uploaded_prior_to,
841839
type="str",
842840
help=(
843-
"Exclude packages newer than given time. Accepts ISO 8601 strings "
844-
"(e.g., '2023-01-01T00:00:00Z'). Uses local timezone if none specified. "
845-
"Only effective when installing from indexes that provide upload-time metadata."
841+
"Only consider packages uploaded prior to the given date time. "
842+
"Accepts ISO 8601 strings (e.g., '2023-01-01T00:00:00Z'). "
843+
"Uses local timezone if none specified. Only effective when "
844+
"installing from indexes that provide upload-time metadata."
846845
),
847846
)
848847

src/pip/_internal/cli/req_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,5 @@ def _build_package_finder(
348348
link_collector=link_collector,
349349
selection_prefs=selection_prefs,
350350
target_python=target_python,
351-
exclude_newer_than=options.exclude_newer_than,
351+
uploaded_prior_to=options.uploaded_prior_to,
352352
)

src/pip/_internal/commands/download.py

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

5656
self.cmd_opts.add_option(
5757
"-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
@@ -207,7 +207,7 @@ def add_options(self) -> None:
207207
),
208208
)
209209

210-
self.cmd_opts.add_option(cmdoptions.exclude_newer_than())
210+
self.cmd_opts.add_option(cmdoptions.uploaded_prior_to())
211211
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
212212
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
213213
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
@@ -67,7 +67,7 @@ def add_options(self) -> None:
6767
self.cmd_opts.add_option(cmdoptions.src())
6868

6969
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
70-
self.cmd_opts.add_option(cmdoptions.exclude_newer_than())
70+
self.cmd_opts.add_option(cmdoptions.uploaded_prior_to())
7171
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
7272
self.cmd_opts.add_option(cmdoptions.use_pep517())
7373
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
@@ -64,7 +64,7 @@ def add_options(self) -> None:
6464
self.cmd_opts.add_option(cmdoptions.requirements())
6565
self.cmd_opts.add_option(cmdoptions.src())
6666
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
67-
self.cmd_opts.add_option(cmdoptions.exclude_newer_than())
67+
self.cmd_opts.add_option(cmdoptions.uploaded_prior_to())
6868
self.cmd_opts.add_option(cmdoptions.no_deps())
6969
self.cmd_opts.add_option(cmdoptions.progress_bar())
7070

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)