Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .venv/lib/python3.12/site-packages/hf_xet-1.4.2.dist-info/licenses/LICENSE +201 -0
- .venv/lib/python3.12/site-packages/hf_xet-1.4.2.dist-info/sboms/hf_xet.cyclonedx.json +0 -0
- .venv/lib/python3.12/site-packages/pip/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv/lib/python3.12/site-packages/pip/__pycache__/__main__.cpython-312.pyc +0 -0
- .venv/lib/python3.12/site-packages/pip/__pycache__/__pip-runner__.cpython-312.pyc +0 -0
- .venv/lib/python3.12/site-packages/pip/_internal/__init__.py +18 -0
- .venv/lib/python3.12/site-packages/pip/_internal/build_env.py +606 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cache.py +291 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/__init__.py +3 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/autocompletion.py +184 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/base_command.py +255 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/cmdoptions.py +1267 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/command_context.py +28 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/index_command.py +195 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/main.py +85 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/main_parser.py +136 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/parser.py +358 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/progress_bars.py +153 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/req_command.py +447 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/spinners.py +235 -0
- .venv/lib/python3.12/site-packages/pip/_internal/cli/status_codes.py +6 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/__init__.py +139 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/cache.py +255 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/check.py +66 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/completion.py +136 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/configuration.py +288 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/debug.py +203 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/download.py +146 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/freeze.py +107 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/hash.py +58 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/help.py +40 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/index.py +166 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/inspect.py +92 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/install.py +810 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/list.py +398 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/lock.py +175 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/search.py +178 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/show.py +231 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/uninstall.py +113 -0
- .venv/lib/python3.12/site-packages/pip/_internal/commands/wheel.py +171 -0
- .venv/lib/python3.12/site-packages/pip/_internal/configuration.py +396 -0
- .venv/lib/python3.12/site-packages/pip/_internal/distributions/__init__.py +21 -0
- .venv/lib/python3.12/site-packages/pip/_internal/distributions/base.py +55 -0
- .venv/lib/python3.12/site-packages/pip/_internal/distributions/installed.py +33 -0
- .venv/lib/python3.12/site-packages/pip/_internal/distributions/sdist.py +164 -0
- .venv/lib/python3.12/site-packages/pip/_internal/distributions/wheel.py +44 -0
- .venv/lib/python3.12/site-packages/pip/_internal/exceptions.py +971 -0
- .venv/lib/python3.12/site-packages/pip/_internal/index/collector.py +488 -0
- .venv/lib/python3.12/site-packages/pip/_internal/index/package_finder.py +1125 -0
- .venv/lib/python3.12/site-packages/pip/_internal/index/sources.py +287 -0
.venv/lib/python3.12/site-packages/hf_xet-1.4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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
.venv/lib/python3.12/site-packages/hf_xet-1.4.2.dist-info/sboms/hf_xet.cyclonedx.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
.venv/lib/python3.12/site-packages/pip/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (646 Bytes). View file
|
|
|
.venv/lib/python3.12/site-packages/pip/__pycache__/__main__.cpython-312.pyc
ADDED
|
Binary file (836 Bytes). View file
|
|
|
.venv/lib/python3.12/site-packages/pip/__pycache__/__pip-runner__.cpython-312.pyc
ADDED
|
Binary file (2.2 kB). View file
|
|
|
.venv/lib/python3.12/site-packages/pip/_internal/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from pip._internal.utils import _log
|
| 4 |
+
|
| 5 |
+
# init_logging() must be called before any call to logging.getLogger()
|
| 6 |
+
# which happens at import of most modules.
|
| 7 |
+
_log.init_logging()
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def main(args: list[str] | None = None) -> int:
|
| 11 |
+
"""This is preserved for old console scripts that may still be referencing
|
| 12 |
+
it.
|
| 13 |
+
|
| 14 |
+
For additional details, see https://github.com/pypa/pip/issues/7498.
|
| 15 |
+
"""
|
| 16 |
+
from pip._internal.utils.entrypoints import _wrapper
|
| 17 |
+
|
| 18 |
+
return _wrapper(args)
|
.venv/lib/python3.12/site-packages/pip/_internal/build_env.py
ADDED
|
@@ -0,0 +1,606 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build Environment used for isolation during sdist building"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import site
|
| 9 |
+
import sys
|
| 10 |
+
import textwrap
|
| 11 |
+
from collections import OrderedDict
|
| 12 |
+
from collections.abc import Iterable, Sequence
|
| 13 |
+
from contextlib import AbstractContextManager as ContextManager
|
| 14 |
+
from contextlib import nullcontext
|
| 15 |
+
from io import StringIO
|
| 16 |
+
from types import TracebackType
|
| 17 |
+
from typing import TYPE_CHECKING, Protocol, TypedDict
|
| 18 |
+
|
| 19 |
+
from pip._vendor.packaging.version import Version
|
| 20 |
+
|
| 21 |
+
from pip import __file__ as pip_location
|
| 22 |
+
from pip._internal.cli.spinners import open_rich_spinner, open_spinner
|
| 23 |
+
from pip._internal.exceptions import (
|
| 24 |
+
BuildDependencyInstallError,
|
| 25 |
+
DiagnosticPipError,
|
| 26 |
+
InstallWheelBuildError,
|
| 27 |
+
PipError,
|
| 28 |
+
)
|
| 29 |
+
from pip._internal.locations import get_platlib, get_purelib, get_scheme
|
| 30 |
+
from pip._internal.metadata import get_default_environment, get_environment
|
| 31 |
+
from pip._internal.utils.deprecation import deprecated
|
| 32 |
+
from pip._internal.utils.logging import VERBOSE, capture_logging
|
| 33 |
+
from pip._internal.utils.packaging import get_requirement
|
| 34 |
+
from pip._internal.utils.subprocess import call_subprocess
|
| 35 |
+
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
| 36 |
+
|
| 37 |
+
if TYPE_CHECKING:
|
| 38 |
+
from pip._internal.cache import WheelCache
|
| 39 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 40 |
+
from pip._internal.operations.build.build_tracker import BuildTracker
|
| 41 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 42 |
+
from pip._internal.resolution.base import BaseResolver
|
| 43 |
+
|
| 44 |
+
class ExtraEnviron(TypedDict, total=False):
|
| 45 |
+
extra_environ: dict[str, str]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
logger = logging.getLogger(__name__)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def _dedup(a: str, b: str) -> tuple[str] | tuple[str, str]:
|
| 52 |
+
return (a, b) if a != b else (a,)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class _Prefix:
|
| 56 |
+
def __init__(self, path: str) -> None:
|
| 57 |
+
self.path = path
|
| 58 |
+
self.setup = False
|
| 59 |
+
scheme = get_scheme("", prefix=path)
|
| 60 |
+
self.bin_dir = scheme.scripts
|
| 61 |
+
self.lib_dirs = _dedup(scheme.purelib, scheme.platlib)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def get_runnable_pip() -> str:
|
| 65 |
+
"""Get a file to pass to a Python executable, to run the currently-running pip.
|
| 66 |
+
|
| 67 |
+
This is used to run a pip subprocess, for installing requirements into the build
|
| 68 |
+
environment.
|
| 69 |
+
"""
|
| 70 |
+
source = pathlib.Path(pip_location).resolve().parent
|
| 71 |
+
|
| 72 |
+
if not source.is_dir():
|
| 73 |
+
# This would happen if someone is using pip from inside a zip file. In that
|
| 74 |
+
# case, we can use that directly.
|
| 75 |
+
return str(source)
|
| 76 |
+
|
| 77 |
+
return os.fsdecode(source / "__pip-runner__.py")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def _get_system_sitepackages() -> set[str]:
|
| 81 |
+
"""Get system site packages
|
| 82 |
+
|
| 83 |
+
Usually from site.getsitepackages,
|
| 84 |
+
but fallback on `get_purelib()/get_platlib()` if unavailable
|
| 85 |
+
(e.g. in a virtualenv created by virtualenv<20)
|
| 86 |
+
|
| 87 |
+
Returns normalized set of strings.
|
| 88 |
+
"""
|
| 89 |
+
if hasattr(site, "getsitepackages"):
|
| 90 |
+
system_sites = site.getsitepackages()
|
| 91 |
+
else:
|
| 92 |
+
# virtualenv < 20 overwrites site.py without getsitepackages
|
| 93 |
+
# fallback on get_purelib/get_platlib.
|
| 94 |
+
# this is known to miss things, but shouldn't in the cases
|
| 95 |
+
# where getsitepackages() has been removed (inside a virtualenv)
|
| 96 |
+
system_sites = [get_purelib(), get_platlib()]
|
| 97 |
+
return {os.path.normcase(path) for path in system_sites}
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class BuildEnvironmentInstaller(Protocol):
|
| 101 |
+
"""
|
| 102 |
+
Interface for installing build dependencies into an isolated build
|
| 103 |
+
environment.
|
| 104 |
+
"""
|
| 105 |
+
|
| 106 |
+
def install(
|
| 107 |
+
self,
|
| 108 |
+
requirements: Iterable[str],
|
| 109 |
+
prefix: _Prefix,
|
| 110 |
+
*,
|
| 111 |
+
kind: str,
|
| 112 |
+
for_req: InstallRequirement | None,
|
| 113 |
+
) -> None: ...
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
class SubprocessBuildEnvironmentInstaller:
|
| 117 |
+
"""
|
| 118 |
+
Install build dependencies by calling pip in a subprocess.
|
| 119 |
+
"""
|
| 120 |
+
|
| 121 |
+
def __init__(
|
| 122 |
+
self,
|
| 123 |
+
finder: PackageFinder,
|
| 124 |
+
build_constraints: list[str] | None = None,
|
| 125 |
+
build_constraint_feature_enabled: bool = False,
|
| 126 |
+
) -> None:
|
| 127 |
+
self.finder = finder
|
| 128 |
+
self._build_constraints = build_constraints or []
|
| 129 |
+
self._build_constraint_feature_enabled = build_constraint_feature_enabled
|
| 130 |
+
|
| 131 |
+
def _deprecation_constraint_check(self) -> None:
|
| 132 |
+
"""
|
| 133 |
+
Check for deprecation warning: PIP_CONSTRAINT affecting build environments.
|
| 134 |
+
|
| 135 |
+
This warns when build-constraint feature is NOT enabled and PIP_CONSTRAINT
|
| 136 |
+
is not empty.
|
| 137 |
+
"""
|
| 138 |
+
if self._build_constraint_feature_enabled or self._build_constraints:
|
| 139 |
+
return
|
| 140 |
+
|
| 141 |
+
pip_constraint = os.environ.get("PIP_CONSTRAINT")
|
| 142 |
+
if not pip_constraint or not pip_constraint.strip():
|
| 143 |
+
return
|
| 144 |
+
|
| 145 |
+
deprecated(
|
| 146 |
+
reason=(
|
| 147 |
+
"Setting PIP_CONSTRAINT will not affect "
|
| 148 |
+
"build constraints in the future,"
|
| 149 |
+
),
|
| 150 |
+
replacement=(
|
| 151 |
+
"to specify build constraints using --build-constraint or "
|
| 152 |
+
"PIP_BUILD_CONSTRAINT. To disable this warning without "
|
| 153 |
+
"any build constraints set --use-feature=build-constraint or "
|
| 154 |
+
'PIP_USE_FEATURE="build-constraint"'
|
| 155 |
+
),
|
| 156 |
+
gone_in="26.2",
|
| 157 |
+
issue=None,
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
def install(
|
| 161 |
+
self,
|
| 162 |
+
requirements: Iterable[str],
|
| 163 |
+
prefix: _Prefix,
|
| 164 |
+
*,
|
| 165 |
+
kind: str,
|
| 166 |
+
for_req: InstallRequirement | None,
|
| 167 |
+
) -> None:
|
| 168 |
+
self._deprecation_constraint_check()
|
| 169 |
+
|
| 170 |
+
finder = self.finder
|
| 171 |
+
args: list[str] = [
|
| 172 |
+
sys.executable,
|
| 173 |
+
get_runnable_pip(),
|
| 174 |
+
"install",
|
| 175 |
+
"--ignore-installed",
|
| 176 |
+
"--no-user",
|
| 177 |
+
"--prefix",
|
| 178 |
+
prefix.path,
|
| 179 |
+
"--no-warn-script-location",
|
| 180 |
+
"--disable-pip-version-check",
|
| 181 |
+
# As the build environment is ephemeral, it's wasteful to
|
| 182 |
+
# pre-compile everything, especially as not every Python
|
| 183 |
+
# module will be used/compiled in most cases.
|
| 184 |
+
"--no-compile",
|
| 185 |
+
# The prefix specified two lines above, thus
|
| 186 |
+
# target from config file or env var should be ignored
|
| 187 |
+
"--target",
|
| 188 |
+
"",
|
| 189 |
+
]
|
| 190 |
+
if logger.getEffectiveLevel() <= logging.DEBUG:
|
| 191 |
+
args.append("-vv")
|
| 192 |
+
elif logger.getEffectiveLevel() <= VERBOSE:
|
| 193 |
+
args.append("-v")
|
| 194 |
+
for format_control in ("no_binary", "only_binary"):
|
| 195 |
+
formats = getattr(finder.format_control, format_control)
|
| 196 |
+
args.extend(
|
| 197 |
+
(
|
| 198 |
+
"--" + format_control.replace("_", "-"),
|
| 199 |
+
",".join(sorted(formats or {":none:"})),
|
| 200 |
+
)
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
if finder.release_control is not None:
|
| 204 |
+
# Use ordered args to preserve the user's original command-line order
|
| 205 |
+
# This is important because later flags can override earlier ones
|
| 206 |
+
for attr_name, value in finder.release_control.get_ordered_args():
|
| 207 |
+
args.extend(("--" + attr_name.replace("_", "-"), value))
|
| 208 |
+
|
| 209 |
+
index_urls = finder.index_urls
|
| 210 |
+
if index_urls:
|
| 211 |
+
args.extend(["-i", index_urls[0]])
|
| 212 |
+
for extra_index in index_urls[1:]:
|
| 213 |
+
args.extend(["--extra-index-url", extra_index])
|
| 214 |
+
else:
|
| 215 |
+
args.append("--no-index")
|
| 216 |
+
for link in finder.find_links:
|
| 217 |
+
args.extend(["--find-links", link])
|
| 218 |
+
|
| 219 |
+
if finder.proxy:
|
| 220 |
+
args.extend(["--proxy", finder.proxy])
|
| 221 |
+
for host in finder.trusted_hosts:
|
| 222 |
+
args.extend(["--trusted-host", host])
|
| 223 |
+
if finder.custom_cert:
|
| 224 |
+
args.extend(["--cert", finder.custom_cert])
|
| 225 |
+
if finder.client_cert:
|
| 226 |
+
args.extend(["--client-cert", finder.client_cert])
|
| 227 |
+
if finder.prefer_binary:
|
| 228 |
+
args.append("--prefer-binary")
|
| 229 |
+
|
| 230 |
+
# Handle build constraints
|
| 231 |
+
if self._build_constraint_feature_enabled:
|
| 232 |
+
args.extend(["--use-feature", "build-constraint"])
|
| 233 |
+
|
| 234 |
+
if self._build_constraints:
|
| 235 |
+
# Build constraints must be passed as both constraints
|
| 236 |
+
# and build constraints, so that nested builds receive
|
| 237 |
+
# build constraints
|
| 238 |
+
for constraint_file in self._build_constraints:
|
| 239 |
+
args.extend(["--constraint", constraint_file])
|
| 240 |
+
args.extend(["--build-constraint", constraint_file])
|
| 241 |
+
|
| 242 |
+
extra_environ: ExtraEnviron = {}
|
| 243 |
+
if self._build_constraint_feature_enabled and not self._build_constraints:
|
| 244 |
+
# If there are no build constraints but the build constraints
|
| 245 |
+
# feature is enabled then we must ignore regular constraints
|
| 246 |
+
# in the isolated build environment
|
| 247 |
+
extra_environ = {"extra_environ": {"_PIP_IN_BUILD_IGNORE_CONSTRAINTS": "1"}}
|
| 248 |
+
|
| 249 |
+
if finder.uploaded_prior_to:
|
| 250 |
+
args.extend(["--uploaded-prior-to", finder.uploaded_prior_to.isoformat()])
|
| 251 |
+
args.append("--")
|
| 252 |
+
args.extend(requirements)
|
| 253 |
+
|
| 254 |
+
identify_requirement = (
|
| 255 |
+
f" for {for_req.name}" if for_req and for_req.name else ""
|
| 256 |
+
)
|
| 257 |
+
with open_spinner(f"Installing {kind}") as spinner:
|
| 258 |
+
call_subprocess(
|
| 259 |
+
args,
|
| 260 |
+
command_desc=f"installing {kind}{identify_requirement}",
|
| 261 |
+
spinner=spinner,
|
| 262 |
+
**extra_environ,
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
class InprocessBuildEnvironmentInstaller:
|
| 267 |
+
"""
|
| 268 |
+
Build dependency installer that runs in the same pip process.
|
| 269 |
+
|
| 270 |
+
This contains a stripped down version of the install command with
|
| 271 |
+
only the logic necessary for installing build dependencies. The
|
| 272 |
+
finder, session, build tracker, and wheel cache are reused, but new
|
| 273 |
+
instances of everything else are created as needed.
|
| 274 |
+
|
| 275 |
+
Options are inherited from the parent install command unless
|
| 276 |
+
they don't make sense for build dependencies (in which case, they
|
| 277 |
+
are hard-coded, see comments below).
|
| 278 |
+
"""
|
| 279 |
+
|
| 280 |
+
def __init__(
|
| 281 |
+
self,
|
| 282 |
+
*,
|
| 283 |
+
finder: PackageFinder,
|
| 284 |
+
build_tracker: BuildTracker,
|
| 285 |
+
wheel_cache: WheelCache,
|
| 286 |
+
build_constraints: Sequence[InstallRequirement] = (),
|
| 287 |
+
verbosity: int = 0,
|
| 288 |
+
) -> None:
|
| 289 |
+
from pip._internal.operations.prepare import RequirementPreparer
|
| 290 |
+
|
| 291 |
+
self._finder = finder
|
| 292 |
+
self._build_constraints = build_constraints
|
| 293 |
+
self._wheel_cache = wheel_cache
|
| 294 |
+
self._level = 0
|
| 295 |
+
|
| 296 |
+
build_dir = TempDirectory(kind="build-env-install", globally_managed=True)
|
| 297 |
+
self._preparer = RequirementPreparer(
|
| 298 |
+
build_isolation_installer=self,
|
| 299 |
+
# Inherited options or state.
|
| 300 |
+
finder=finder,
|
| 301 |
+
session=finder._link_collector.session,
|
| 302 |
+
build_dir=build_dir.path,
|
| 303 |
+
build_tracker=build_tracker,
|
| 304 |
+
verbosity=verbosity,
|
| 305 |
+
# This is irrelevant as it only applies to editable requirements.
|
| 306 |
+
src_dir="",
|
| 307 |
+
# Hard-coded options (that should NOT be inherited).
|
| 308 |
+
download_dir=None,
|
| 309 |
+
build_isolation=True,
|
| 310 |
+
check_build_deps=False,
|
| 311 |
+
progress_bar="off",
|
| 312 |
+
# TODO: hash-checking should be extended to build deps, but that is
|
| 313 |
+
# deferred for later as it'd be a breaking change.
|
| 314 |
+
require_hashes=False,
|
| 315 |
+
use_user_site=False,
|
| 316 |
+
lazy_wheel=False,
|
| 317 |
+
legacy_resolver=False,
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
def install(
|
| 321 |
+
self,
|
| 322 |
+
requirements: Iterable[str],
|
| 323 |
+
prefix: _Prefix,
|
| 324 |
+
*,
|
| 325 |
+
kind: str,
|
| 326 |
+
for_req: InstallRequirement | None,
|
| 327 |
+
) -> None:
|
| 328 |
+
"""Install entrypoint. Manages output capturing and error handling."""
|
| 329 |
+
capture_logs = not logger.isEnabledFor(VERBOSE) and self._level == 0
|
| 330 |
+
if capture_logs:
|
| 331 |
+
# Hide the logs from the installation of build dependencies.
|
| 332 |
+
# They will be shown only if an error occurs.
|
| 333 |
+
capture_ctx: ContextManager[StringIO] = capture_logging()
|
| 334 |
+
spinner: ContextManager[None] = open_rich_spinner(f"Installing {kind}")
|
| 335 |
+
else:
|
| 336 |
+
# Otherwise, pass-through all logs (with a header).
|
| 337 |
+
capture_ctx, spinner = nullcontext(StringIO()), nullcontext()
|
| 338 |
+
logger.info("Installing %s ...", kind)
|
| 339 |
+
|
| 340 |
+
try:
|
| 341 |
+
self._level += 1
|
| 342 |
+
with spinner, capture_ctx as stream:
|
| 343 |
+
self._install_impl(requirements, prefix)
|
| 344 |
+
|
| 345 |
+
except DiagnosticPipError as exc:
|
| 346 |
+
# Format similar to a nested subprocess error, where the
|
| 347 |
+
# causing error is shown first, followed by the build error.
|
| 348 |
+
logger.info(textwrap.dedent(stream.getvalue()))
|
| 349 |
+
logger.error("%s", exc, extra={"rich": True})
|
| 350 |
+
logger.info("")
|
| 351 |
+
raise BuildDependencyInstallError(
|
| 352 |
+
for_req, requirements, cause=exc, log_lines=None
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
except Exception as exc:
|
| 356 |
+
logs: list[str] | None = textwrap.dedent(stream.getvalue()).splitlines()
|
| 357 |
+
if not capture_logs:
|
| 358 |
+
# If logs aren't being captured, then display the error inline
|
| 359 |
+
# with the rest of the logs.
|
| 360 |
+
logs = None
|
| 361 |
+
if isinstance(exc, PipError):
|
| 362 |
+
logger.error("%s", exc)
|
| 363 |
+
else:
|
| 364 |
+
logger.exception("pip crashed unexpectedly")
|
| 365 |
+
raise BuildDependencyInstallError(
|
| 366 |
+
for_req, requirements, cause=exc, log_lines=logs
|
| 367 |
+
)
|
| 368 |
+
|
| 369 |
+
finally:
|
| 370 |
+
self._level -= 1
|
| 371 |
+
|
| 372 |
+
def _install_impl(self, requirements: Iterable[str], prefix: _Prefix) -> None:
|
| 373 |
+
"""Core build dependency install logic."""
|
| 374 |
+
from pip._internal.commands.install import installed_packages_summary
|
| 375 |
+
from pip._internal.req import install_given_reqs
|
| 376 |
+
from pip._internal.req.constructors import install_req_from_line
|
| 377 |
+
from pip._internal.wheel_builder import build
|
| 378 |
+
|
| 379 |
+
ireqs = [install_req_from_line(req, user_supplied=True) for req in requirements]
|
| 380 |
+
ireqs.extend(self._build_constraints)
|
| 381 |
+
|
| 382 |
+
resolver = self._make_resolver()
|
| 383 |
+
resolved_set = resolver.resolve(ireqs, check_supported_wheels=True)
|
| 384 |
+
self._preparer.prepare_linked_requirements_more(
|
| 385 |
+
resolved_set.requirements.values()
|
| 386 |
+
)
|
| 387 |
+
|
| 388 |
+
reqs_to_build = [
|
| 389 |
+
r for r in resolved_set.requirements_to_install if not r.is_wheel
|
| 390 |
+
]
|
| 391 |
+
_, build_failures = build(reqs_to_build, self._wheel_cache, verify=True)
|
| 392 |
+
if build_failures:
|
| 393 |
+
raise InstallWheelBuildError(build_failures)
|
| 394 |
+
|
| 395 |
+
installed = install_given_reqs(
|
| 396 |
+
resolver.get_installation_order(resolved_set),
|
| 397 |
+
prefix=prefix.path,
|
| 398 |
+
# Hard-coded options (that should NOT be inherited).
|
| 399 |
+
root=None,
|
| 400 |
+
home=None,
|
| 401 |
+
warn_script_location=False,
|
| 402 |
+
use_user_site=False,
|
| 403 |
+
# As the build environment is ephemeral, it's wasteful to
|
| 404 |
+
# pre-compile everything since not all modules will be used.
|
| 405 |
+
pycompile=False,
|
| 406 |
+
progress_bar="off",
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
env = get_environment(list(prefix.lib_dirs))
|
| 410 |
+
if summary := installed_packages_summary(installed, env):
|
| 411 |
+
logger.info(summary)
|
| 412 |
+
|
| 413 |
+
def _make_resolver(self) -> BaseResolver:
|
| 414 |
+
"""Create a new resolver for one time use."""
|
| 415 |
+
# Legacy installer never used the legacy resolver so create a
|
| 416 |
+
# resolvelib resolver directly. Yuck.
|
| 417 |
+
from pip._internal.req.constructors import install_req_from_req_string
|
| 418 |
+
from pip._internal.resolution.resolvelib.resolver import Resolver
|
| 419 |
+
|
| 420 |
+
return Resolver(
|
| 421 |
+
make_install_req=install_req_from_req_string,
|
| 422 |
+
# Inherited state.
|
| 423 |
+
preparer=self._preparer,
|
| 424 |
+
finder=self._finder,
|
| 425 |
+
wheel_cache=self._wheel_cache,
|
| 426 |
+
# Hard-coded options (that should NOT be inherited).
|
| 427 |
+
ignore_requires_python=False,
|
| 428 |
+
use_user_site=False,
|
| 429 |
+
ignore_dependencies=False,
|
| 430 |
+
ignore_installed=True,
|
| 431 |
+
force_reinstall=False,
|
| 432 |
+
upgrade_strategy="to-satisfy-only",
|
| 433 |
+
py_version_info=None,
|
| 434 |
+
)
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
class BuildEnvironment:
|
| 438 |
+
"""Creates and manages an isolated environment to install build deps"""
|
| 439 |
+
|
| 440 |
+
def __init__(self, installer: BuildEnvironmentInstaller) -> None:
|
| 441 |
+
self.installer = installer
|
| 442 |
+
temp_dir = TempDirectory(kind=tempdir_kinds.BUILD_ENV, globally_managed=True)
|
| 443 |
+
|
| 444 |
+
self._prefixes = OrderedDict(
|
| 445 |
+
(name, _Prefix(os.path.join(temp_dir.path, name)))
|
| 446 |
+
for name in ("normal", "overlay")
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
self._bin_dirs: list[str] = []
|
| 450 |
+
self._lib_dirs: list[str] = []
|
| 451 |
+
for prefix in reversed(list(self._prefixes.values())):
|
| 452 |
+
self._bin_dirs.append(prefix.bin_dir)
|
| 453 |
+
self._lib_dirs.extend(prefix.lib_dirs)
|
| 454 |
+
|
| 455 |
+
# Customize site to:
|
| 456 |
+
# - ensure .pth files are honored
|
| 457 |
+
# - prevent access to system site packages
|
| 458 |
+
system_sites = _get_system_sitepackages()
|
| 459 |
+
|
| 460 |
+
self._site_dir = os.path.join(temp_dir.path, "site")
|
| 461 |
+
if not os.path.exists(self._site_dir):
|
| 462 |
+
os.mkdir(self._site_dir)
|
| 463 |
+
with open(
|
| 464 |
+
os.path.join(self._site_dir, "sitecustomize.py"), "w", encoding="utf-8"
|
| 465 |
+
) as fp:
|
| 466 |
+
fp.write(
|
| 467 |
+
textwrap.dedent(
|
| 468 |
+
"""
|
| 469 |
+
import os, site, sys
|
| 470 |
+
|
| 471 |
+
# First, drop system-sites related paths.
|
| 472 |
+
original_sys_path = sys.path[:]
|
| 473 |
+
known_paths = set()
|
| 474 |
+
for path in {system_sites!r}:
|
| 475 |
+
site.addsitedir(path, known_paths=known_paths)
|
| 476 |
+
system_paths = set(
|
| 477 |
+
os.path.normcase(path)
|
| 478 |
+
for path in sys.path[len(original_sys_path):]
|
| 479 |
+
)
|
| 480 |
+
original_sys_path = [
|
| 481 |
+
path for path in original_sys_path
|
| 482 |
+
if os.path.normcase(path) not in system_paths
|
| 483 |
+
]
|
| 484 |
+
sys.path = original_sys_path
|
| 485 |
+
|
| 486 |
+
# Second, add lib directories.
|
| 487 |
+
# ensuring .pth file are processed.
|
| 488 |
+
for path in {lib_dirs!r}:
|
| 489 |
+
assert not path in sys.path
|
| 490 |
+
site.addsitedir(path)
|
| 491 |
+
"""
|
| 492 |
+
).format(system_sites=system_sites, lib_dirs=self._lib_dirs)
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
+
def __enter__(self) -> None:
|
| 496 |
+
self._save_env = {
|
| 497 |
+
name: os.environ.get(name, None)
|
| 498 |
+
for name in ("PATH", "PYTHONNOUSERSITE", "PYTHONPATH")
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
path = self._bin_dirs[:]
|
| 502 |
+
old_path = self._save_env["PATH"]
|
| 503 |
+
if old_path:
|
| 504 |
+
path.extend(old_path.split(os.pathsep))
|
| 505 |
+
|
| 506 |
+
pythonpath = [self._site_dir]
|
| 507 |
+
|
| 508 |
+
os.environ.update(
|
| 509 |
+
{
|
| 510 |
+
"PATH": os.pathsep.join(path),
|
| 511 |
+
"PYTHONNOUSERSITE": "1",
|
| 512 |
+
"PYTHONPATH": os.pathsep.join(pythonpath),
|
| 513 |
+
}
|
| 514 |
+
)
|
| 515 |
+
|
| 516 |
+
def __exit__(
|
| 517 |
+
self,
|
| 518 |
+
exc_type: type[BaseException] | None,
|
| 519 |
+
exc_val: BaseException | None,
|
| 520 |
+
exc_tb: TracebackType | None,
|
| 521 |
+
) -> None:
|
| 522 |
+
for varname, old_value in self._save_env.items():
|
| 523 |
+
if old_value is None:
|
| 524 |
+
os.environ.pop(varname, None)
|
| 525 |
+
else:
|
| 526 |
+
os.environ[varname] = old_value
|
| 527 |
+
|
| 528 |
+
def check_requirements(
|
| 529 |
+
self, reqs: Iterable[str]
|
| 530 |
+
) -> tuple[set[tuple[str, str]], set[str]]:
|
| 531 |
+
"""Return 2 sets:
|
| 532 |
+
- conflicting requirements: set of (installed, wanted) reqs tuples
|
| 533 |
+
- missing requirements: set of reqs
|
| 534 |
+
"""
|
| 535 |
+
missing = set()
|
| 536 |
+
conflicting = set()
|
| 537 |
+
if reqs:
|
| 538 |
+
env = (
|
| 539 |
+
get_environment(self._lib_dirs)
|
| 540 |
+
if hasattr(self, "_lib_dirs")
|
| 541 |
+
else get_default_environment()
|
| 542 |
+
)
|
| 543 |
+
for req_str in reqs:
|
| 544 |
+
req = get_requirement(req_str)
|
| 545 |
+
# We're explicitly evaluating with an empty extra value, since build
|
| 546 |
+
# environments are not provided any mechanism to select specific extras.
|
| 547 |
+
if req.marker is not None and not req.marker.evaluate({"extra": ""}):
|
| 548 |
+
continue
|
| 549 |
+
dist = env.get_distribution(req.name)
|
| 550 |
+
if not dist:
|
| 551 |
+
missing.add(req_str)
|
| 552 |
+
continue
|
| 553 |
+
if isinstance(dist.version, Version):
|
| 554 |
+
installed_req_str = f"{req.name}=={dist.version}"
|
| 555 |
+
else:
|
| 556 |
+
installed_req_str = f"{req.name}==={dist.version}"
|
| 557 |
+
if not req.specifier.contains(dist.version, prereleases=True):
|
| 558 |
+
conflicting.add((installed_req_str, req_str))
|
| 559 |
+
# FIXME: Consider direct URL?
|
| 560 |
+
return conflicting, missing
|
| 561 |
+
|
| 562 |
+
def install_requirements(
|
| 563 |
+
self,
|
| 564 |
+
requirements: Iterable[str],
|
| 565 |
+
prefix_as_string: str,
|
| 566 |
+
*,
|
| 567 |
+
kind: str,
|
| 568 |
+
for_req: InstallRequirement | None = None,
|
| 569 |
+
) -> None:
|
| 570 |
+
prefix = self._prefixes[prefix_as_string]
|
| 571 |
+
assert not prefix.setup
|
| 572 |
+
prefix.setup = True
|
| 573 |
+
if not requirements:
|
| 574 |
+
return
|
| 575 |
+
self.installer.install(requirements, prefix, kind=kind, for_req=for_req)
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
class NoOpBuildEnvironment(BuildEnvironment):
|
| 579 |
+
"""A no-op drop-in replacement for BuildEnvironment"""
|
| 580 |
+
|
| 581 |
+
def __init__(self) -> None:
|
| 582 |
+
pass
|
| 583 |
+
|
| 584 |
+
def __enter__(self) -> None:
|
| 585 |
+
pass
|
| 586 |
+
|
| 587 |
+
def __exit__(
|
| 588 |
+
self,
|
| 589 |
+
exc_type: type[BaseException] | None,
|
| 590 |
+
exc_val: BaseException | None,
|
| 591 |
+
exc_tb: TracebackType | None,
|
| 592 |
+
) -> None:
|
| 593 |
+
pass
|
| 594 |
+
|
| 595 |
+
def cleanup(self) -> None:
|
| 596 |
+
pass
|
| 597 |
+
|
| 598 |
+
def install_requirements(
|
| 599 |
+
self,
|
| 600 |
+
requirements: Iterable[str],
|
| 601 |
+
prefix_as_string: str,
|
| 602 |
+
*,
|
| 603 |
+
kind: str,
|
| 604 |
+
for_req: InstallRequirement | None = None,
|
| 605 |
+
) -> None:
|
| 606 |
+
raise NotImplementedError()
|
.venv/lib/python3.12/site-packages/pip/_internal/cache.py
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Cache Management"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import hashlib
|
| 6 |
+
import json
|
| 7 |
+
import logging
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
|
| 13 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 14 |
+
|
| 15 |
+
from pip._internal.exceptions import InvalidWheelFilename
|
| 16 |
+
from pip._internal.models.direct_url import DirectUrl
|
| 17 |
+
from pip._internal.models.link import Link
|
| 18 |
+
from pip._internal.models.wheel import Wheel
|
| 19 |
+
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
| 20 |
+
from pip._internal.utils.urls import path_to_url
|
| 21 |
+
|
| 22 |
+
logger = logging.getLogger(__name__)
|
| 23 |
+
|
| 24 |
+
ORIGIN_JSON_NAME = "origin.json"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _hash_dict(d: dict[str, str]) -> str:
|
| 28 |
+
"""Return a stable sha224 of a dictionary."""
|
| 29 |
+
s = json.dumps(d, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
|
| 30 |
+
return hashlib.sha224(s.encode("ascii")).hexdigest()
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class Cache:
|
| 34 |
+
"""An abstract class - provides cache directories for data from links
|
| 35 |
+
|
| 36 |
+
:param cache_dir: The root of the cache.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
def __init__(self, cache_dir: str) -> None:
|
| 40 |
+
super().__init__()
|
| 41 |
+
assert not cache_dir or os.path.isabs(cache_dir)
|
| 42 |
+
self.cache_dir = cache_dir or None
|
| 43 |
+
|
| 44 |
+
def _get_cache_path_parts(self, link: Link) -> list[str]:
|
| 45 |
+
"""Get parts of part that must be os.path.joined with cache_dir"""
|
| 46 |
+
|
| 47 |
+
# We want to generate an url to use as our cache key, we don't want to
|
| 48 |
+
# just reuse the URL because it might have other items in the fragment
|
| 49 |
+
# and we don't care about those.
|
| 50 |
+
key_parts = {"url": link.url_without_fragment}
|
| 51 |
+
if link.hash_name is not None and link.hash is not None:
|
| 52 |
+
key_parts[link.hash_name] = link.hash
|
| 53 |
+
if link.subdirectory_fragment:
|
| 54 |
+
key_parts["subdirectory"] = link.subdirectory_fragment
|
| 55 |
+
|
| 56 |
+
# Include interpreter name, major and minor version in cache key
|
| 57 |
+
# to cope with ill-behaved sdists that build a different wheel
|
| 58 |
+
# depending on the python version their setup.py is being run on,
|
| 59 |
+
# and don't encode the difference in compatibility tags.
|
| 60 |
+
# https://github.com/pypa/pip/issues/7296
|
| 61 |
+
key_parts["interpreter_name"] = interpreter_name()
|
| 62 |
+
key_parts["interpreter_version"] = interpreter_version()
|
| 63 |
+
|
| 64 |
+
# Encode our key url with sha224, we'll use this because it has similar
|
| 65 |
+
# security properties to sha256, but with a shorter total output (and
|
| 66 |
+
# thus less secure). However the differences don't make a lot of
|
| 67 |
+
# difference for our use case here.
|
| 68 |
+
hashed = _hash_dict(key_parts)
|
| 69 |
+
|
| 70 |
+
# We want to nest the directories some to prevent having a ton of top
|
| 71 |
+
# level directories where we might run out of sub directories on some
|
| 72 |
+
# FS.
|
| 73 |
+
parts = [hashed[:2], hashed[2:4], hashed[4:6], hashed[6:]]
|
| 74 |
+
|
| 75 |
+
return parts
|
| 76 |
+
|
| 77 |
+
def _get_candidates(self, link: Link, canonical_package_name: str) -> list[Any]:
|
| 78 |
+
can_not_cache = not self.cache_dir or not canonical_package_name or not link
|
| 79 |
+
if can_not_cache:
|
| 80 |
+
return []
|
| 81 |
+
|
| 82 |
+
path = self.get_path_for_link(link)
|
| 83 |
+
if os.path.isdir(path):
|
| 84 |
+
return [(candidate, path) for candidate in os.listdir(path)]
|
| 85 |
+
return []
|
| 86 |
+
|
| 87 |
+
def get_path_for_link(self, link: Link) -> str:
|
| 88 |
+
"""Return a directory to store cached items in for link."""
|
| 89 |
+
raise NotImplementedError()
|
| 90 |
+
|
| 91 |
+
def get(
|
| 92 |
+
self,
|
| 93 |
+
link: Link,
|
| 94 |
+
package_name: str | None,
|
| 95 |
+
supported_tags: list[Tag],
|
| 96 |
+
) -> Link:
|
| 97 |
+
"""Returns a link to a cached item if it exists, otherwise returns the
|
| 98 |
+
passed link.
|
| 99 |
+
"""
|
| 100 |
+
raise NotImplementedError()
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
class SimpleWheelCache(Cache):
|
| 104 |
+
"""A cache of wheels for future installs."""
|
| 105 |
+
|
| 106 |
+
def __init__(self, cache_dir: str) -> None:
|
| 107 |
+
super().__init__(cache_dir)
|
| 108 |
+
|
| 109 |
+
def get_path_for_link(self, link: Link) -> str:
|
| 110 |
+
"""Return a directory to store cached wheels for link
|
| 111 |
+
|
| 112 |
+
Because there are M wheels for any one sdist, we provide a directory
|
| 113 |
+
to cache them in, and then consult that directory when looking up
|
| 114 |
+
cache hits.
|
| 115 |
+
|
| 116 |
+
We only insert things into the cache if they have plausible version
|
| 117 |
+
numbers, so that we don't contaminate the cache with things that were
|
| 118 |
+
not unique. E.g. ./package might have dozens of installs done for it
|
| 119 |
+
and build a version of 0.0...and if we built and cached a wheel, we'd
|
| 120 |
+
end up using the same wheel even if the source has been edited.
|
| 121 |
+
|
| 122 |
+
:param link: The link of the sdist for which this will cache wheels.
|
| 123 |
+
"""
|
| 124 |
+
parts = self._get_cache_path_parts(link)
|
| 125 |
+
assert self.cache_dir
|
| 126 |
+
# Store wheels within the root cache_dir
|
| 127 |
+
return os.path.join(self.cache_dir, "wheels", *parts)
|
| 128 |
+
|
| 129 |
+
def get(
|
| 130 |
+
self,
|
| 131 |
+
link: Link,
|
| 132 |
+
package_name: str | None,
|
| 133 |
+
supported_tags: list[Tag],
|
| 134 |
+
) -> Link:
|
| 135 |
+
candidates = []
|
| 136 |
+
|
| 137 |
+
if not package_name:
|
| 138 |
+
return link
|
| 139 |
+
|
| 140 |
+
canonical_package_name = canonicalize_name(package_name)
|
| 141 |
+
for wheel_name, wheel_dir in self._get_candidates(link, canonical_package_name):
|
| 142 |
+
try:
|
| 143 |
+
wheel = Wheel(wheel_name)
|
| 144 |
+
except InvalidWheelFilename:
|
| 145 |
+
continue
|
| 146 |
+
if wheel.name != canonical_package_name:
|
| 147 |
+
logger.debug(
|
| 148 |
+
"Ignoring cached wheel %s for %s as it "
|
| 149 |
+
"does not match the expected distribution name %s.",
|
| 150 |
+
wheel_name,
|
| 151 |
+
link,
|
| 152 |
+
package_name,
|
| 153 |
+
)
|
| 154 |
+
continue
|
| 155 |
+
if not wheel.supported(supported_tags):
|
| 156 |
+
# Built for a different python/arch/etc
|
| 157 |
+
continue
|
| 158 |
+
candidates.append(
|
| 159 |
+
(
|
| 160 |
+
wheel.support_index_min(supported_tags),
|
| 161 |
+
wheel_name,
|
| 162 |
+
wheel_dir,
|
| 163 |
+
)
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
if not candidates:
|
| 167 |
+
return link
|
| 168 |
+
|
| 169 |
+
_, wheel_name, wheel_dir = min(candidates)
|
| 170 |
+
return Link(path_to_url(os.path.join(wheel_dir, wheel_name)))
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
class EphemWheelCache(SimpleWheelCache):
|
| 174 |
+
"""A SimpleWheelCache that creates it's own temporary cache directory"""
|
| 175 |
+
|
| 176 |
+
def __init__(self) -> None:
|
| 177 |
+
self._temp_dir = TempDirectory(
|
| 178 |
+
kind=tempdir_kinds.EPHEM_WHEEL_CACHE,
|
| 179 |
+
globally_managed=True,
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
super().__init__(self._temp_dir.path)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
class CacheEntry:
|
| 186 |
+
def __init__(
|
| 187 |
+
self,
|
| 188 |
+
link: Link,
|
| 189 |
+
persistent: bool,
|
| 190 |
+
):
|
| 191 |
+
self.link = link
|
| 192 |
+
self.persistent = persistent
|
| 193 |
+
self.origin: DirectUrl | None = None
|
| 194 |
+
origin_direct_url_path = Path(self.link.file_path).parent / ORIGIN_JSON_NAME
|
| 195 |
+
if origin_direct_url_path.exists():
|
| 196 |
+
try:
|
| 197 |
+
self.origin = DirectUrl.from_json(
|
| 198 |
+
origin_direct_url_path.read_text(encoding="utf-8")
|
| 199 |
+
)
|
| 200 |
+
except Exception as e:
|
| 201 |
+
logger.warning(
|
| 202 |
+
"Ignoring invalid cache entry origin file %s for %s (%s)",
|
| 203 |
+
origin_direct_url_path,
|
| 204 |
+
link.filename,
|
| 205 |
+
e,
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
class WheelCache(Cache):
|
| 210 |
+
"""Wraps EphemWheelCache and SimpleWheelCache into a single Cache
|
| 211 |
+
|
| 212 |
+
This Cache allows for gracefully degradation, using the ephem wheel cache
|
| 213 |
+
when a certain link is not found in the simple wheel cache first.
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
def __init__(self, cache_dir: str) -> None:
|
| 217 |
+
super().__init__(cache_dir)
|
| 218 |
+
self._wheel_cache = SimpleWheelCache(cache_dir)
|
| 219 |
+
self._ephem_cache = EphemWheelCache()
|
| 220 |
+
|
| 221 |
+
def get_path_for_link(self, link: Link) -> str:
|
| 222 |
+
return self._wheel_cache.get_path_for_link(link)
|
| 223 |
+
|
| 224 |
+
def get_ephem_path_for_link(self, link: Link) -> str:
|
| 225 |
+
return self._ephem_cache.get_path_for_link(link)
|
| 226 |
+
|
| 227 |
+
def get(
|
| 228 |
+
self,
|
| 229 |
+
link: Link,
|
| 230 |
+
package_name: str | None,
|
| 231 |
+
supported_tags: list[Tag],
|
| 232 |
+
) -> Link:
|
| 233 |
+
cache_entry = self.get_cache_entry(link, package_name, supported_tags)
|
| 234 |
+
if cache_entry is None:
|
| 235 |
+
return link
|
| 236 |
+
return cache_entry.link
|
| 237 |
+
|
| 238 |
+
def get_cache_entry(
|
| 239 |
+
self,
|
| 240 |
+
link: Link,
|
| 241 |
+
package_name: str | None,
|
| 242 |
+
supported_tags: list[Tag],
|
| 243 |
+
) -> CacheEntry | None:
|
| 244 |
+
"""Returns a CacheEntry with a link to a cached item if it exists or
|
| 245 |
+
None. The cache entry indicates if the item was found in the persistent
|
| 246 |
+
or ephemeral cache.
|
| 247 |
+
"""
|
| 248 |
+
retval = self._wheel_cache.get(
|
| 249 |
+
link=link,
|
| 250 |
+
package_name=package_name,
|
| 251 |
+
supported_tags=supported_tags,
|
| 252 |
+
)
|
| 253 |
+
if retval is not link:
|
| 254 |
+
return CacheEntry(retval, persistent=True)
|
| 255 |
+
|
| 256 |
+
retval = self._ephem_cache.get(
|
| 257 |
+
link=link,
|
| 258 |
+
package_name=package_name,
|
| 259 |
+
supported_tags=supported_tags,
|
| 260 |
+
)
|
| 261 |
+
if retval is not link:
|
| 262 |
+
return CacheEntry(retval, persistent=False)
|
| 263 |
+
|
| 264 |
+
return None
|
| 265 |
+
|
| 266 |
+
@staticmethod
|
| 267 |
+
def record_download_origin(cache_dir: str, download_info: DirectUrl) -> None:
|
| 268 |
+
origin_path = Path(cache_dir) / ORIGIN_JSON_NAME
|
| 269 |
+
if origin_path.exists():
|
| 270 |
+
try:
|
| 271 |
+
origin = DirectUrl.from_json(origin_path.read_text(encoding="utf-8"))
|
| 272 |
+
except Exception as e:
|
| 273 |
+
logger.warning(
|
| 274 |
+
"Could not read origin file %s in cache entry (%s). "
|
| 275 |
+
"Will attempt to overwrite it.",
|
| 276 |
+
origin_path,
|
| 277 |
+
e,
|
| 278 |
+
)
|
| 279 |
+
else:
|
| 280 |
+
# TODO: use DirectUrl.equivalent when
|
| 281 |
+
# https://github.com/pypa/pip/pull/10564 is merged.
|
| 282 |
+
if origin.url != download_info.url:
|
| 283 |
+
logger.warning(
|
| 284 |
+
"Origin URL %s in cache entry %s does not match download URL "
|
| 285 |
+
"%s. This is likely a pip bug or a cache corruption issue. "
|
| 286 |
+
"Will overwrite it with the new value.",
|
| 287 |
+
origin.url,
|
| 288 |
+
cache_dir,
|
| 289 |
+
download_info.url,
|
| 290 |
+
)
|
| 291 |
+
origin_path.write_text(download_info.to_json(), encoding="utf-8")
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/__init__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Subpackage containing all of pip's command line interface related code"""
|
| 2 |
+
|
| 3 |
+
# This file intentionally does not import submodules
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/autocompletion.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Logic that powers autocompletion installed by ``pip completion``."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import optparse
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
from collections.abc import Iterable
|
| 9 |
+
from itertools import chain
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
from pip._internal.cli.main_parser import create_main_parser
|
| 13 |
+
from pip._internal.commands import commands_dict, create_command
|
| 14 |
+
from pip._internal.metadata import get_default_environment
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def autocomplete() -> None:
|
| 18 |
+
"""Entry Point for completion of main and subcommand options."""
|
| 19 |
+
# Don't complete if user hasn't sourced bash_completion file.
|
| 20 |
+
if "PIP_AUTO_COMPLETE" not in os.environ:
|
| 21 |
+
return
|
| 22 |
+
# Don't complete if autocompletion environment variables
|
| 23 |
+
# are not present
|
| 24 |
+
if not os.environ.get("COMP_WORDS") or not os.environ.get("COMP_CWORD"):
|
| 25 |
+
return
|
| 26 |
+
cwords = os.environ["COMP_WORDS"].split()[1:]
|
| 27 |
+
cword = int(os.environ["COMP_CWORD"])
|
| 28 |
+
try:
|
| 29 |
+
current = cwords[cword - 1]
|
| 30 |
+
except IndexError:
|
| 31 |
+
current = ""
|
| 32 |
+
|
| 33 |
+
parser = create_main_parser()
|
| 34 |
+
subcommands = list(commands_dict)
|
| 35 |
+
options = []
|
| 36 |
+
|
| 37 |
+
# subcommand
|
| 38 |
+
subcommand_name: str | None = None
|
| 39 |
+
for word in cwords:
|
| 40 |
+
if word in subcommands:
|
| 41 |
+
subcommand_name = word
|
| 42 |
+
break
|
| 43 |
+
# subcommand options
|
| 44 |
+
if subcommand_name is not None:
|
| 45 |
+
# special case: 'help' subcommand has no options
|
| 46 |
+
if subcommand_name == "help":
|
| 47 |
+
sys.exit(1)
|
| 48 |
+
# special case: list locally installed dists for show and uninstall
|
| 49 |
+
should_list_installed = not current.startswith("-") and subcommand_name in [
|
| 50 |
+
"show",
|
| 51 |
+
"uninstall",
|
| 52 |
+
]
|
| 53 |
+
if should_list_installed:
|
| 54 |
+
env = get_default_environment()
|
| 55 |
+
lc = current.lower()
|
| 56 |
+
installed = [
|
| 57 |
+
dist.canonical_name
|
| 58 |
+
for dist in env.iter_installed_distributions(local_only=True)
|
| 59 |
+
if dist.canonical_name.startswith(lc)
|
| 60 |
+
and dist.canonical_name not in cwords[1:]
|
| 61 |
+
]
|
| 62 |
+
# if there are no dists installed, fall back to option completion
|
| 63 |
+
if installed:
|
| 64 |
+
for dist in installed:
|
| 65 |
+
print(dist)
|
| 66 |
+
sys.exit(1)
|
| 67 |
+
|
| 68 |
+
should_list_installables = (
|
| 69 |
+
not current.startswith("-") and subcommand_name == "install"
|
| 70 |
+
)
|
| 71 |
+
if should_list_installables:
|
| 72 |
+
for path in auto_complete_paths(current, "path"):
|
| 73 |
+
print(path)
|
| 74 |
+
sys.exit(1)
|
| 75 |
+
|
| 76 |
+
subcommand = create_command(subcommand_name)
|
| 77 |
+
|
| 78 |
+
for opt in subcommand.parser.option_list_all:
|
| 79 |
+
if opt.help != optparse.SUPPRESS_HELP:
|
| 80 |
+
options += [
|
| 81 |
+
(opt_str, opt.nargs) for opt_str in opt._long_opts + opt._short_opts
|
| 82 |
+
]
|
| 83 |
+
|
| 84 |
+
# filter out previously specified options from available options
|
| 85 |
+
prev_opts = [x.split("=")[0] for x in cwords[1 : cword - 1]]
|
| 86 |
+
options = [(x, v) for (x, v) in options if x not in prev_opts]
|
| 87 |
+
# filter options by current input
|
| 88 |
+
options = [(k, v) for k, v in options if k.startswith(current)]
|
| 89 |
+
# get completion type given cwords and available subcommand options
|
| 90 |
+
completion_type = get_path_completion_type(
|
| 91 |
+
cwords,
|
| 92 |
+
cword,
|
| 93 |
+
subcommand.parser.option_list_all,
|
| 94 |
+
)
|
| 95 |
+
# get completion files and directories if ``completion_type`` is
|
| 96 |
+
# ``<file>``, ``<dir>`` or ``<path>``
|
| 97 |
+
if completion_type:
|
| 98 |
+
paths = auto_complete_paths(current, completion_type)
|
| 99 |
+
options = [(path, 0) for path in paths]
|
| 100 |
+
for option in options:
|
| 101 |
+
opt_label = option[0]
|
| 102 |
+
# append '=' to options which require args
|
| 103 |
+
if option[1] and option[0][:2] == "--":
|
| 104 |
+
opt_label += "="
|
| 105 |
+
print(opt_label)
|
| 106 |
+
|
| 107 |
+
# Complete sub-commands (unless one is already given).
|
| 108 |
+
if not any(name in cwords for name in subcommand.handler_map()):
|
| 109 |
+
for handler_name in subcommand.handler_map():
|
| 110 |
+
if handler_name.startswith(current):
|
| 111 |
+
print(handler_name)
|
| 112 |
+
else:
|
| 113 |
+
# show main parser options only when necessary
|
| 114 |
+
|
| 115 |
+
opts = [i.option_list for i in parser.option_groups]
|
| 116 |
+
opts.append(parser.option_list)
|
| 117 |
+
flattened_opts = chain.from_iterable(opts)
|
| 118 |
+
if current.startswith("-"):
|
| 119 |
+
for opt in flattened_opts:
|
| 120 |
+
if opt.help != optparse.SUPPRESS_HELP:
|
| 121 |
+
subcommands += opt._long_opts + opt._short_opts
|
| 122 |
+
else:
|
| 123 |
+
# get completion type given cwords and all available options
|
| 124 |
+
completion_type = get_path_completion_type(cwords, cword, flattened_opts)
|
| 125 |
+
if completion_type:
|
| 126 |
+
subcommands = list(auto_complete_paths(current, completion_type))
|
| 127 |
+
|
| 128 |
+
print(" ".join([x for x in subcommands if x.startswith(current)]))
|
| 129 |
+
sys.exit(1)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def get_path_completion_type(
|
| 133 |
+
cwords: list[str], cword: int, opts: Iterable[Any]
|
| 134 |
+
) -> str | None:
|
| 135 |
+
"""Get the type of path completion (``file``, ``dir``, ``path`` or None)
|
| 136 |
+
|
| 137 |
+
:param cwords: same as the environmental variable ``COMP_WORDS``
|
| 138 |
+
:param cword: same as the environmental variable ``COMP_CWORD``
|
| 139 |
+
:param opts: The available options to check
|
| 140 |
+
:return: path completion type (``file``, ``dir``, ``path`` or None)
|
| 141 |
+
"""
|
| 142 |
+
if cword < 2 or not cwords[cword - 2].startswith("-"):
|
| 143 |
+
return None
|
| 144 |
+
for opt in opts:
|
| 145 |
+
if opt.help == optparse.SUPPRESS_HELP:
|
| 146 |
+
continue
|
| 147 |
+
for o in str(opt).split("/"):
|
| 148 |
+
if cwords[cword - 2].split("=")[0] == o:
|
| 149 |
+
if not opt.metavar or any(
|
| 150 |
+
x in ("path", "file", "dir") for x in opt.metavar.split("/")
|
| 151 |
+
):
|
| 152 |
+
return opt.metavar
|
| 153 |
+
return None
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def auto_complete_paths(current: str, completion_type: str) -> Iterable[str]:
|
| 157 |
+
"""If ``completion_type`` is ``file`` or ``path``, list all regular files
|
| 158 |
+
and directories starting with ``current``; otherwise only list directories
|
| 159 |
+
starting with ``current``.
|
| 160 |
+
|
| 161 |
+
:param current: The word to be completed
|
| 162 |
+
:param completion_type: path completion type(``file``, ``path`` or ``dir``)
|
| 163 |
+
:return: A generator of regular files and/or directories
|
| 164 |
+
"""
|
| 165 |
+
directory, filename = os.path.split(current)
|
| 166 |
+
current_path = os.path.abspath(directory)
|
| 167 |
+
# Don't complete paths if they can't be accessed
|
| 168 |
+
if not os.access(current_path, os.R_OK):
|
| 169 |
+
return
|
| 170 |
+
filename = os.path.normcase(filename)
|
| 171 |
+
# list all files that start with ``filename``
|
| 172 |
+
file_list = (
|
| 173 |
+
x for x in os.listdir(current_path) if os.path.normcase(x).startswith(filename)
|
| 174 |
+
)
|
| 175 |
+
for f in file_list:
|
| 176 |
+
opt = os.path.join(current_path, f)
|
| 177 |
+
comp_file = os.path.normcase(os.path.join(directory, f))
|
| 178 |
+
# complete regular files when there is not ``<dir>`` after option
|
| 179 |
+
# complete directories when there is ``<file>``, ``<path>`` or
|
| 180 |
+
# ``<dir>``after option
|
| 181 |
+
if completion_type != "dir" and os.path.isfile(opt):
|
| 182 |
+
yield comp_file
|
| 183 |
+
elif os.path.isdir(opt):
|
| 184 |
+
yield os.path.join(comp_file, "")
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/base_command.py
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Base Command class, and related routines"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import logging.config
|
| 7 |
+
import optparse
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
import traceback
|
| 11 |
+
from optparse import Values
|
| 12 |
+
from typing import Callable
|
| 13 |
+
|
| 14 |
+
from pip._vendor.rich import reconfigure
|
| 15 |
+
from pip._vendor.rich import traceback as rich_traceback
|
| 16 |
+
|
| 17 |
+
from pip._internal.cli import cmdoptions
|
| 18 |
+
from pip._internal.cli.command_context import CommandContextMixIn
|
| 19 |
+
from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
|
| 20 |
+
from pip._internal.cli.status_codes import (
|
| 21 |
+
ERROR,
|
| 22 |
+
PREVIOUS_BUILD_DIR_ERROR,
|
| 23 |
+
UNKNOWN_ERROR,
|
| 24 |
+
VIRTUALENV_NOT_FOUND,
|
| 25 |
+
)
|
| 26 |
+
from pip._internal.exceptions import (
|
| 27 |
+
BadCommand,
|
| 28 |
+
CommandError,
|
| 29 |
+
DiagnosticPipError,
|
| 30 |
+
InstallationError,
|
| 31 |
+
NetworkConnectionError,
|
| 32 |
+
PreviousBuildDirError,
|
| 33 |
+
)
|
| 34 |
+
from pip._internal.utils.filesystem import check_path_owner
|
| 35 |
+
from pip._internal.utils.logging import BrokenStdoutLoggingError, setup_logging
|
| 36 |
+
from pip._internal.utils.misc import get_prog, normalize_path
|
| 37 |
+
from pip._internal.utils.temp_dir import TempDirectoryTypeRegistry as TempDirRegistry
|
| 38 |
+
from pip._internal.utils.temp_dir import global_tempdir_manager, tempdir_registry
|
| 39 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
| 40 |
+
|
| 41 |
+
__all__ = ["Command"]
|
| 42 |
+
|
| 43 |
+
logger = logging.getLogger(__name__)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Command(CommandContextMixIn):
|
| 47 |
+
usage: str = ""
|
| 48 |
+
ignore_require_venv: bool = False
|
| 49 |
+
|
| 50 |
+
def __init__(self, name: str, summary: str, isolated: bool = False) -> None:
|
| 51 |
+
super().__init__()
|
| 52 |
+
|
| 53 |
+
self.name = name
|
| 54 |
+
self.summary = summary
|
| 55 |
+
self.parser = ConfigOptionParser(
|
| 56 |
+
usage=self.usage,
|
| 57 |
+
prog=f"{get_prog()} {name}",
|
| 58 |
+
formatter=UpdatingDefaultsHelpFormatter(),
|
| 59 |
+
add_help_option=False,
|
| 60 |
+
name=name,
|
| 61 |
+
description=self.__doc__,
|
| 62 |
+
isolated=isolated,
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
self.tempdir_registry: TempDirRegistry | None = None
|
| 66 |
+
|
| 67 |
+
# Commands should add options to this option group
|
| 68 |
+
optgroup_name = f"{self.name.capitalize()} Options"
|
| 69 |
+
self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name)
|
| 70 |
+
|
| 71 |
+
# Add the general options
|
| 72 |
+
gen_opts = cmdoptions.make_option_group(
|
| 73 |
+
cmdoptions.general_group,
|
| 74 |
+
self.parser,
|
| 75 |
+
)
|
| 76 |
+
self.parser.add_option_group(gen_opts)
|
| 77 |
+
|
| 78 |
+
self.add_options()
|
| 79 |
+
|
| 80 |
+
def add_options(self) -> None:
|
| 81 |
+
pass
|
| 82 |
+
|
| 83 |
+
def handle_pip_version_check(self, options: Values) -> None:
|
| 84 |
+
"""
|
| 85 |
+
This is a no-op so that commands by default do not do the pip version
|
| 86 |
+
check.
|
| 87 |
+
"""
|
| 88 |
+
# Make sure we do the pip version check if the index_group options
|
| 89 |
+
# are present.
|
| 90 |
+
assert not hasattr(options, "no_index")
|
| 91 |
+
|
| 92 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 93 |
+
raise NotImplementedError
|
| 94 |
+
|
| 95 |
+
def _run_wrapper(self, level_number: int, options: Values, args: list[str]) -> int:
|
| 96 |
+
def _inner_run() -> int:
|
| 97 |
+
try:
|
| 98 |
+
return self.run(options, args)
|
| 99 |
+
finally:
|
| 100 |
+
self.handle_pip_version_check(options)
|
| 101 |
+
|
| 102 |
+
if options.debug_mode:
|
| 103 |
+
rich_traceback.install(show_locals=True)
|
| 104 |
+
return _inner_run()
|
| 105 |
+
|
| 106 |
+
try:
|
| 107 |
+
status = _inner_run()
|
| 108 |
+
assert isinstance(status, int)
|
| 109 |
+
return status
|
| 110 |
+
except DiagnosticPipError as exc:
|
| 111 |
+
logger.error("%s", exc, extra={"rich": True})
|
| 112 |
+
logger.debug("Exception information:", exc_info=True)
|
| 113 |
+
|
| 114 |
+
return ERROR
|
| 115 |
+
except PreviousBuildDirError as exc:
|
| 116 |
+
logger.critical(str(exc))
|
| 117 |
+
logger.debug("Exception information:", exc_info=True)
|
| 118 |
+
|
| 119 |
+
return PREVIOUS_BUILD_DIR_ERROR
|
| 120 |
+
except (
|
| 121 |
+
InstallationError,
|
| 122 |
+
BadCommand,
|
| 123 |
+
NetworkConnectionError,
|
| 124 |
+
) as exc:
|
| 125 |
+
logger.critical(str(exc))
|
| 126 |
+
logger.debug("Exception information:", exc_info=True)
|
| 127 |
+
|
| 128 |
+
return ERROR
|
| 129 |
+
except CommandError as exc:
|
| 130 |
+
logger.critical("%s", exc)
|
| 131 |
+
logger.debug("Exception information:", exc_info=True)
|
| 132 |
+
|
| 133 |
+
return ERROR
|
| 134 |
+
except BrokenStdoutLoggingError:
|
| 135 |
+
# Bypass our logger and write any remaining messages to
|
| 136 |
+
# stderr because stdout no longer works.
|
| 137 |
+
print("ERROR: Pipe to stdout was broken", file=sys.stderr)
|
| 138 |
+
if level_number <= logging.DEBUG:
|
| 139 |
+
traceback.print_exc(file=sys.stderr)
|
| 140 |
+
|
| 141 |
+
return ERROR
|
| 142 |
+
except KeyboardInterrupt:
|
| 143 |
+
logger.critical("Operation cancelled by user")
|
| 144 |
+
logger.debug("Exception information:", exc_info=True)
|
| 145 |
+
|
| 146 |
+
return ERROR
|
| 147 |
+
except BaseException:
|
| 148 |
+
logger.critical("Exception:", exc_info=True)
|
| 149 |
+
|
| 150 |
+
return UNKNOWN_ERROR
|
| 151 |
+
|
| 152 |
+
def parse_args(self, args: list[str]) -> tuple[Values, list[str]]:
|
| 153 |
+
# factored out for testability
|
| 154 |
+
return self.parser.parse_args(args)
|
| 155 |
+
|
| 156 |
+
def main(self, args: list[str]) -> int:
|
| 157 |
+
try:
|
| 158 |
+
with self.main_context():
|
| 159 |
+
return self._main(args)
|
| 160 |
+
finally:
|
| 161 |
+
logging.shutdown()
|
| 162 |
+
|
| 163 |
+
def _main(self, args: list[str]) -> int:
|
| 164 |
+
# We must initialize this before the tempdir manager, otherwise the
|
| 165 |
+
# configuration would not be accessible by the time we clean up the
|
| 166 |
+
# tempdir manager.
|
| 167 |
+
self.tempdir_registry = self.enter_context(tempdir_registry())
|
| 168 |
+
# Intentionally set as early as possible so globally-managed temporary
|
| 169 |
+
# directories are available to the rest of the code.
|
| 170 |
+
self.enter_context(global_tempdir_manager())
|
| 171 |
+
|
| 172 |
+
options, args = self.parse_args(args)
|
| 173 |
+
|
| 174 |
+
# Set verbosity so that it can be used elsewhere.
|
| 175 |
+
self.verbosity = options.verbose - options.quiet
|
| 176 |
+
if options.debug_mode:
|
| 177 |
+
self.verbosity = 2
|
| 178 |
+
|
| 179 |
+
if hasattr(options, "progress_bar") and options.progress_bar == "auto":
|
| 180 |
+
options.progress_bar = "on" if self.verbosity >= 0 else "off"
|
| 181 |
+
|
| 182 |
+
reconfigure(no_color=options.no_color)
|
| 183 |
+
level_number = setup_logging(
|
| 184 |
+
verbosity=self.verbosity,
|
| 185 |
+
no_color=options.no_color,
|
| 186 |
+
user_log_file=options.log,
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
always_enabled_features = set(options.features_enabled) & set(
|
| 190 |
+
cmdoptions.ALWAYS_ENABLED_FEATURES
|
| 191 |
+
)
|
| 192 |
+
if always_enabled_features:
|
| 193 |
+
logger.warning(
|
| 194 |
+
"The following features are always enabled: %s. ",
|
| 195 |
+
", ".join(sorted(always_enabled_features)),
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
# Make sure that the --python argument isn't specified after the
|
| 199 |
+
# subcommand. We can tell, because if --python was specified,
|
| 200 |
+
# we should only reach this point if we're running in the created
|
| 201 |
+
# subprocess, which has the _PIP_RUNNING_IN_SUBPROCESS environment
|
| 202 |
+
# variable set.
|
| 203 |
+
if options.python and "_PIP_RUNNING_IN_SUBPROCESS" not in os.environ:
|
| 204 |
+
logger.critical(
|
| 205 |
+
"The --python option must be placed before the pip subcommand name"
|
| 206 |
+
)
|
| 207 |
+
sys.exit(ERROR)
|
| 208 |
+
|
| 209 |
+
# TODO: Try to get these passing down from the command?
|
| 210 |
+
# without resorting to os.environ to hold these.
|
| 211 |
+
# This also affects isolated builds and it should.
|
| 212 |
+
|
| 213 |
+
if options.no_input:
|
| 214 |
+
os.environ["PIP_NO_INPUT"] = "1"
|
| 215 |
+
|
| 216 |
+
if options.exists_action:
|
| 217 |
+
os.environ["PIP_EXISTS_ACTION"] = " ".join(options.exists_action)
|
| 218 |
+
|
| 219 |
+
if options.require_venv and not self.ignore_require_venv:
|
| 220 |
+
# If a venv is required check if it can really be found
|
| 221 |
+
if not running_under_virtualenv():
|
| 222 |
+
logger.critical("Could not find an activated virtualenv (required).")
|
| 223 |
+
sys.exit(VIRTUALENV_NOT_FOUND)
|
| 224 |
+
|
| 225 |
+
if options.cache_dir:
|
| 226 |
+
options.cache_dir = normalize_path(options.cache_dir)
|
| 227 |
+
if not check_path_owner(options.cache_dir):
|
| 228 |
+
logger.warning(
|
| 229 |
+
"The directory '%s' or its parent directory is not owned "
|
| 230 |
+
"or is not writable by the current user. The cache "
|
| 231 |
+
"has been disabled. Check the permissions and owner of "
|
| 232 |
+
"that directory. If executing pip with sudo, you should "
|
| 233 |
+
"use sudo's -H flag.",
|
| 234 |
+
options.cache_dir,
|
| 235 |
+
)
|
| 236 |
+
options.cache_dir = None
|
| 237 |
+
|
| 238 |
+
if (
|
| 239 |
+
"inprocess-build-deps" in options.features_enabled
|
| 240 |
+
and os.environ.get("PIP_CONSTRAINT", "")
|
| 241 |
+
and "build-constraint" not in options.features_enabled
|
| 242 |
+
):
|
| 243 |
+
logger.warning(
|
| 244 |
+
"In-process build dependencies are enabled, "
|
| 245 |
+
"PIP_CONSTRAINT will have no effect for build dependencies"
|
| 246 |
+
)
|
| 247 |
+
options.features_enabled.append("build-constraint")
|
| 248 |
+
|
| 249 |
+
return self._run_wrapper(level_number, options, args)
|
| 250 |
+
|
| 251 |
+
def handler_map(self) -> dict[str, Callable[[Values, list[str]], None]]:
|
| 252 |
+
"""
|
| 253 |
+
map of names to handler actions for commands with sub-actions
|
| 254 |
+
"""
|
| 255 |
+
return {}
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/cmdoptions.py
ADDED
|
@@ -0,0 +1,1267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
shared options and groups
|
| 3 |
+
|
| 4 |
+
The principle here is to define options once, but *not* instantiate them
|
| 5 |
+
globally. One reason being that options with action='append' can carry state
|
| 6 |
+
between parses. pip parses general options twice internally, and shouldn't
|
| 7 |
+
pass on state. To be consistent, all options will follow this design.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
# The following comment should be removed at some point in the future.
|
| 11 |
+
# mypy: strict-optional=False
|
| 12 |
+
from __future__ import annotations
|
| 13 |
+
|
| 14 |
+
import logging
|
| 15 |
+
import os
|
| 16 |
+
import pathlib
|
| 17 |
+
import textwrap
|
| 18 |
+
from functools import partial
|
| 19 |
+
from optparse import SUPPRESS_HELP, Option, OptionGroup, OptionParser, Values
|
| 20 |
+
from textwrap import dedent
|
| 21 |
+
from typing import Any, Callable
|
| 22 |
+
|
| 23 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 24 |
+
|
| 25 |
+
from pip._internal.cli.parser import ConfigOptionParser
|
| 26 |
+
from pip._internal.exceptions import CommandError
|
| 27 |
+
from pip._internal.locations import USER_CACHE_DIR, get_src_prefix
|
| 28 |
+
from pip._internal.models.format_control import FormatControl
|
| 29 |
+
from pip._internal.models.index import PyPI
|
| 30 |
+
from pip._internal.models.release_control import ReleaseControl
|
| 31 |
+
from pip._internal.models.target_python import TargetPython
|
| 32 |
+
from pip._internal.utils.datetime import parse_iso_datetime
|
| 33 |
+
from pip._internal.utils.hashes import STRONG_HASHES
|
| 34 |
+
from pip._internal.utils.misc import strtobool
|
| 35 |
+
|
| 36 |
+
logger = logging.getLogger(__name__)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def raise_option_error(parser: OptionParser, option: Option, msg: str) -> None:
|
| 40 |
+
"""
|
| 41 |
+
Raise an option parsing error using parser.error().
|
| 42 |
+
|
| 43 |
+
Args:
|
| 44 |
+
parser: an OptionParser instance.
|
| 45 |
+
option: an Option instance.
|
| 46 |
+
msg: the error text.
|
| 47 |
+
"""
|
| 48 |
+
msg = f"{option} error: {msg}"
|
| 49 |
+
msg = textwrap.fill(" ".join(msg.split()))
|
| 50 |
+
parser.error(msg)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def make_option_group(group: dict[str, Any], parser: ConfigOptionParser) -> OptionGroup:
|
| 54 |
+
"""
|
| 55 |
+
Return an OptionGroup object
|
| 56 |
+
group -- assumed to be dict with 'name' and 'options' keys
|
| 57 |
+
parser -- an optparse Parser
|
| 58 |
+
"""
|
| 59 |
+
option_group = OptionGroup(parser, group["name"])
|
| 60 |
+
for option in group["options"]:
|
| 61 |
+
option_group.add_option(option())
|
| 62 |
+
return option_group
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def check_dist_restriction(options: Values, check_target: bool = False) -> None:
|
| 66 |
+
"""Function for determining if custom platform options are allowed.
|
| 67 |
+
|
| 68 |
+
:param options: The OptionParser options.
|
| 69 |
+
:param check_target: Whether or not to check if --target is being used.
|
| 70 |
+
"""
|
| 71 |
+
dist_restriction_set = any(
|
| 72 |
+
[
|
| 73 |
+
options.python_version,
|
| 74 |
+
options.platforms,
|
| 75 |
+
options.abis,
|
| 76 |
+
options.implementation,
|
| 77 |
+
]
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
binary_only = FormatControl(set(), {":all:"})
|
| 81 |
+
sdist_dependencies_allowed = (
|
| 82 |
+
options.format_control != binary_only and not options.ignore_dependencies
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
# Installations or downloads using dist restrictions must not combine
|
| 86 |
+
# source distributions and dist-specific wheels, as they are not
|
| 87 |
+
# guaranteed to be locally compatible.
|
| 88 |
+
if dist_restriction_set and sdist_dependencies_allowed:
|
| 89 |
+
raise CommandError(
|
| 90 |
+
"When restricting platform and interpreter constraints using "
|
| 91 |
+
"--python-version, --platform, --abi, or --implementation, "
|
| 92 |
+
"either --no-deps must be set, or --only-binary=:all: must be "
|
| 93 |
+
"set and --no-binary must not be set (or must be set to "
|
| 94 |
+
":none:)."
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
if check_target:
|
| 98 |
+
if not options.dry_run and dist_restriction_set and not options.target_dir:
|
| 99 |
+
raise CommandError(
|
| 100 |
+
"Can not use any platform or abi specific options unless "
|
| 101 |
+
"installing via '--target' or using '--dry-run'"
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def check_build_constraints(options: Values) -> None:
|
| 106 |
+
"""Function for validating build constraints options.
|
| 107 |
+
|
| 108 |
+
:param options: The OptionParser options.
|
| 109 |
+
"""
|
| 110 |
+
if hasattr(options, "build_constraints") and options.build_constraints:
|
| 111 |
+
if not options.build_isolation:
|
| 112 |
+
raise CommandError(
|
| 113 |
+
"--build-constraint cannot be used with --no-build-isolation."
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
# Import here to avoid circular imports
|
| 117 |
+
from pip._internal.network.session import PipSession
|
| 118 |
+
from pip._internal.req.req_file import get_file_content
|
| 119 |
+
|
| 120 |
+
# Eagerly check build constraints file contents
|
| 121 |
+
# is valid so that we don't fail in when trying
|
| 122 |
+
# to check constraints in isolated build process
|
| 123 |
+
with PipSession() as session:
|
| 124 |
+
for constraint_file in options.build_constraints:
|
| 125 |
+
get_file_content(constraint_file, session)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def _path_option_check(option: Option, opt: str, value: str) -> str:
|
| 129 |
+
return os.path.expanduser(value)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def _package_name_option_check(option: Option, opt: str, value: str) -> str:
|
| 133 |
+
return canonicalize_name(value)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
class PipOption(Option):
|
| 137 |
+
TYPES = Option.TYPES + ("path", "package_name")
|
| 138 |
+
TYPE_CHECKER = Option.TYPE_CHECKER.copy()
|
| 139 |
+
TYPE_CHECKER["package_name"] = _package_name_option_check
|
| 140 |
+
TYPE_CHECKER["path"] = _path_option_check
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
###########
|
| 144 |
+
# options #
|
| 145 |
+
###########
|
| 146 |
+
|
| 147 |
+
help_: Callable[..., Option] = partial(
|
| 148 |
+
Option,
|
| 149 |
+
"-h",
|
| 150 |
+
"--help",
|
| 151 |
+
dest="help",
|
| 152 |
+
action="help",
|
| 153 |
+
help="Show help.",
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
debug_mode: Callable[..., Option] = partial(
|
| 157 |
+
Option,
|
| 158 |
+
"--debug",
|
| 159 |
+
dest="debug_mode",
|
| 160 |
+
action="store_true",
|
| 161 |
+
default=False,
|
| 162 |
+
help=(
|
| 163 |
+
"Let unhandled exceptions propagate outside the main subroutine, "
|
| 164 |
+
"instead of logging them to stderr."
|
| 165 |
+
),
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
isolated_mode: Callable[..., Option] = partial(
|
| 169 |
+
Option,
|
| 170 |
+
"--isolated",
|
| 171 |
+
dest="isolated_mode",
|
| 172 |
+
action="store_true",
|
| 173 |
+
default=False,
|
| 174 |
+
help=(
|
| 175 |
+
"Run pip in an isolated mode, ignoring environment variables and user "
|
| 176 |
+
"configuration."
|
| 177 |
+
),
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
require_virtualenv: Callable[..., Option] = partial(
|
| 181 |
+
Option,
|
| 182 |
+
"--require-virtualenv",
|
| 183 |
+
"--require-venv",
|
| 184 |
+
dest="require_venv",
|
| 185 |
+
action="store_true",
|
| 186 |
+
default=False,
|
| 187 |
+
help=(
|
| 188 |
+
"Allow pip to only run in a virtual environment; exit with an error otherwise."
|
| 189 |
+
),
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
override_externally_managed: Callable[..., Option] = partial(
|
| 193 |
+
Option,
|
| 194 |
+
"--break-system-packages",
|
| 195 |
+
dest="override_externally_managed",
|
| 196 |
+
action="store_true",
|
| 197 |
+
help="Allow pip to modify an EXTERNALLY-MANAGED Python installation",
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
python: Callable[..., Option] = partial(
|
| 201 |
+
Option,
|
| 202 |
+
"--python",
|
| 203 |
+
dest="python",
|
| 204 |
+
help="Run pip with the specified Python interpreter.",
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
verbose: Callable[..., Option] = partial(
|
| 208 |
+
Option,
|
| 209 |
+
"-v",
|
| 210 |
+
"--verbose",
|
| 211 |
+
dest="verbose",
|
| 212 |
+
action="count",
|
| 213 |
+
default=0,
|
| 214 |
+
help="Give more output. Option is additive, and can be used up to 3 times.",
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
no_color: Callable[..., Option] = partial(
|
| 218 |
+
Option,
|
| 219 |
+
"--no-color",
|
| 220 |
+
dest="no_color",
|
| 221 |
+
action="store_true",
|
| 222 |
+
default=False,
|
| 223 |
+
help="Suppress colored output.",
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
version: Callable[..., Option] = partial(
|
| 227 |
+
Option,
|
| 228 |
+
"-V",
|
| 229 |
+
"--version",
|
| 230 |
+
dest="version",
|
| 231 |
+
action="store_true",
|
| 232 |
+
help="Show version and exit.",
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
quiet: Callable[..., Option] = partial(
|
| 236 |
+
Option,
|
| 237 |
+
"-q",
|
| 238 |
+
"--quiet",
|
| 239 |
+
dest="quiet",
|
| 240 |
+
action="count",
|
| 241 |
+
default=0,
|
| 242 |
+
help=(
|
| 243 |
+
"Give less output. Option is additive, and can be used up to 3"
|
| 244 |
+
" times (corresponding to WARNING, ERROR, and CRITICAL logging"
|
| 245 |
+
" levels)."
|
| 246 |
+
),
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
progress_bar: Callable[..., Option] = partial(
|
| 250 |
+
Option,
|
| 251 |
+
"--progress-bar",
|
| 252 |
+
dest="progress_bar",
|
| 253 |
+
type="choice",
|
| 254 |
+
choices=["auto", "on", "off", "raw"],
|
| 255 |
+
default="auto",
|
| 256 |
+
help=(
|
| 257 |
+
"Specify whether the progress bar should be used. In 'auto'"
|
| 258 |
+
" mode, --quiet will suppress all progress bars."
|
| 259 |
+
" [auto, on, off, raw] (default: auto)"
|
| 260 |
+
),
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
log: Callable[..., Option] = partial(
|
| 264 |
+
PipOption,
|
| 265 |
+
"--log",
|
| 266 |
+
"--log-file",
|
| 267 |
+
"--local-log",
|
| 268 |
+
dest="log",
|
| 269 |
+
metavar="path",
|
| 270 |
+
type="path",
|
| 271 |
+
help="Path to a verbose appending log.",
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
no_input: Callable[..., Option] = partial(
|
| 275 |
+
Option,
|
| 276 |
+
# Don't ask for input
|
| 277 |
+
"--no-input",
|
| 278 |
+
dest="no_input",
|
| 279 |
+
action="store_true",
|
| 280 |
+
default=False,
|
| 281 |
+
help="Disable prompting for input.",
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
keyring_provider: Callable[..., Option] = partial(
|
| 285 |
+
Option,
|
| 286 |
+
"--keyring-provider",
|
| 287 |
+
dest="keyring_provider",
|
| 288 |
+
choices=["auto", "disabled", "import", "subprocess"],
|
| 289 |
+
default="auto",
|
| 290 |
+
help=(
|
| 291 |
+
"Enable the credential lookup via the keyring library if user input is allowed."
|
| 292 |
+
" Specify which mechanism to use [auto, disabled, import, subprocess]."
|
| 293 |
+
" (default: %default)"
|
| 294 |
+
),
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
proxy: Callable[..., Option] = partial(
|
| 298 |
+
Option,
|
| 299 |
+
"--proxy",
|
| 300 |
+
dest="proxy",
|
| 301 |
+
type="str",
|
| 302 |
+
default="",
|
| 303 |
+
help="Specify a proxy in the form scheme://[user:passwd@]proxy.server:port.",
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
retries: Callable[..., Option] = partial(
|
| 307 |
+
Option,
|
| 308 |
+
"--retries",
|
| 309 |
+
dest="retries",
|
| 310 |
+
type="int",
|
| 311 |
+
default=5,
|
| 312 |
+
help="Maximum attempts to establish a new HTTP connection. (default: %default)",
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
+
resume_retries: Callable[..., Option] = partial(
|
| 316 |
+
Option,
|
| 317 |
+
"--resume-retries",
|
| 318 |
+
dest="resume_retries",
|
| 319 |
+
type="int",
|
| 320 |
+
default=5,
|
| 321 |
+
help="Maximum attempts to resume or restart an incomplete download. "
|
| 322 |
+
"(default: %default)",
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
timeout: Callable[..., Option] = partial(
|
| 326 |
+
Option,
|
| 327 |
+
"--timeout",
|
| 328 |
+
"--default-timeout",
|
| 329 |
+
metavar="sec",
|
| 330 |
+
dest="timeout",
|
| 331 |
+
type="float",
|
| 332 |
+
default=15,
|
| 333 |
+
help="Set the socket timeout (default %default seconds).",
|
| 334 |
+
)
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
def exists_action() -> Option:
|
| 338 |
+
return Option(
|
| 339 |
+
# Option when path already exist
|
| 340 |
+
"--exists-action",
|
| 341 |
+
dest="exists_action",
|
| 342 |
+
type="choice",
|
| 343 |
+
choices=["s", "i", "w", "b", "a"],
|
| 344 |
+
default=[],
|
| 345 |
+
action="append",
|
| 346 |
+
metavar="action",
|
| 347 |
+
help="Default action when a path already exists: "
|
| 348 |
+
"(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.",
|
| 349 |
+
)
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
cert: Callable[..., Option] = partial(
|
| 353 |
+
PipOption,
|
| 354 |
+
"--cert",
|
| 355 |
+
dest="cert",
|
| 356 |
+
type="path",
|
| 357 |
+
metavar="path",
|
| 358 |
+
help=(
|
| 359 |
+
"Path to PEM-encoded CA certificate bundle. "
|
| 360 |
+
"If provided, overrides the default. "
|
| 361 |
+
"See 'SSL Certificate Verification' in pip documentation "
|
| 362 |
+
"for more information."
|
| 363 |
+
),
|
| 364 |
+
)
|
| 365 |
+
|
| 366 |
+
client_cert: Callable[..., Option] = partial(
|
| 367 |
+
PipOption,
|
| 368 |
+
"--client-cert",
|
| 369 |
+
dest="client_cert",
|
| 370 |
+
type="path",
|
| 371 |
+
default=None,
|
| 372 |
+
metavar="path",
|
| 373 |
+
help="Path to SSL client certificate, a single file containing the "
|
| 374 |
+
"private key and the certificate in PEM format.",
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
index_url: Callable[..., Option] = partial(
|
| 378 |
+
Option,
|
| 379 |
+
"-i",
|
| 380 |
+
"--index-url",
|
| 381 |
+
"--pypi-url",
|
| 382 |
+
dest="index_url",
|
| 383 |
+
metavar="URL",
|
| 384 |
+
default=PyPI.simple_url,
|
| 385 |
+
help="Base URL of the Python Package Index (default %default). "
|
| 386 |
+
"This should point to a repository compliant with PEP 503 "
|
| 387 |
+
"(the simple repository API) or a local directory laid out "
|
| 388 |
+
"in the same format.",
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
def extra_index_url() -> Option:
|
| 393 |
+
return Option(
|
| 394 |
+
"--extra-index-url",
|
| 395 |
+
dest="extra_index_urls",
|
| 396 |
+
metavar="URL",
|
| 397 |
+
action="append",
|
| 398 |
+
default=[],
|
| 399 |
+
help="Extra URLs of package indexes to use in addition to "
|
| 400 |
+
"--index-url. Should follow the same rules as "
|
| 401 |
+
"--index-url.",
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
no_index: Callable[..., Option] = partial(
|
| 406 |
+
Option,
|
| 407 |
+
"--no-index",
|
| 408 |
+
dest="no_index",
|
| 409 |
+
action="store_true",
|
| 410 |
+
default=False,
|
| 411 |
+
help="Ignore package index (only looking at --find-links URLs instead).",
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
def find_links() -> Option:
|
| 416 |
+
return Option(
|
| 417 |
+
"-f",
|
| 418 |
+
"--find-links",
|
| 419 |
+
dest="find_links",
|
| 420 |
+
action="append",
|
| 421 |
+
default=[],
|
| 422 |
+
metavar="url",
|
| 423 |
+
help="If a URL or path to an html file, then parse for links to "
|
| 424 |
+
"archives such as sdist (.tar.gz) or wheel (.whl) files. "
|
| 425 |
+
"If a local path or file:// URL that's a directory, "
|
| 426 |
+
"then look for archives in the directory listing. "
|
| 427 |
+
"Links to VCS project URLs are not supported.",
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
def _handle_uploaded_prior_to(
|
| 432 |
+
option: Option, opt: str, value: str, parser: OptionParser
|
| 433 |
+
) -> None:
|
| 434 |
+
"""
|
| 435 |
+
This is an optparse.Option callback for the --uploaded-prior-to option.
|
| 436 |
+
|
| 437 |
+
Parses an ISO 8601 datetime string. If no timezone is specified in the string,
|
| 438 |
+
local timezone is used.
|
| 439 |
+
|
| 440 |
+
Note: This option only works with indexes that provide upload-time metadata
|
| 441 |
+
as specified in the simple repository API:
|
| 442 |
+
https://packaging.python.org/en/latest/specifications/simple-repository-api/
|
| 443 |
+
"""
|
| 444 |
+
if value is None:
|
| 445 |
+
return None
|
| 446 |
+
|
| 447 |
+
try:
|
| 448 |
+
uploaded_prior_to = parse_iso_datetime(value)
|
| 449 |
+
# Use local timezone if no offset is given in the ISO string.
|
| 450 |
+
if uploaded_prior_to.tzinfo is None:
|
| 451 |
+
uploaded_prior_to = uploaded_prior_to.astimezone()
|
| 452 |
+
parser.values.uploaded_prior_to = uploaded_prior_to
|
| 453 |
+
except ValueError as exc:
|
| 454 |
+
msg = (
|
| 455 |
+
f"invalid value: {value!r}: {exc}. "
|
| 456 |
+
f"Expected an ISO 8601 datetime string, "
|
| 457 |
+
f"e.g '2023-01-01' or '2023-01-01T00:00:00Z'"
|
| 458 |
+
)
|
| 459 |
+
raise_option_error(parser, option=option, msg=msg)
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
def uploaded_prior_to() -> Option:
|
| 463 |
+
return Option(
|
| 464 |
+
"--uploaded-prior-to",
|
| 465 |
+
dest="uploaded_prior_to",
|
| 466 |
+
metavar="datetime",
|
| 467 |
+
action="callback",
|
| 468 |
+
callback=_handle_uploaded_prior_to,
|
| 469 |
+
type="str",
|
| 470 |
+
help=(
|
| 471 |
+
"Only consider packages uploaded prior to the given date time. "
|
| 472 |
+
"Accepts ISO 8601 strings (e.g., '2023-01-01T00:00:00Z'). "
|
| 473 |
+
"Uses local timezone if none specified. Only effective when "
|
| 474 |
+
"installing from indexes that provide upload-time metadata."
|
| 475 |
+
),
|
| 476 |
+
)
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
def trusted_host() -> Option:
|
| 480 |
+
return Option(
|
| 481 |
+
"--trusted-host",
|
| 482 |
+
dest="trusted_hosts",
|
| 483 |
+
action="append",
|
| 484 |
+
metavar="HOSTNAME",
|
| 485 |
+
default=[],
|
| 486 |
+
help="Mark this host or host:port pair as trusted, even though it "
|
| 487 |
+
"does not have valid or any HTTPS.",
|
| 488 |
+
)
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
def constraints() -> Option:
|
| 492 |
+
return Option(
|
| 493 |
+
"-c",
|
| 494 |
+
"--constraint",
|
| 495 |
+
dest="constraints",
|
| 496 |
+
action="append",
|
| 497 |
+
default=[],
|
| 498 |
+
metavar="file",
|
| 499 |
+
help="Constrain versions using the given constraints file. "
|
| 500 |
+
"This option can be used multiple times.",
|
| 501 |
+
)
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
def build_constraints() -> Option:
|
| 505 |
+
return Option(
|
| 506 |
+
"--build-constraint",
|
| 507 |
+
dest="build_constraints",
|
| 508 |
+
action="append",
|
| 509 |
+
type="str",
|
| 510 |
+
default=[],
|
| 511 |
+
metavar="file",
|
| 512 |
+
help=(
|
| 513 |
+
"Constrain build dependencies using the given constraints file. "
|
| 514 |
+
"This option can be used multiple times."
|
| 515 |
+
),
|
| 516 |
+
)
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
def requirements() -> Option:
|
| 520 |
+
return Option(
|
| 521 |
+
"-r",
|
| 522 |
+
"--requirement",
|
| 523 |
+
dest="requirements",
|
| 524 |
+
action="append",
|
| 525 |
+
default=[],
|
| 526 |
+
metavar="file",
|
| 527 |
+
help="Install from the given requirements file. "
|
| 528 |
+
"This option can be used multiple times.",
|
| 529 |
+
)
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def requirements_from_scripts() -> Option:
|
| 533 |
+
return Option(
|
| 534 |
+
"--requirements-from-script",
|
| 535 |
+
action="append",
|
| 536 |
+
default=[],
|
| 537 |
+
dest="requirements_from_scripts",
|
| 538 |
+
metavar="file",
|
| 539 |
+
help="Install dependencies of the given script file"
|
| 540 |
+
"as defined by PEP 723 inline metadata. ",
|
| 541 |
+
)
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
def editable() -> Option:
|
| 545 |
+
return Option(
|
| 546 |
+
"-e",
|
| 547 |
+
"--editable",
|
| 548 |
+
dest="editables",
|
| 549 |
+
action="append",
|
| 550 |
+
default=[],
|
| 551 |
+
metavar="path/url",
|
| 552 |
+
help=(
|
| 553 |
+
"Install a project in editable mode (i.e. setuptools "
|
| 554 |
+
'"develop mode") from a local project path or a VCS url.'
|
| 555 |
+
),
|
| 556 |
+
)
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
def _handle_src(option: Option, opt_str: str, value: str, parser: OptionParser) -> None:
|
| 560 |
+
value = os.path.abspath(value)
|
| 561 |
+
setattr(parser.values, option.dest, value)
|
| 562 |
+
|
| 563 |
+
|
| 564 |
+
src: Callable[..., Option] = partial(
|
| 565 |
+
PipOption,
|
| 566 |
+
"--src",
|
| 567 |
+
"--source",
|
| 568 |
+
"--source-dir",
|
| 569 |
+
"--source-directory",
|
| 570 |
+
dest="src_dir",
|
| 571 |
+
type="path",
|
| 572 |
+
metavar="dir",
|
| 573 |
+
default=get_src_prefix(),
|
| 574 |
+
action="callback",
|
| 575 |
+
callback=_handle_src,
|
| 576 |
+
help="Directory to check out editable projects into. "
|
| 577 |
+
'The default in a virtualenv is "<venv path>/src". '
|
| 578 |
+
'The default for global installs is "<current dir>/src".',
|
| 579 |
+
)
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def _get_format_control(values: Values, option: Option) -> Any:
|
| 583 |
+
"""Get a format_control object."""
|
| 584 |
+
return getattr(values, option.dest)
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
def _handle_no_binary(
|
| 588 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 589 |
+
) -> None:
|
| 590 |
+
existing = _get_format_control(parser.values, option)
|
| 591 |
+
FormatControl.handle_mutual_excludes(
|
| 592 |
+
value,
|
| 593 |
+
existing.no_binary,
|
| 594 |
+
existing.only_binary,
|
| 595 |
+
)
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
def _handle_only_binary(
|
| 599 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 600 |
+
) -> None:
|
| 601 |
+
existing = _get_format_control(parser.values, option)
|
| 602 |
+
FormatControl.handle_mutual_excludes(
|
| 603 |
+
value,
|
| 604 |
+
existing.only_binary,
|
| 605 |
+
existing.no_binary,
|
| 606 |
+
)
|
| 607 |
+
|
| 608 |
+
|
| 609 |
+
def no_binary() -> Option:
|
| 610 |
+
format_control = FormatControl(set(), set())
|
| 611 |
+
return Option(
|
| 612 |
+
"--no-binary",
|
| 613 |
+
dest="format_control",
|
| 614 |
+
action="callback",
|
| 615 |
+
callback=_handle_no_binary,
|
| 616 |
+
type="str",
|
| 617 |
+
default=format_control,
|
| 618 |
+
help="Do not use binary packages. Can be supplied multiple times, and "
|
| 619 |
+
'each time adds to the existing value. Accepts either ":all:" to '
|
| 620 |
+
'disable all binary packages, ":none:" to empty the set (notice '
|
| 621 |
+
"the colons), or one or more package names with commas between "
|
| 622 |
+
"them (no colons). Note that some packages are tricky to compile "
|
| 623 |
+
"and may fail to install when this option is used on them.",
|
| 624 |
+
)
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
def only_binary() -> Option:
|
| 628 |
+
format_control = FormatControl(set(), set())
|
| 629 |
+
return Option(
|
| 630 |
+
"--only-binary",
|
| 631 |
+
dest="format_control",
|
| 632 |
+
action="callback",
|
| 633 |
+
callback=_handle_only_binary,
|
| 634 |
+
type="str",
|
| 635 |
+
default=format_control,
|
| 636 |
+
help="Do not use source packages. Can be supplied multiple times, and "
|
| 637 |
+
'each time adds to the existing value. Accepts either ":all:" to '
|
| 638 |
+
'disable all source packages, ":none:" to empty the set, or one '
|
| 639 |
+
"or more package names with commas between them. Packages "
|
| 640 |
+
"without binary distributions will fail to install when this "
|
| 641 |
+
"option is used on them.",
|
| 642 |
+
)
|
| 643 |
+
|
| 644 |
+
|
| 645 |
+
def _get_release_control(values: Values, option: Option) -> Any:
|
| 646 |
+
"""Get a release_control object."""
|
| 647 |
+
return getattr(values, option.dest)
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
def _handle_all_releases(
|
| 651 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 652 |
+
) -> None:
|
| 653 |
+
existing = _get_release_control(parser.values, option)
|
| 654 |
+
existing.handle_mutual_excludes(
|
| 655 |
+
value,
|
| 656 |
+
existing.all_releases,
|
| 657 |
+
existing.only_final,
|
| 658 |
+
"all_releases",
|
| 659 |
+
)
|
| 660 |
+
|
| 661 |
+
|
| 662 |
+
def _handle_only_final(
|
| 663 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 664 |
+
) -> None:
|
| 665 |
+
existing = _get_release_control(parser.values, option)
|
| 666 |
+
existing.handle_mutual_excludes(
|
| 667 |
+
value,
|
| 668 |
+
existing.only_final,
|
| 669 |
+
existing.all_releases,
|
| 670 |
+
"only_final",
|
| 671 |
+
)
|
| 672 |
+
|
| 673 |
+
|
| 674 |
+
def all_releases() -> Option:
|
| 675 |
+
release_control = ReleaseControl(set(), set())
|
| 676 |
+
return Option(
|
| 677 |
+
"--all-releases",
|
| 678 |
+
dest="release_control",
|
| 679 |
+
action="callback",
|
| 680 |
+
callback=_handle_all_releases,
|
| 681 |
+
type="str",
|
| 682 |
+
default=release_control,
|
| 683 |
+
help="Allow all release types (including pre-releases) for a package. "
|
| 684 |
+
"Can be supplied multiple times, and each time adds to the existing "
|
| 685 |
+
'value. Accepts either ":all:" to allow pre-releases for all '
|
| 686 |
+
'packages, ":none:" to empty the set (notice the colons), or one or '
|
| 687 |
+
"more package names with commas between them (no colons). Cannot be "
|
| 688 |
+
"used with --pre.",
|
| 689 |
+
)
|
| 690 |
+
|
| 691 |
+
|
| 692 |
+
def only_final() -> Option:
|
| 693 |
+
release_control = ReleaseControl(set(), set())
|
| 694 |
+
return Option(
|
| 695 |
+
"--only-final",
|
| 696 |
+
dest="release_control",
|
| 697 |
+
action="callback",
|
| 698 |
+
callback=_handle_only_final,
|
| 699 |
+
type="str",
|
| 700 |
+
default=release_control,
|
| 701 |
+
help="Only allow final releases (no pre-releases) for a package. Can be "
|
| 702 |
+
"supplied multiple times, and each time adds to the existing value. "
|
| 703 |
+
'Accepts either ":all:" to disable pre-releases for all packages, '
|
| 704 |
+
'":none:" to empty the set, or one or more package names with commas '
|
| 705 |
+
"between them. Cannot be used with --pre.",
|
| 706 |
+
)
|
| 707 |
+
|
| 708 |
+
|
| 709 |
+
def check_release_control_exclusive(options: Values) -> None:
|
| 710 |
+
"""
|
| 711 |
+
Raise an error if --pre is used with --all-releases or --only-final,
|
| 712 |
+
and transform --pre into --all-releases :all: if used alone.
|
| 713 |
+
"""
|
| 714 |
+
if not hasattr(options, "pre") or not options.pre:
|
| 715 |
+
return
|
| 716 |
+
|
| 717 |
+
release_control = options.release_control
|
| 718 |
+
if release_control.all_releases or release_control.only_final:
|
| 719 |
+
raise CommandError("--pre cannot be used with --all-releases or --only-final.")
|
| 720 |
+
|
| 721 |
+
# Transform --pre into --all-releases :all:
|
| 722 |
+
release_control.all_releases.add(":all:")
|
| 723 |
+
|
| 724 |
+
|
| 725 |
+
platforms: Callable[..., Option] = partial(
|
| 726 |
+
Option,
|
| 727 |
+
"--platform",
|
| 728 |
+
dest="platforms",
|
| 729 |
+
metavar="platform",
|
| 730 |
+
action="append",
|
| 731 |
+
default=None,
|
| 732 |
+
help=(
|
| 733 |
+
"Only use wheels compatible with <platform>. Defaults to the "
|
| 734 |
+
"platform of the running system. Use this option multiple times to "
|
| 735 |
+
"specify multiple platforms supported by the target interpreter."
|
| 736 |
+
),
|
| 737 |
+
)
|
| 738 |
+
|
| 739 |
+
|
| 740 |
+
# This was made a separate function for unit-testing purposes.
|
| 741 |
+
def _convert_python_version(value: str) -> tuple[tuple[int, ...], str | None]:
|
| 742 |
+
"""
|
| 743 |
+
Convert a version string like "3", "37", or "3.7.3" into a tuple of ints.
|
| 744 |
+
|
| 745 |
+
:return: A 2-tuple (version_info, error_msg), where `error_msg` is
|
| 746 |
+
non-None if and only if there was a parsing error.
|
| 747 |
+
"""
|
| 748 |
+
if not value:
|
| 749 |
+
# The empty string is the same as not providing a value.
|
| 750 |
+
return (None, None)
|
| 751 |
+
|
| 752 |
+
parts = value.split(".")
|
| 753 |
+
if len(parts) > 3:
|
| 754 |
+
return ((), "at most three version parts are allowed")
|
| 755 |
+
|
| 756 |
+
if len(parts) == 1:
|
| 757 |
+
# Then we are in the case of "3" or "37".
|
| 758 |
+
value = parts[0]
|
| 759 |
+
if len(value) > 1:
|
| 760 |
+
parts = [value[0], value[1:]]
|
| 761 |
+
|
| 762 |
+
try:
|
| 763 |
+
version_info = tuple(int(part) for part in parts)
|
| 764 |
+
except ValueError:
|
| 765 |
+
return ((), "each version part must be an integer")
|
| 766 |
+
|
| 767 |
+
return (version_info, None)
|
| 768 |
+
|
| 769 |
+
|
| 770 |
+
def _handle_python_version(
|
| 771 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 772 |
+
) -> None:
|
| 773 |
+
"""
|
| 774 |
+
Handle a provided --python-version value.
|
| 775 |
+
"""
|
| 776 |
+
version_info, error_msg = _convert_python_version(value)
|
| 777 |
+
if error_msg is not None:
|
| 778 |
+
msg = f"invalid --python-version value: {value!r}: {error_msg}"
|
| 779 |
+
raise_option_error(parser, option=option, msg=msg)
|
| 780 |
+
|
| 781 |
+
parser.values.python_version = version_info
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
python_version: Callable[..., Option] = partial(
|
| 785 |
+
Option,
|
| 786 |
+
"--python-version",
|
| 787 |
+
dest="python_version",
|
| 788 |
+
metavar="python_version",
|
| 789 |
+
action="callback",
|
| 790 |
+
callback=_handle_python_version,
|
| 791 |
+
type="str",
|
| 792 |
+
default=None,
|
| 793 |
+
help=dedent(
|
| 794 |
+
"""\
|
| 795 |
+
The Python interpreter version to use for wheel and "Requires-Python"
|
| 796 |
+
compatibility checks. Defaults to a version derived from the running
|
| 797 |
+
interpreter. The version can be specified using up to three dot-separated
|
| 798 |
+
integers (e.g. "3" for 3.0.0, "3.7" for 3.7.0, or "3.7.3"). A major-minor
|
| 799 |
+
version can also be given as a string without dots (e.g. "37" for 3.7.0).
|
| 800 |
+
"""
|
| 801 |
+
),
|
| 802 |
+
)
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
implementation: Callable[..., Option] = partial(
|
| 806 |
+
Option,
|
| 807 |
+
"--implementation",
|
| 808 |
+
dest="implementation",
|
| 809 |
+
metavar="implementation",
|
| 810 |
+
default=None,
|
| 811 |
+
help=(
|
| 812 |
+
"Only use wheels compatible with Python "
|
| 813 |
+
"implementation <implementation>, e.g. 'pp', 'jy', 'cp', "
|
| 814 |
+
" or 'ip'. If not specified, then the current "
|
| 815 |
+
"interpreter implementation is used. Use 'py' to force "
|
| 816 |
+
"implementation-agnostic wheels."
|
| 817 |
+
),
|
| 818 |
+
)
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
abis: Callable[..., Option] = partial(
|
| 822 |
+
Option,
|
| 823 |
+
"--abi",
|
| 824 |
+
dest="abis",
|
| 825 |
+
metavar="abi",
|
| 826 |
+
action="append",
|
| 827 |
+
default=None,
|
| 828 |
+
help=(
|
| 829 |
+
"Only use wheels compatible with Python abi <abi>, e.g. 'pypy_41'. "
|
| 830 |
+
"If not specified, then the current interpreter abi tag is used. "
|
| 831 |
+
"Use this option multiple times to specify multiple abis supported "
|
| 832 |
+
"by the target interpreter. Generally you will need to specify "
|
| 833 |
+
"--implementation, --platform, and --python-version when using this "
|
| 834 |
+
"option."
|
| 835 |
+
),
|
| 836 |
+
)
|
| 837 |
+
|
| 838 |
+
|
| 839 |
+
def add_target_python_options(cmd_opts: OptionGroup) -> None:
|
| 840 |
+
cmd_opts.add_option(platforms())
|
| 841 |
+
cmd_opts.add_option(python_version())
|
| 842 |
+
cmd_opts.add_option(implementation())
|
| 843 |
+
cmd_opts.add_option(abis())
|
| 844 |
+
|
| 845 |
+
|
| 846 |
+
def make_target_python(options: Values) -> TargetPython:
|
| 847 |
+
target_python = TargetPython(
|
| 848 |
+
platforms=options.platforms,
|
| 849 |
+
py_version_info=options.python_version,
|
| 850 |
+
abis=options.abis,
|
| 851 |
+
implementation=options.implementation,
|
| 852 |
+
)
|
| 853 |
+
|
| 854 |
+
return target_python
|
| 855 |
+
|
| 856 |
+
|
| 857 |
+
def prefer_binary() -> Option:
|
| 858 |
+
return Option(
|
| 859 |
+
"--prefer-binary",
|
| 860 |
+
dest="prefer_binary",
|
| 861 |
+
action="store_true",
|
| 862 |
+
default=False,
|
| 863 |
+
help=(
|
| 864 |
+
"Prefer binary packages over source packages, even if the "
|
| 865 |
+
"source packages are newer."
|
| 866 |
+
),
|
| 867 |
+
)
|
| 868 |
+
|
| 869 |
+
|
| 870 |
+
cache_dir: Callable[..., Option] = partial(
|
| 871 |
+
PipOption,
|
| 872 |
+
"--cache-dir",
|
| 873 |
+
dest="cache_dir",
|
| 874 |
+
default=USER_CACHE_DIR,
|
| 875 |
+
metavar="dir",
|
| 876 |
+
type="path",
|
| 877 |
+
help="Store the cache data in <dir>.",
|
| 878 |
+
)
|
| 879 |
+
|
| 880 |
+
|
| 881 |
+
def _handle_no_cache_dir(
|
| 882 |
+
option: Option, opt: str, value: str, parser: OptionParser
|
| 883 |
+
) -> None:
|
| 884 |
+
"""
|
| 885 |
+
Process a value provided for the --no-cache-dir option.
|
| 886 |
+
|
| 887 |
+
This is an optparse.Option callback for the --no-cache-dir option.
|
| 888 |
+
"""
|
| 889 |
+
# The value argument will be None if --no-cache-dir is passed via the
|
| 890 |
+
# command-line, since the option doesn't accept arguments. However,
|
| 891 |
+
# the value can be non-None if the option is triggered e.g. by an
|
| 892 |
+
# environment variable, like PIP_NO_CACHE_DIR=true.
|
| 893 |
+
if value is not None:
|
| 894 |
+
# Then parse the string value to get argument error-checking.
|
| 895 |
+
try:
|
| 896 |
+
strtobool(value)
|
| 897 |
+
except ValueError as exc:
|
| 898 |
+
raise_option_error(parser, option=option, msg=str(exc))
|
| 899 |
+
|
| 900 |
+
# Originally, setting PIP_NO_CACHE_DIR to a value that strtobool()
|
| 901 |
+
# converted to 0 (like "false" or "no") caused cache_dir to be disabled
|
| 902 |
+
# rather than enabled (logic would say the latter). Thus, we disable
|
| 903 |
+
# the cache directory not just on values that parse to True, but (for
|
| 904 |
+
# backwards compatibility reasons) also on values that parse to False.
|
| 905 |
+
# In other words, always set it to False if the option is provided in
|
| 906 |
+
# some (valid) form.
|
| 907 |
+
parser.values.cache_dir = False
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
no_cache: Callable[..., Option] = partial(
|
| 911 |
+
Option,
|
| 912 |
+
"--no-cache-dir",
|
| 913 |
+
dest="cache_dir",
|
| 914 |
+
action="callback",
|
| 915 |
+
callback=_handle_no_cache_dir,
|
| 916 |
+
help="Disable the cache.",
|
| 917 |
+
)
|
| 918 |
+
|
| 919 |
+
no_deps: Callable[..., Option] = partial(
|
| 920 |
+
Option,
|
| 921 |
+
"--no-deps",
|
| 922 |
+
"--no-dependencies",
|
| 923 |
+
dest="ignore_dependencies",
|
| 924 |
+
action="store_true",
|
| 925 |
+
default=False,
|
| 926 |
+
help="Don't install package dependencies.",
|
| 927 |
+
)
|
| 928 |
+
|
| 929 |
+
|
| 930 |
+
def _handle_dependency_group(
|
| 931 |
+
option: Option, opt: str, value: str, parser: OptionParser
|
| 932 |
+
) -> None:
|
| 933 |
+
"""
|
| 934 |
+
Process a value provided for the --group option.
|
| 935 |
+
|
| 936 |
+
Splits on the rightmost ":", and validates that the path (if present) ends
|
| 937 |
+
in `pyproject.toml`. Defaults the path to `pyproject.toml` when one is not given.
|
| 938 |
+
|
| 939 |
+
`:` cannot appear in dependency group names, so this is a safe and simple parse.
|
| 940 |
+
|
| 941 |
+
This is an optparse.Option callback for the dependency_groups option.
|
| 942 |
+
"""
|
| 943 |
+
path, sep, groupname = value.rpartition(":")
|
| 944 |
+
if not sep:
|
| 945 |
+
path = "pyproject.toml"
|
| 946 |
+
else:
|
| 947 |
+
# check for 'pyproject.toml' filenames using pathlib
|
| 948 |
+
if pathlib.PurePath(path).name != "pyproject.toml":
|
| 949 |
+
msg = "group paths use 'pyproject.toml' filenames"
|
| 950 |
+
raise_option_error(parser, option=option, msg=msg)
|
| 951 |
+
|
| 952 |
+
parser.values.dependency_groups.append((path, groupname))
|
| 953 |
+
|
| 954 |
+
|
| 955 |
+
dependency_groups: Callable[..., Option] = partial(
|
| 956 |
+
Option,
|
| 957 |
+
"--group",
|
| 958 |
+
dest="dependency_groups",
|
| 959 |
+
default=[],
|
| 960 |
+
type=str,
|
| 961 |
+
action="callback",
|
| 962 |
+
callback=_handle_dependency_group,
|
| 963 |
+
metavar="[path:]group",
|
| 964 |
+
help='Install a named dependency-group from a "pyproject.toml" file. '
|
| 965 |
+
'If a path is given, the name of the file must be "pyproject.toml". '
|
| 966 |
+
'Defaults to using "pyproject.toml" in the current directory.',
|
| 967 |
+
)
|
| 968 |
+
|
| 969 |
+
ignore_requires_python: Callable[..., Option] = partial(
|
| 970 |
+
Option,
|
| 971 |
+
"--ignore-requires-python",
|
| 972 |
+
dest="ignore_requires_python",
|
| 973 |
+
action="store_true",
|
| 974 |
+
help="Ignore the Requires-Python information.",
|
| 975 |
+
)
|
| 976 |
+
|
| 977 |
+
|
| 978 |
+
no_build_isolation: Callable[..., Option] = partial(
|
| 979 |
+
Option,
|
| 980 |
+
"--no-build-isolation",
|
| 981 |
+
dest="build_isolation",
|
| 982 |
+
action="store_false",
|
| 983 |
+
default=True,
|
| 984 |
+
help="Disable isolation when building a modern source distribution. "
|
| 985 |
+
"Build dependencies specified by PEP 518 must be already installed "
|
| 986 |
+
"if this option is used.",
|
| 987 |
+
)
|
| 988 |
+
|
| 989 |
+
check_build_deps: Callable[..., Option] = partial(
|
| 990 |
+
Option,
|
| 991 |
+
"--check-build-dependencies",
|
| 992 |
+
dest="check_build_deps",
|
| 993 |
+
action="store_true",
|
| 994 |
+
default=False,
|
| 995 |
+
help="Check the build dependencies.",
|
| 996 |
+
)
|
| 997 |
+
|
| 998 |
+
|
| 999 |
+
use_pep517: Any = partial(
|
| 1000 |
+
Option,
|
| 1001 |
+
"--use-pep517",
|
| 1002 |
+
dest="use_pep517",
|
| 1003 |
+
action="store_true",
|
| 1004 |
+
default=True,
|
| 1005 |
+
help=SUPPRESS_HELP,
|
| 1006 |
+
)
|
| 1007 |
+
|
| 1008 |
+
|
| 1009 |
+
def _handle_config_settings(
|
| 1010 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 1011 |
+
) -> None:
|
| 1012 |
+
key, sep, val = value.partition("=")
|
| 1013 |
+
if sep != "=":
|
| 1014 |
+
parser.error(f"Arguments to {opt_str} must be of the form KEY=VAL")
|
| 1015 |
+
dest = getattr(parser.values, option.dest)
|
| 1016 |
+
if dest is None:
|
| 1017 |
+
dest = {}
|
| 1018 |
+
setattr(parser.values, option.dest, dest)
|
| 1019 |
+
if key in dest:
|
| 1020 |
+
if isinstance(dest[key], list):
|
| 1021 |
+
dest[key].append(val)
|
| 1022 |
+
else:
|
| 1023 |
+
dest[key] = [dest[key], val]
|
| 1024 |
+
else:
|
| 1025 |
+
dest[key] = val
|
| 1026 |
+
|
| 1027 |
+
|
| 1028 |
+
config_settings: Callable[..., Option] = partial(
|
| 1029 |
+
Option,
|
| 1030 |
+
"-C",
|
| 1031 |
+
"--config-settings",
|
| 1032 |
+
dest="config_settings",
|
| 1033 |
+
type=str,
|
| 1034 |
+
action="callback",
|
| 1035 |
+
callback=_handle_config_settings,
|
| 1036 |
+
metavar="settings",
|
| 1037 |
+
help="Configuration settings to be passed to the build backend. "
|
| 1038 |
+
"Settings take the form KEY=VALUE. Use multiple --config-settings options "
|
| 1039 |
+
"to pass multiple keys to the backend.",
|
| 1040 |
+
)
|
| 1041 |
+
|
| 1042 |
+
no_clean: Callable[..., Option] = partial(
|
| 1043 |
+
Option,
|
| 1044 |
+
"--no-clean",
|
| 1045 |
+
action="store_true",
|
| 1046 |
+
default=False,
|
| 1047 |
+
help="Don't clean up build directories.",
|
| 1048 |
+
)
|
| 1049 |
+
|
| 1050 |
+
pre: Callable[..., Option] = partial(
|
| 1051 |
+
Option,
|
| 1052 |
+
"--pre",
|
| 1053 |
+
action="store_true",
|
| 1054 |
+
default=False,
|
| 1055 |
+
help="Include pre-release and development versions. By default, "
|
| 1056 |
+
"pip only finds stable versions.",
|
| 1057 |
+
)
|
| 1058 |
+
|
| 1059 |
+
json: Callable[..., Option] = partial(
|
| 1060 |
+
Option,
|
| 1061 |
+
"--json",
|
| 1062 |
+
action="store_true",
|
| 1063 |
+
default=False,
|
| 1064 |
+
help="Output data in a machine-readable JSON format.",
|
| 1065 |
+
)
|
| 1066 |
+
|
| 1067 |
+
disable_pip_version_check: Callable[..., Option] = partial(
|
| 1068 |
+
Option,
|
| 1069 |
+
"--disable-pip-version-check",
|
| 1070 |
+
dest="disable_pip_version_check",
|
| 1071 |
+
action="store_true",
|
| 1072 |
+
default=False,
|
| 1073 |
+
help="Don't periodically check PyPI to determine whether a new version "
|
| 1074 |
+
"of pip is available for download. Implied with --no-index.",
|
| 1075 |
+
)
|
| 1076 |
+
|
| 1077 |
+
root_user_action: Callable[..., Option] = partial(
|
| 1078 |
+
Option,
|
| 1079 |
+
"--root-user-action",
|
| 1080 |
+
dest="root_user_action",
|
| 1081 |
+
default="warn",
|
| 1082 |
+
choices=["warn", "ignore"],
|
| 1083 |
+
help="Action if pip is run as a root user [warn, ignore] (default: warn)",
|
| 1084 |
+
)
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
def _handle_merge_hash(
|
| 1088 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 1089 |
+
) -> None:
|
| 1090 |
+
"""Given a value spelled "algo:digest", append the digest to a list
|
| 1091 |
+
pointed to in a dict by the algo name."""
|
| 1092 |
+
if not parser.values.hashes:
|
| 1093 |
+
parser.values.hashes = {}
|
| 1094 |
+
try:
|
| 1095 |
+
algo, digest = value.split(":", 1)
|
| 1096 |
+
except ValueError:
|
| 1097 |
+
parser.error(
|
| 1098 |
+
f"Arguments to {opt_str} must be a hash name "
|
| 1099 |
+
"followed by a value, like --hash=sha256:"
|
| 1100 |
+
"abcde..."
|
| 1101 |
+
)
|
| 1102 |
+
if algo not in STRONG_HASHES:
|
| 1103 |
+
parser.error(
|
| 1104 |
+
"Allowed hash algorithms for {} are {}.".format(
|
| 1105 |
+
opt_str, ", ".join(STRONG_HASHES)
|
| 1106 |
+
)
|
| 1107 |
+
)
|
| 1108 |
+
parser.values.hashes.setdefault(algo, []).append(digest)
|
| 1109 |
+
|
| 1110 |
+
|
| 1111 |
+
hash: Callable[..., Option] = partial(
|
| 1112 |
+
Option,
|
| 1113 |
+
"--hash",
|
| 1114 |
+
# Hash values eventually end up in InstallRequirement.hashes due to
|
| 1115 |
+
# __dict__ copying in process_line().
|
| 1116 |
+
dest="hashes",
|
| 1117 |
+
action="callback",
|
| 1118 |
+
callback=_handle_merge_hash,
|
| 1119 |
+
type="string",
|
| 1120 |
+
help="Verify that the package's archive matches this "
|
| 1121 |
+
"hash before installing. Example: --hash=sha256:abcdef...",
|
| 1122 |
+
)
|
| 1123 |
+
|
| 1124 |
+
|
| 1125 |
+
require_hashes: Callable[..., Option] = partial(
|
| 1126 |
+
Option,
|
| 1127 |
+
"--require-hashes",
|
| 1128 |
+
dest="require_hashes",
|
| 1129 |
+
action="store_true",
|
| 1130 |
+
default=False,
|
| 1131 |
+
help="Require a hash to check each requirement against, for "
|
| 1132 |
+
"repeatable installs. This option is implied when any package in a "
|
| 1133 |
+
"requirements file has a --hash option.",
|
| 1134 |
+
)
|
| 1135 |
+
|
| 1136 |
+
|
| 1137 |
+
list_path: Callable[..., Option] = partial(
|
| 1138 |
+
PipOption,
|
| 1139 |
+
"--path",
|
| 1140 |
+
dest="path",
|
| 1141 |
+
type="path",
|
| 1142 |
+
action="append",
|
| 1143 |
+
help="Restrict to the specified installation path for listing "
|
| 1144 |
+
"packages (can be used multiple times).",
|
| 1145 |
+
)
|
| 1146 |
+
|
| 1147 |
+
|
| 1148 |
+
def check_list_path_option(options: Values) -> None:
|
| 1149 |
+
if options.path and (options.user or options.local):
|
| 1150 |
+
raise CommandError("Cannot combine '--path' with '--user' or '--local'")
|
| 1151 |
+
|
| 1152 |
+
|
| 1153 |
+
list_exclude: Callable[..., Option] = partial(
|
| 1154 |
+
PipOption,
|
| 1155 |
+
"--exclude",
|
| 1156 |
+
dest="excludes",
|
| 1157 |
+
action="append",
|
| 1158 |
+
metavar="package",
|
| 1159 |
+
type="package_name",
|
| 1160 |
+
help="Exclude specified package from the output",
|
| 1161 |
+
)
|
| 1162 |
+
|
| 1163 |
+
|
| 1164 |
+
no_python_version_warning: Callable[..., Option] = partial(
|
| 1165 |
+
Option,
|
| 1166 |
+
"--no-python-version-warning",
|
| 1167 |
+
dest="no_python_version_warning",
|
| 1168 |
+
action="store_true",
|
| 1169 |
+
default=False,
|
| 1170 |
+
help=SUPPRESS_HELP, # No-op, a hold-over from the Python 2->3 transition.
|
| 1171 |
+
)
|
| 1172 |
+
|
| 1173 |
+
|
| 1174 |
+
# Features that are now always on. A warning is printed if they are used.
|
| 1175 |
+
ALWAYS_ENABLED_FEATURES = [
|
| 1176 |
+
"truststore", # always on since 24.2
|
| 1177 |
+
"no-binary-enable-wheel-cache", # always on since 23.1
|
| 1178 |
+
]
|
| 1179 |
+
|
| 1180 |
+
use_new_feature: Callable[..., Option] = partial(
|
| 1181 |
+
Option,
|
| 1182 |
+
"--use-feature",
|
| 1183 |
+
dest="features_enabled",
|
| 1184 |
+
metavar="feature",
|
| 1185 |
+
action="append",
|
| 1186 |
+
default=[],
|
| 1187 |
+
choices=[
|
| 1188 |
+
"fast-deps",
|
| 1189 |
+
"build-constraint",
|
| 1190 |
+
"inprocess-build-deps",
|
| 1191 |
+
]
|
| 1192 |
+
+ ALWAYS_ENABLED_FEATURES,
|
| 1193 |
+
help="Enable new functionality, that may be backward incompatible.",
|
| 1194 |
+
)
|
| 1195 |
+
|
| 1196 |
+
use_deprecated_feature: Callable[..., Option] = partial(
|
| 1197 |
+
Option,
|
| 1198 |
+
"--use-deprecated",
|
| 1199 |
+
dest="deprecated_features_enabled",
|
| 1200 |
+
metavar="feature",
|
| 1201 |
+
action="append",
|
| 1202 |
+
default=[],
|
| 1203 |
+
choices=[
|
| 1204 |
+
"legacy-resolver",
|
| 1205 |
+
"legacy-certs",
|
| 1206 |
+
],
|
| 1207 |
+
help=("Enable deprecated functionality, that will be removed in the future."),
|
| 1208 |
+
)
|
| 1209 |
+
|
| 1210 |
+
##########
|
| 1211 |
+
# groups #
|
| 1212 |
+
##########
|
| 1213 |
+
|
| 1214 |
+
general_group: dict[str, Any] = {
|
| 1215 |
+
"name": "General Options",
|
| 1216 |
+
"options": [
|
| 1217 |
+
help_,
|
| 1218 |
+
debug_mode,
|
| 1219 |
+
isolated_mode,
|
| 1220 |
+
require_virtualenv,
|
| 1221 |
+
python,
|
| 1222 |
+
verbose,
|
| 1223 |
+
version,
|
| 1224 |
+
quiet,
|
| 1225 |
+
log,
|
| 1226 |
+
no_input,
|
| 1227 |
+
keyring_provider,
|
| 1228 |
+
proxy,
|
| 1229 |
+
retries,
|
| 1230 |
+
timeout,
|
| 1231 |
+
exists_action,
|
| 1232 |
+
trusted_host,
|
| 1233 |
+
cert,
|
| 1234 |
+
client_cert,
|
| 1235 |
+
cache_dir,
|
| 1236 |
+
no_cache,
|
| 1237 |
+
disable_pip_version_check,
|
| 1238 |
+
no_color,
|
| 1239 |
+
no_python_version_warning,
|
| 1240 |
+
use_new_feature,
|
| 1241 |
+
use_deprecated_feature,
|
| 1242 |
+
resume_retries,
|
| 1243 |
+
],
|
| 1244 |
+
}
|
| 1245 |
+
|
| 1246 |
+
index_group: dict[str, Any] = {
|
| 1247 |
+
"name": "Package Index Options",
|
| 1248 |
+
"options": [
|
| 1249 |
+
index_url,
|
| 1250 |
+
extra_index_url,
|
| 1251 |
+
no_index,
|
| 1252 |
+
find_links,
|
| 1253 |
+
uploaded_prior_to,
|
| 1254 |
+
],
|
| 1255 |
+
}
|
| 1256 |
+
|
| 1257 |
+
package_selection_group: dict[str, Any] = {
|
| 1258 |
+
"name": "Package Selection Options",
|
| 1259 |
+
"options": [
|
| 1260 |
+
pre,
|
| 1261 |
+
all_releases,
|
| 1262 |
+
only_final,
|
| 1263 |
+
no_binary,
|
| 1264 |
+
only_binary,
|
| 1265 |
+
prefer_binary,
|
| 1266 |
+
],
|
| 1267 |
+
}
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/command_context.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Generator
|
| 2 |
+
from contextlib import AbstractContextManager, ExitStack, contextmanager
|
| 3 |
+
from typing import TypeVar
|
| 4 |
+
|
| 5 |
+
_T = TypeVar("_T", covariant=True)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class CommandContextMixIn:
|
| 9 |
+
def __init__(self) -> None:
|
| 10 |
+
super().__init__()
|
| 11 |
+
self._in_main_context = False
|
| 12 |
+
self._main_context = ExitStack()
|
| 13 |
+
|
| 14 |
+
@contextmanager
|
| 15 |
+
def main_context(self) -> Generator[None, None, None]:
|
| 16 |
+
assert not self._in_main_context
|
| 17 |
+
|
| 18 |
+
self._in_main_context = True
|
| 19 |
+
try:
|
| 20 |
+
with self._main_context:
|
| 21 |
+
yield
|
| 22 |
+
finally:
|
| 23 |
+
self._in_main_context = False
|
| 24 |
+
|
| 25 |
+
def enter_context(self, context_provider: AbstractContextManager[_T]) -> _T:
|
| 26 |
+
assert self._in_main_context
|
| 27 |
+
|
| 28 |
+
return self._main_context.enter_context(context_provider)
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/index_command.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Contains command classes which may interact with an index / the network.
|
| 3 |
+
|
| 4 |
+
Unlike its sister module, req_command, this module still uses lazy imports
|
| 5 |
+
so commands which don't always hit the network (e.g. list w/o --outdated or
|
| 6 |
+
--uptodate) don't need waste time importing PipSession and friends.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import logging
|
| 12 |
+
import os
|
| 13 |
+
import sys
|
| 14 |
+
from functools import lru_cache
|
| 15 |
+
from optparse import Values
|
| 16 |
+
from typing import TYPE_CHECKING
|
| 17 |
+
|
| 18 |
+
from pip._vendor import certifi
|
| 19 |
+
|
| 20 |
+
from pip._internal.cli.base_command import Command
|
| 21 |
+
from pip._internal.cli.command_context import CommandContextMixIn
|
| 22 |
+
|
| 23 |
+
if TYPE_CHECKING:
|
| 24 |
+
from ssl import SSLContext
|
| 25 |
+
|
| 26 |
+
from pip._vendor.packaging.utils import NormalizedName
|
| 27 |
+
|
| 28 |
+
from pip._internal.network.session import PipSession
|
| 29 |
+
|
| 30 |
+
logger = logging.getLogger(__name__)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@lru_cache
|
| 34 |
+
def _create_truststore_ssl_context() -> SSLContext | None:
|
| 35 |
+
if sys.version_info < (3, 10):
|
| 36 |
+
logger.debug("Disabling truststore because Python version isn't 3.10+")
|
| 37 |
+
return None
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
import ssl
|
| 41 |
+
except ImportError:
|
| 42 |
+
logger.warning("Disabling truststore since ssl support is missing")
|
| 43 |
+
return None
|
| 44 |
+
|
| 45 |
+
try:
|
| 46 |
+
from pip._vendor import truststore
|
| 47 |
+
except ImportError:
|
| 48 |
+
logger.warning("Disabling truststore because platform isn't supported")
|
| 49 |
+
return None
|
| 50 |
+
|
| 51 |
+
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
| 52 |
+
ctx.load_verify_locations(certifi.where())
|
| 53 |
+
return ctx
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class SessionCommandMixin(CommandContextMixIn):
|
| 57 |
+
"""
|
| 58 |
+
A class mixin for command classes needing _build_session().
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
def __init__(self) -> None:
|
| 62 |
+
super().__init__()
|
| 63 |
+
self._session: PipSession | None = None
|
| 64 |
+
|
| 65 |
+
@classmethod
|
| 66 |
+
def _get_index_urls(cls, options: Values) -> list[str] | None:
|
| 67 |
+
"""Return a list of index urls from user-provided options."""
|
| 68 |
+
index_urls = []
|
| 69 |
+
if not getattr(options, "no_index", False):
|
| 70 |
+
url = getattr(options, "index_url", None)
|
| 71 |
+
if url:
|
| 72 |
+
index_urls.append(url)
|
| 73 |
+
urls = getattr(options, "extra_index_urls", None)
|
| 74 |
+
if urls:
|
| 75 |
+
index_urls.extend(urls)
|
| 76 |
+
# Return None rather than an empty list
|
| 77 |
+
return index_urls or None
|
| 78 |
+
|
| 79 |
+
def get_default_session(self, options: Values) -> PipSession:
|
| 80 |
+
"""Get a default-managed session."""
|
| 81 |
+
if self._session is None:
|
| 82 |
+
self._session = self.enter_context(self._build_session(options))
|
| 83 |
+
# there's no type annotation on requests.Session, so it's
|
| 84 |
+
# automatically ContextManager[Any] and self._session becomes Any,
|
| 85 |
+
# then https://github.com/python/mypy/issues/7696 kicks in
|
| 86 |
+
assert self._session is not None
|
| 87 |
+
return self._session
|
| 88 |
+
|
| 89 |
+
def _build_session(
|
| 90 |
+
self,
|
| 91 |
+
options: Values,
|
| 92 |
+
retries: int | None = None,
|
| 93 |
+
timeout: int | None = None,
|
| 94 |
+
) -> PipSession:
|
| 95 |
+
from pip._internal.network.session import PipSession
|
| 96 |
+
|
| 97 |
+
cache_dir = options.cache_dir
|
| 98 |
+
assert not cache_dir or os.path.isabs(cache_dir)
|
| 99 |
+
|
| 100 |
+
if "legacy-certs" not in options.deprecated_features_enabled:
|
| 101 |
+
ssl_context = _create_truststore_ssl_context()
|
| 102 |
+
else:
|
| 103 |
+
ssl_context = None
|
| 104 |
+
|
| 105 |
+
session = PipSession(
|
| 106 |
+
cache=os.path.join(cache_dir, "http-v2") if cache_dir else None,
|
| 107 |
+
retries=retries if retries is not None else options.retries,
|
| 108 |
+
resume_retries=options.resume_retries,
|
| 109 |
+
trusted_hosts=options.trusted_hosts,
|
| 110 |
+
index_urls=self._get_index_urls(options),
|
| 111 |
+
ssl_context=ssl_context,
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# Handle custom ca-bundles from the user
|
| 115 |
+
if options.cert:
|
| 116 |
+
session.verify = options.cert
|
| 117 |
+
|
| 118 |
+
# Handle SSL client certificate
|
| 119 |
+
if options.client_cert:
|
| 120 |
+
session.cert = options.client_cert
|
| 121 |
+
|
| 122 |
+
# Handle timeouts
|
| 123 |
+
if options.timeout or timeout:
|
| 124 |
+
session.timeout = timeout if timeout is not None else options.timeout
|
| 125 |
+
|
| 126 |
+
# Handle configured proxies
|
| 127 |
+
if options.proxy:
|
| 128 |
+
session.proxies = {
|
| 129 |
+
"http": options.proxy,
|
| 130 |
+
"https": options.proxy,
|
| 131 |
+
}
|
| 132 |
+
session.trust_env = False
|
| 133 |
+
session.pip_proxy = options.proxy
|
| 134 |
+
|
| 135 |
+
# Determine if we can prompt the user for authentication or not
|
| 136 |
+
session.auth.prompting = not options.no_input
|
| 137 |
+
session.auth.keyring_provider = options.keyring_provider
|
| 138 |
+
|
| 139 |
+
return session
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _pip_self_version_check(session: PipSession, options: Values) -> None:
|
| 143 |
+
from pip._internal.self_outdated_check import pip_self_version_check as check
|
| 144 |
+
|
| 145 |
+
check(session, options)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
class IndexGroupCommand(Command, SessionCommandMixin):
|
| 149 |
+
"""
|
| 150 |
+
Abstract base class for commands with the index_group options.
|
| 151 |
+
|
| 152 |
+
This also corresponds to the commands that permit the pip version check.
|
| 153 |
+
"""
|
| 154 |
+
|
| 155 |
+
def should_exclude_prerelease(
|
| 156 |
+
self, options: Values, package_name: NormalizedName
|
| 157 |
+
) -> bool:
|
| 158 |
+
"""
|
| 159 |
+
Determine if pre-releases should be excluded for a package.
|
| 160 |
+
"""
|
| 161 |
+
# Check per-package release control settings
|
| 162 |
+
if options.release_control:
|
| 163 |
+
allow_prereleases = options.release_control.allows_prereleases(package_name)
|
| 164 |
+
if allow_prereleases is True:
|
| 165 |
+
return False # Include pre-releases
|
| 166 |
+
elif allow_prereleases is False:
|
| 167 |
+
return True # Exclude pre-releases
|
| 168 |
+
|
| 169 |
+
# No specific setting: exclude prereleases by default
|
| 170 |
+
return True
|
| 171 |
+
|
| 172 |
+
def handle_pip_version_check(self, options: Values) -> None:
|
| 173 |
+
"""
|
| 174 |
+
Do the pip version check if not disabled.
|
| 175 |
+
|
| 176 |
+
This overrides the default behavior of not doing the check.
|
| 177 |
+
"""
|
| 178 |
+
# Make sure the index_group options are present.
|
| 179 |
+
assert hasattr(options, "no_index")
|
| 180 |
+
|
| 181 |
+
if options.disable_pip_version_check or options.no_index:
|
| 182 |
+
return
|
| 183 |
+
|
| 184 |
+
try:
|
| 185 |
+
# Otherwise, check if we're using the latest version of pip available.
|
| 186 |
+
session = self._build_session(
|
| 187 |
+
options,
|
| 188 |
+
retries=0,
|
| 189 |
+
timeout=min(5, options.timeout),
|
| 190 |
+
)
|
| 191 |
+
with session:
|
| 192 |
+
_pip_self_version_check(session, options)
|
| 193 |
+
except Exception:
|
| 194 |
+
logger.warning("There was an error checking the latest version of pip.")
|
| 195 |
+
logger.debug("See below for error", exc_info=True)
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/main.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Primary application entrypoint."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import locale
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
import warnings
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# Do not import and use main() directly! Using it directly is actively
|
| 15 |
+
# discouraged by pip's maintainers. The name, location and behavior of
|
| 16 |
+
# this function is subject to change, so calling it directly is not
|
| 17 |
+
# portable across different pip versions.
|
| 18 |
+
|
| 19 |
+
# In addition, running pip in-process is unsupported and unsafe. This is
|
| 20 |
+
# elaborated in detail at
|
| 21 |
+
# https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program.
|
| 22 |
+
# That document also provides suggestions that should work for nearly
|
| 23 |
+
# all users that are considering importing and using main() directly.
|
| 24 |
+
|
| 25 |
+
# However, we know that certain users will still want to invoke pip
|
| 26 |
+
# in-process. If you understand and accept the implications of using pip
|
| 27 |
+
# in an unsupported manner, the best approach is to use runpy to avoid
|
| 28 |
+
# depending on the exact location of this entry point.
|
| 29 |
+
|
| 30 |
+
# The following example shows how to use runpy to invoke pip in that
|
| 31 |
+
# case:
|
| 32 |
+
#
|
| 33 |
+
# sys.argv = ["pip", your, args, here]
|
| 34 |
+
# runpy.run_module("pip", run_name="__main__")
|
| 35 |
+
#
|
| 36 |
+
# Note that this will exit the process after running, unlike a direct
|
| 37 |
+
# call to main. As it is not safe to do any processing after calling
|
| 38 |
+
# main, this should not be an issue in practice.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def main(args: list[str] | None = None) -> int:
|
| 42 |
+
# NOTE: Lazy imports to speed up import of this module,
|
| 43 |
+
# which is imported from the pip console script. This doesn't
|
| 44 |
+
# speed up normal pip execution, but might be important in the future
|
| 45 |
+
# if we use ``multiprocessing`` module,
|
| 46 |
+
# which imports __main__ for each spawned subprocess.
|
| 47 |
+
from pip._internal.cli.autocompletion import autocomplete
|
| 48 |
+
from pip._internal.cli.main_parser import parse_command
|
| 49 |
+
from pip._internal.commands import create_command
|
| 50 |
+
from pip._internal.exceptions import PipError
|
| 51 |
+
from pip._internal.utils import deprecation
|
| 52 |
+
|
| 53 |
+
if args is None:
|
| 54 |
+
args = sys.argv[1:]
|
| 55 |
+
|
| 56 |
+
# Suppress the pkg_resources deprecation warning
|
| 57 |
+
# Note - we use a module of .*pkg_resources to cover
|
| 58 |
+
# the normal case (pip._vendor.pkg_resources) and the
|
| 59 |
+
# devendored case (a bare pkg_resources)
|
| 60 |
+
warnings.filterwarnings(
|
| 61 |
+
action="ignore", category=DeprecationWarning, module=".*pkg_resources"
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
# Configure our deprecation warnings to be sent through loggers
|
| 65 |
+
deprecation.install_warning_logger()
|
| 66 |
+
|
| 67 |
+
autocomplete()
|
| 68 |
+
|
| 69 |
+
try:
|
| 70 |
+
cmd_name, cmd_args = parse_command(args)
|
| 71 |
+
except PipError as exc:
|
| 72 |
+
sys.stderr.write(f"ERROR: {exc}")
|
| 73 |
+
sys.stderr.write(os.linesep)
|
| 74 |
+
sys.exit(1)
|
| 75 |
+
|
| 76 |
+
# Needed for locale.getpreferredencoding(False) to work
|
| 77 |
+
# in pip._internal.utils.encoding.auto_decode
|
| 78 |
+
try:
|
| 79 |
+
locale.setlocale(locale.LC_ALL, "")
|
| 80 |
+
except locale.Error as e:
|
| 81 |
+
# setlocale can apparently crash if locale are uninitialized
|
| 82 |
+
logger.debug("Ignoring error %s when setting locale", e)
|
| 83 |
+
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
|
| 84 |
+
|
| 85 |
+
return command.main(cmd_args)
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/main_parser.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A single place for constructing and exposing the main parser"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
|
| 9 |
+
from pip._vendor.rich.markup import escape
|
| 10 |
+
|
| 11 |
+
from pip._internal.build_env import get_runnable_pip
|
| 12 |
+
from pip._internal.cli import cmdoptions
|
| 13 |
+
from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
|
| 14 |
+
from pip._internal.commands import commands_dict, get_similar_commands
|
| 15 |
+
from pip._internal.exceptions import CommandError
|
| 16 |
+
from pip._internal.utils.misc import get_pip_version, get_prog
|
| 17 |
+
|
| 18 |
+
__all__ = ["create_main_parser", "parse_command"]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def create_main_parser() -> ConfigOptionParser:
|
| 22 |
+
"""Creates and returns the main parser for pip's CLI"""
|
| 23 |
+
|
| 24 |
+
parser = ConfigOptionParser(
|
| 25 |
+
usage="\n%prog <command> [options]",
|
| 26 |
+
add_help_option=False,
|
| 27 |
+
formatter=UpdatingDefaultsHelpFormatter(),
|
| 28 |
+
name="global",
|
| 29 |
+
prog=get_prog(),
|
| 30 |
+
)
|
| 31 |
+
parser.disable_interspersed_args()
|
| 32 |
+
|
| 33 |
+
parser.version = get_pip_version()
|
| 34 |
+
|
| 35 |
+
# add the general options
|
| 36 |
+
gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser)
|
| 37 |
+
parser.add_option_group(gen_opts)
|
| 38 |
+
|
| 39 |
+
# so the help formatter knows
|
| 40 |
+
parser.main = True # type: ignore
|
| 41 |
+
|
| 42 |
+
# create command listing for description
|
| 43 |
+
description = [""] + [
|
| 44 |
+
f"[optparse.longargs]{name:27}[/] {escape(command_info.summary)}"
|
| 45 |
+
for name, command_info in commands_dict.items()
|
| 46 |
+
]
|
| 47 |
+
parser.description = "\n".join(description)
|
| 48 |
+
|
| 49 |
+
return parser
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def identify_python_interpreter(python: str) -> str | None:
|
| 53 |
+
# If the named file exists, use it.
|
| 54 |
+
# If it's a directory, assume it's a virtual environment and
|
| 55 |
+
# look for the environment's Python executable.
|
| 56 |
+
if os.path.exists(python):
|
| 57 |
+
if os.path.isdir(python):
|
| 58 |
+
# bin/python for Unix, Scripts/python.exe for Windows
|
| 59 |
+
# Try both in case of odd cases like cygwin.
|
| 60 |
+
for exe in ("bin/python", "Scripts/python.exe"):
|
| 61 |
+
py = os.path.join(python, exe)
|
| 62 |
+
if os.path.exists(py):
|
| 63 |
+
return py
|
| 64 |
+
else:
|
| 65 |
+
return python
|
| 66 |
+
|
| 67 |
+
# Could not find the interpreter specified
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def parse_command(args: list[str]) -> tuple[str, list[str]]:
|
| 72 |
+
parser = create_main_parser()
|
| 73 |
+
|
| 74 |
+
# Note: parser calls disable_interspersed_args(), so the result of this
|
| 75 |
+
# call is to split the initial args into the general options before the
|
| 76 |
+
# subcommand and everything else.
|
| 77 |
+
# For example:
|
| 78 |
+
# args: ['--timeout=5', 'install', '--user', 'INITools']
|
| 79 |
+
# general_options: ['--timeout==5']
|
| 80 |
+
# args_else: ['install', '--user', 'INITools']
|
| 81 |
+
general_options, args_else = parser.parse_args(args)
|
| 82 |
+
|
| 83 |
+
# --python
|
| 84 |
+
if general_options.python and "_PIP_RUNNING_IN_SUBPROCESS" not in os.environ:
|
| 85 |
+
# Re-invoke pip using the specified Python interpreter
|
| 86 |
+
interpreter = identify_python_interpreter(general_options.python)
|
| 87 |
+
if interpreter is None:
|
| 88 |
+
raise CommandError(
|
| 89 |
+
f"Could not locate Python interpreter {general_options.python}"
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
pip_cmd = [
|
| 93 |
+
interpreter,
|
| 94 |
+
get_runnable_pip(),
|
| 95 |
+
]
|
| 96 |
+
pip_cmd.extend(args)
|
| 97 |
+
|
| 98 |
+
# Set a flag so the child doesn't re-invoke itself, causing
|
| 99 |
+
# an infinite loop.
|
| 100 |
+
os.environ["_PIP_RUNNING_IN_SUBPROCESS"] = "1"
|
| 101 |
+
returncode = 0
|
| 102 |
+
try:
|
| 103 |
+
proc = subprocess.run(pip_cmd)
|
| 104 |
+
returncode = proc.returncode
|
| 105 |
+
except (subprocess.SubprocessError, OSError) as exc:
|
| 106 |
+
raise CommandError(f"Failed to run pip under {interpreter}: {exc}")
|
| 107 |
+
sys.exit(returncode)
|
| 108 |
+
|
| 109 |
+
# --version
|
| 110 |
+
if general_options.version:
|
| 111 |
+
sys.stdout.write(parser.version)
|
| 112 |
+
sys.stdout.write(os.linesep)
|
| 113 |
+
sys.exit()
|
| 114 |
+
|
| 115 |
+
# pip || pip help -> print_help()
|
| 116 |
+
if not args_else or (args_else[0] == "help" and len(args_else) == 1):
|
| 117 |
+
parser.print_help()
|
| 118 |
+
sys.exit()
|
| 119 |
+
|
| 120 |
+
# the subcommand name
|
| 121 |
+
cmd_name = args_else[0]
|
| 122 |
+
|
| 123 |
+
if cmd_name not in commands_dict:
|
| 124 |
+
guess = get_similar_commands(cmd_name)
|
| 125 |
+
|
| 126 |
+
msg = [f'unknown command "{cmd_name}"']
|
| 127 |
+
if guess:
|
| 128 |
+
msg.append(f'maybe you meant "{guess}"')
|
| 129 |
+
|
| 130 |
+
raise CommandError(" - ".join(msg))
|
| 131 |
+
|
| 132 |
+
# all the args without the subcommand
|
| 133 |
+
cmd_args = args[:]
|
| 134 |
+
cmd_args.remove(cmd_name)
|
| 135 |
+
|
| 136 |
+
return cmd_name, cmd_args
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/parser.py
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Base option parser setup"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import optparse
|
| 7 |
+
import os
|
| 8 |
+
import re
|
| 9 |
+
import shutil
|
| 10 |
+
import sys
|
| 11 |
+
import textwrap
|
| 12 |
+
from collections.abc import Generator
|
| 13 |
+
from contextlib import suppress
|
| 14 |
+
from typing import Any, NoReturn
|
| 15 |
+
|
| 16 |
+
from pip._vendor.rich.markup import escape
|
| 17 |
+
from pip._vendor.rich.theme import Theme
|
| 18 |
+
|
| 19 |
+
from pip._internal.cli.status_codes import UNKNOWN_ERROR
|
| 20 |
+
from pip._internal.configuration import Configuration, ConfigurationError
|
| 21 |
+
from pip._internal.utils.logging import PipConsole
|
| 22 |
+
from pip._internal.utils.misc import redact_auth_from_url, strtobool
|
| 23 |
+
|
| 24 |
+
logger = logging.getLogger(__name__)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class PrettyHelpFormatter(optparse.IndentedHelpFormatter):
|
| 28 |
+
"""A prettier/less verbose help formatter for optparse."""
|
| 29 |
+
|
| 30 |
+
styles = {
|
| 31 |
+
"optparse.shortargs": "green",
|
| 32 |
+
"optparse.longargs": "cyan",
|
| 33 |
+
"optparse.groups": "bold blue",
|
| 34 |
+
"optparse.metavar": "yellow",
|
| 35 |
+
}
|
| 36 |
+
highlights = {
|
| 37 |
+
r"\s(-{1}[\w]+[\w-]*)": "shortargs", # highlight -letter as short args
|
| 38 |
+
r"\s(-{2}[\w]+[\w-]*)": "longargs", # highlight --words as long args
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
| 42 |
+
# help position must be aligned with __init__.parseopts.description
|
| 43 |
+
kwargs["max_help_position"] = 30
|
| 44 |
+
kwargs["indent_increment"] = 1
|
| 45 |
+
kwargs["width"] = shutil.get_terminal_size()[0] - 2
|
| 46 |
+
super().__init__(*args, **kwargs)
|
| 47 |
+
|
| 48 |
+
def format_option_strings(self, option: optparse.Option) -> str:
|
| 49 |
+
"""Return a comma-separated list of option strings and metavars."""
|
| 50 |
+
opts = []
|
| 51 |
+
|
| 52 |
+
if option._short_opts:
|
| 53 |
+
opts.append(f"[optparse.shortargs]{option._short_opts[0]}[/]")
|
| 54 |
+
if option._long_opts:
|
| 55 |
+
opts.append(f"[optparse.longargs]{option._long_opts[0]}[/]")
|
| 56 |
+
if len(opts) > 1:
|
| 57 |
+
opts.insert(1, ", ")
|
| 58 |
+
|
| 59 |
+
if option.takes_value():
|
| 60 |
+
assert option.dest is not None
|
| 61 |
+
metavar = option.metavar or option.dest.lower()
|
| 62 |
+
opts.append(f" [optparse.metavar]<{escape(metavar.lower())}>[/]")
|
| 63 |
+
|
| 64 |
+
return "".join(opts)
|
| 65 |
+
|
| 66 |
+
def format_option(self, option: optparse.Option) -> str:
|
| 67 |
+
"""Overridden method with Rich support."""
|
| 68 |
+
# fmt: off
|
| 69 |
+
result = []
|
| 70 |
+
opts = self.option_strings[option]
|
| 71 |
+
opt_width = self.help_position - self.current_indent - 2
|
| 72 |
+
# Remove the rich style tags before calculating width during
|
| 73 |
+
# text wrap calculations. Also store the length removed to adjust
|
| 74 |
+
# the padding in the else branch.
|
| 75 |
+
stripped = re.sub(r"(\[[a-z.]+\])|(\[\/\])", "", opts)
|
| 76 |
+
style_tag_length = len(opts) - len(stripped)
|
| 77 |
+
if len(stripped) > opt_width:
|
| 78 |
+
opts = "%*s%s\n" % (self.current_indent, "", opts) # noqa: UP031
|
| 79 |
+
indent_first = self.help_position
|
| 80 |
+
else: # start help on same line as opts
|
| 81 |
+
opts = "%*s%-*s " % (self.current_indent, "", # noqa: UP031
|
| 82 |
+
opt_width + style_tag_length, opts)
|
| 83 |
+
indent_first = 0
|
| 84 |
+
result.append(opts)
|
| 85 |
+
if option.help:
|
| 86 |
+
help_text = self.expand_default(option)
|
| 87 |
+
help_lines = textwrap.wrap(help_text, self.help_width)
|
| 88 |
+
result.append("%*s%s\n" % (indent_first, "", help_lines[0])) # noqa: UP031
|
| 89 |
+
result.extend(["%*s%s\n" % (self.help_position, "", line) # noqa: UP031
|
| 90 |
+
for line in help_lines[1:]])
|
| 91 |
+
elif opts[-1] != "\n":
|
| 92 |
+
result.append("\n")
|
| 93 |
+
return "".join(result)
|
| 94 |
+
# fmt: on
|
| 95 |
+
|
| 96 |
+
def format_heading(self, heading: str) -> str:
|
| 97 |
+
if heading == "Options":
|
| 98 |
+
return ""
|
| 99 |
+
return "[optparse.groups]" + escape(heading) + ":[/]\n"
|
| 100 |
+
|
| 101 |
+
def format_usage(self, usage: str) -> str:
|
| 102 |
+
"""
|
| 103 |
+
Ensure there is only one newline between usage and the first heading
|
| 104 |
+
if there is no description.
|
| 105 |
+
"""
|
| 106 |
+
contents = self.indent_lines(textwrap.dedent(usage), " ")
|
| 107 |
+
msg = f"\n[optparse.groups]Usage:[/] {escape(contents)}\n"
|
| 108 |
+
return msg
|
| 109 |
+
|
| 110 |
+
def format_description(self, description: str | None) -> str:
|
| 111 |
+
# leave full control over description to us
|
| 112 |
+
if description:
|
| 113 |
+
if hasattr(self.parser, "main"):
|
| 114 |
+
label = "[optparse.groups]Commands:[/]"
|
| 115 |
+
else:
|
| 116 |
+
label = "[optparse.groups]Description:[/]"
|
| 117 |
+
|
| 118 |
+
# some doc strings have initial newlines, some don't
|
| 119 |
+
description = description.lstrip("\n")
|
| 120 |
+
# some doc strings have final newlines and spaces, some don't
|
| 121 |
+
description = description.rstrip()
|
| 122 |
+
# dedent, then reindent
|
| 123 |
+
description = self.indent_lines(textwrap.dedent(description), " ")
|
| 124 |
+
description = f"{label}\n{description}\n"
|
| 125 |
+
return description
|
| 126 |
+
else:
|
| 127 |
+
return ""
|
| 128 |
+
|
| 129 |
+
def format_epilog(self, epilog: str | None) -> str:
|
| 130 |
+
# leave full control over epilog to us
|
| 131 |
+
if epilog:
|
| 132 |
+
return escape(epilog)
|
| 133 |
+
else:
|
| 134 |
+
return ""
|
| 135 |
+
|
| 136 |
+
def expand_default(self, option: optparse.Option) -> str:
|
| 137 |
+
"""Overridden HelpFormatter.expand_default() which colorizes flags."""
|
| 138 |
+
help = escape(super().expand_default(option))
|
| 139 |
+
for regex, style in self.highlights.items():
|
| 140 |
+
help = re.sub(regex, rf"[optparse.{style}] \1[/]", help)
|
| 141 |
+
return help
|
| 142 |
+
|
| 143 |
+
def indent_lines(self, text: str, indent: str) -> str:
|
| 144 |
+
new_lines = [indent + line for line in text.split("\n")]
|
| 145 |
+
return "\n".join(new_lines)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
|
| 149 |
+
"""Custom help formatter for use in ConfigOptionParser.
|
| 150 |
+
|
| 151 |
+
This is updates the defaults before expanding them, allowing
|
| 152 |
+
them to show up correctly in the help listing.
|
| 153 |
+
|
| 154 |
+
Also redact auth from url type options
|
| 155 |
+
"""
|
| 156 |
+
|
| 157 |
+
def expand_default(self, option: optparse.Option) -> str:
|
| 158 |
+
default_values = None
|
| 159 |
+
if self.parser is not None:
|
| 160 |
+
assert isinstance(self.parser, ConfigOptionParser)
|
| 161 |
+
self.parser._update_defaults(self.parser.defaults)
|
| 162 |
+
assert option.dest is not None
|
| 163 |
+
default_values = self.parser.defaults.get(option.dest)
|
| 164 |
+
help_text = super().expand_default(option)
|
| 165 |
+
|
| 166 |
+
if default_values and option.metavar == "URL":
|
| 167 |
+
if isinstance(default_values, str):
|
| 168 |
+
default_values = [default_values]
|
| 169 |
+
|
| 170 |
+
# If its not a list, we should abort and just return the help text
|
| 171 |
+
if not isinstance(default_values, list):
|
| 172 |
+
default_values = []
|
| 173 |
+
|
| 174 |
+
for val in default_values:
|
| 175 |
+
help_text = help_text.replace(val, redact_auth_from_url(val))
|
| 176 |
+
|
| 177 |
+
return help_text
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
class CustomOptionParser(optparse.OptionParser):
|
| 181 |
+
def insert_option_group(
|
| 182 |
+
self, idx: int, *args: Any, **kwargs: Any
|
| 183 |
+
) -> optparse.OptionGroup:
|
| 184 |
+
"""Insert an OptionGroup at a given position."""
|
| 185 |
+
group = self.add_option_group(*args, **kwargs)
|
| 186 |
+
|
| 187 |
+
self.option_groups.pop()
|
| 188 |
+
self.option_groups.insert(idx, group)
|
| 189 |
+
|
| 190 |
+
return group
|
| 191 |
+
|
| 192 |
+
@property
|
| 193 |
+
def option_list_all(self) -> list[optparse.Option]:
|
| 194 |
+
"""Get a list of all options, including those in option groups."""
|
| 195 |
+
res = self.option_list[:]
|
| 196 |
+
for i in self.option_groups:
|
| 197 |
+
res.extend(i.option_list)
|
| 198 |
+
|
| 199 |
+
return res
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
class ConfigOptionParser(CustomOptionParser):
|
| 203 |
+
"""Custom option parser which updates its defaults by checking the
|
| 204 |
+
configuration files and environmental variables"""
|
| 205 |
+
|
| 206 |
+
def __init__(
|
| 207 |
+
self,
|
| 208 |
+
*args: Any,
|
| 209 |
+
name: str,
|
| 210 |
+
isolated: bool = False,
|
| 211 |
+
**kwargs: Any,
|
| 212 |
+
) -> None:
|
| 213 |
+
self.name = name
|
| 214 |
+
self.config = Configuration(isolated)
|
| 215 |
+
|
| 216 |
+
assert self.name
|
| 217 |
+
super().__init__(*args, **kwargs)
|
| 218 |
+
|
| 219 |
+
def check_default(self, option: optparse.Option, key: str, val: Any) -> Any:
|
| 220 |
+
try:
|
| 221 |
+
return option.check_value(key, val)
|
| 222 |
+
except optparse.OptionValueError as exc:
|
| 223 |
+
print(f"An error occurred during configuration: {exc}")
|
| 224 |
+
sys.exit(3)
|
| 225 |
+
|
| 226 |
+
def _get_ordered_configuration_items(
|
| 227 |
+
self,
|
| 228 |
+
) -> Generator[tuple[str, Any], None, None]:
|
| 229 |
+
# Configuration gives keys in an unordered manner. Order them.
|
| 230 |
+
override_order = ["global", self.name, ":env:"]
|
| 231 |
+
|
| 232 |
+
# Pool the options into different groups
|
| 233 |
+
# Use a dict because we need to implement the fallthrough logic after PR 12201
|
| 234 |
+
# was merged which removed the fallthrough logic for options
|
| 235 |
+
section_items_dict: dict[str, dict[str, Any]] = {
|
| 236 |
+
name: {} for name in override_order
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
for _, value in self.config.items():
|
| 240 |
+
for section_key, val in value.items():
|
| 241 |
+
|
| 242 |
+
section, key = section_key.split(".", 1)
|
| 243 |
+
if section in override_order:
|
| 244 |
+
section_items_dict[section][key] = val
|
| 245 |
+
|
| 246 |
+
# Now that we a dict of items per section, convert to list of tuples
|
| 247 |
+
# Make sure we completely remove empty values again
|
| 248 |
+
section_items = {
|
| 249 |
+
name: [(k, v) for k, v in section_items_dict[name].items() if v]
|
| 250 |
+
for name in override_order
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
# Yield each group in their override order
|
| 254 |
+
for section in override_order:
|
| 255 |
+
yield from section_items[section]
|
| 256 |
+
|
| 257 |
+
def _update_defaults(self, defaults: dict[str, Any]) -> dict[str, Any]:
|
| 258 |
+
"""Updates the given defaults with values from the config files and
|
| 259 |
+
the environ. Does a little special handling for certain types of
|
| 260 |
+
options (lists)."""
|
| 261 |
+
|
| 262 |
+
# Accumulate complex default state.
|
| 263 |
+
self.values = optparse.Values(self.defaults)
|
| 264 |
+
late_eval = set()
|
| 265 |
+
# Then set the options with those values
|
| 266 |
+
for key, val in self._get_ordered_configuration_items():
|
| 267 |
+
# '--' because configuration supports only long names
|
| 268 |
+
option = self.get_option("--" + key)
|
| 269 |
+
|
| 270 |
+
# Ignore options not present in this parser. E.g. non-globals put
|
| 271 |
+
# in [global] by users that want them to apply to all applicable
|
| 272 |
+
# commands.
|
| 273 |
+
if option is None:
|
| 274 |
+
continue
|
| 275 |
+
|
| 276 |
+
assert option.dest is not None
|
| 277 |
+
|
| 278 |
+
if option.action in ("store_true", "store_false"):
|
| 279 |
+
try:
|
| 280 |
+
val = strtobool(val)
|
| 281 |
+
except ValueError:
|
| 282 |
+
self.error(
|
| 283 |
+
f"{val} is not a valid value for {key} option, "
|
| 284 |
+
"please specify a boolean value like yes/no, "
|
| 285 |
+
"true/false or 1/0 instead."
|
| 286 |
+
)
|
| 287 |
+
elif option.action == "count":
|
| 288 |
+
with suppress(ValueError):
|
| 289 |
+
val = strtobool(val)
|
| 290 |
+
with suppress(ValueError):
|
| 291 |
+
val = int(val)
|
| 292 |
+
if not isinstance(val, int) or val < 0:
|
| 293 |
+
self.error(
|
| 294 |
+
f"{val} is not a valid value for {key} option, "
|
| 295 |
+
"please instead specify either a non-negative integer "
|
| 296 |
+
"or a boolean value like yes/no or false/true "
|
| 297 |
+
"which is equivalent to 1/0."
|
| 298 |
+
)
|
| 299 |
+
elif option.action == "append":
|
| 300 |
+
val = val.split()
|
| 301 |
+
val = [self.check_default(option, key, v) for v in val]
|
| 302 |
+
elif option.action == "callback":
|
| 303 |
+
assert option.callback is not None
|
| 304 |
+
late_eval.add(option.dest)
|
| 305 |
+
opt_str = option.get_opt_string()
|
| 306 |
+
val = option.convert_value(opt_str, val)
|
| 307 |
+
# From take_action
|
| 308 |
+
args = option.callback_args or ()
|
| 309 |
+
kwargs = option.callback_kwargs or {}
|
| 310 |
+
option.callback(option, opt_str, val, self, *args, **kwargs)
|
| 311 |
+
else:
|
| 312 |
+
val = self.check_default(option, key, val)
|
| 313 |
+
|
| 314 |
+
defaults[option.dest] = val
|
| 315 |
+
|
| 316 |
+
for key in late_eval:
|
| 317 |
+
defaults[key] = getattr(self.values, key)
|
| 318 |
+
self.values = None
|
| 319 |
+
return defaults
|
| 320 |
+
|
| 321 |
+
def get_default_values(self) -> optparse.Values:
|
| 322 |
+
"""Overriding to make updating the defaults after instantiation of
|
| 323 |
+
the option parser possible, _update_defaults() does the dirty work."""
|
| 324 |
+
if not self.process_default_values:
|
| 325 |
+
# Old, pre-Optik 1.5 behaviour.
|
| 326 |
+
return optparse.Values(self.defaults)
|
| 327 |
+
|
| 328 |
+
# Load the configuration, or error out in case of an error
|
| 329 |
+
try:
|
| 330 |
+
self.config.load()
|
| 331 |
+
except ConfigurationError as err:
|
| 332 |
+
self.exit(UNKNOWN_ERROR, str(err))
|
| 333 |
+
|
| 334 |
+
defaults = self._update_defaults(self.defaults.copy()) # ours
|
| 335 |
+
for option in self._get_all_options():
|
| 336 |
+
assert option.dest is not None
|
| 337 |
+
default = defaults.get(option.dest)
|
| 338 |
+
if isinstance(default, str):
|
| 339 |
+
opt_str = option.get_opt_string()
|
| 340 |
+
defaults[option.dest] = option.check_value(opt_str, default)
|
| 341 |
+
return optparse.Values(defaults)
|
| 342 |
+
|
| 343 |
+
def error(self, msg: str) -> NoReturn:
|
| 344 |
+
self.print_usage(sys.stderr)
|
| 345 |
+
self.exit(UNKNOWN_ERROR, f"{msg}\n")
|
| 346 |
+
|
| 347 |
+
def print_help(self, file: Any = None) -> None:
|
| 348 |
+
# This is unfortunate but necessary since arguments may have not been
|
| 349 |
+
# parsed yet at this point, so detect --no-color manually.
|
| 350 |
+
no_color = (
|
| 351 |
+
"--no-color" in sys.argv
|
| 352 |
+
or bool(strtobool(os.environ.get("PIP_NO_COLOR", "no") or "no"))
|
| 353 |
+
or "NO_COLOR" in os.environ
|
| 354 |
+
)
|
| 355 |
+
console = PipConsole(
|
| 356 |
+
theme=Theme(PrettyHelpFormatter.styles), no_color=no_color, file=file
|
| 357 |
+
)
|
| 358 |
+
console.print(self.format_help().rstrip(), highlight=False)
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/progress_bars.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import functools
|
| 4 |
+
import sys
|
| 5 |
+
from collections.abc import Generator, Iterable, Iterator
|
| 6 |
+
from typing import TYPE_CHECKING, Callable, Literal, TypeVar
|
| 7 |
+
|
| 8 |
+
from pip._vendor.rich.progress import (
|
| 9 |
+
BarColumn,
|
| 10 |
+
DownloadColumn,
|
| 11 |
+
FileSizeColumn,
|
| 12 |
+
MofNCompleteColumn,
|
| 13 |
+
Progress,
|
| 14 |
+
ProgressColumn,
|
| 15 |
+
SpinnerColumn,
|
| 16 |
+
TextColumn,
|
| 17 |
+
TimeElapsedColumn,
|
| 18 |
+
TimeRemainingColumn,
|
| 19 |
+
TransferSpeedColumn,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
from pip._internal.cli.spinners import RateLimiter
|
| 23 |
+
from pip._internal.utils.logging import get_console, get_indentation
|
| 24 |
+
|
| 25 |
+
if TYPE_CHECKING:
|
| 26 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 27 |
+
|
| 28 |
+
T = TypeVar("T")
|
| 29 |
+
ProgressRenderer = Callable[[Iterable[T]], Iterator[T]]
|
| 30 |
+
BarType = Literal["on", "off", "raw"]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _rich_download_progress_bar(
|
| 34 |
+
iterable: Iterable[bytes],
|
| 35 |
+
*,
|
| 36 |
+
bar_type: BarType,
|
| 37 |
+
size: int | None,
|
| 38 |
+
initial_progress: int | None = None,
|
| 39 |
+
) -> Generator[bytes, None, None]:
|
| 40 |
+
assert bar_type == "on", "This should only be used in the default mode."
|
| 41 |
+
|
| 42 |
+
if not size:
|
| 43 |
+
total = float("inf")
|
| 44 |
+
columns: tuple[ProgressColumn, ...] = (
|
| 45 |
+
TextColumn("[progress.description]{task.description}"),
|
| 46 |
+
SpinnerColumn("line", speed=1.5),
|
| 47 |
+
FileSizeColumn(),
|
| 48 |
+
TransferSpeedColumn(),
|
| 49 |
+
TimeElapsedColumn(),
|
| 50 |
+
)
|
| 51 |
+
else:
|
| 52 |
+
total = size
|
| 53 |
+
columns = (
|
| 54 |
+
TextColumn("[progress.description]{task.description}"),
|
| 55 |
+
BarColumn(),
|
| 56 |
+
DownloadColumn(),
|
| 57 |
+
TransferSpeedColumn(),
|
| 58 |
+
TextColumn("{task.fields[time_description]}"),
|
| 59 |
+
TimeRemainingColumn(elapsed_when_finished=True),
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
progress = Progress(*columns, refresh_per_second=5)
|
| 63 |
+
task_id = progress.add_task(
|
| 64 |
+
" " * (get_indentation() + 2), total=total, time_description="eta"
|
| 65 |
+
)
|
| 66 |
+
if initial_progress is not None:
|
| 67 |
+
progress.update(task_id, advance=initial_progress)
|
| 68 |
+
with progress:
|
| 69 |
+
for chunk in iterable:
|
| 70 |
+
yield chunk
|
| 71 |
+
progress.update(task_id, advance=len(chunk))
|
| 72 |
+
progress.update(task_id, time_description="")
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _rich_install_progress_bar(
|
| 76 |
+
iterable: Iterable[InstallRequirement], *, total: int
|
| 77 |
+
) -> Iterator[InstallRequirement]:
|
| 78 |
+
columns = (
|
| 79 |
+
TextColumn("{task.fields[indent]}"),
|
| 80 |
+
BarColumn(),
|
| 81 |
+
MofNCompleteColumn(),
|
| 82 |
+
TextColumn("{task.description}"),
|
| 83 |
+
)
|
| 84 |
+
console = get_console()
|
| 85 |
+
|
| 86 |
+
bar = Progress(*columns, refresh_per_second=6, console=console, transient=True)
|
| 87 |
+
# Hiding the progress bar at initialization forces a refresh cycle to occur
|
| 88 |
+
# until the bar appears, avoiding very short flashes.
|
| 89 |
+
task = bar.add_task("", total=total, indent=" " * get_indentation(), visible=False)
|
| 90 |
+
with bar:
|
| 91 |
+
for req in iterable:
|
| 92 |
+
bar.update(task, description=rf"\[{req.name}]", visible=True)
|
| 93 |
+
yield req
|
| 94 |
+
bar.advance(task)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def _raw_progress_bar(
|
| 98 |
+
iterable: Iterable[bytes],
|
| 99 |
+
*,
|
| 100 |
+
size: int | None,
|
| 101 |
+
initial_progress: int | None = None,
|
| 102 |
+
) -> Generator[bytes, None, None]:
|
| 103 |
+
def write_progress(current: int, total: int) -> None:
|
| 104 |
+
sys.stdout.write(f"Progress {current} of {total}\n")
|
| 105 |
+
sys.stdout.flush()
|
| 106 |
+
|
| 107 |
+
current = initial_progress or 0
|
| 108 |
+
total = size or 0
|
| 109 |
+
rate_limiter = RateLimiter(0.25)
|
| 110 |
+
|
| 111 |
+
write_progress(current, total)
|
| 112 |
+
for chunk in iterable:
|
| 113 |
+
current += len(chunk)
|
| 114 |
+
if rate_limiter.ready() or current == total:
|
| 115 |
+
write_progress(current, total)
|
| 116 |
+
rate_limiter.reset()
|
| 117 |
+
yield chunk
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def get_download_progress_renderer(
|
| 121 |
+
*, bar_type: BarType, size: int | None = None, initial_progress: int | None = None
|
| 122 |
+
) -> ProgressRenderer[bytes]:
|
| 123 |
+
"""Get an object that can be used to render the download progress.
|
| 124 |
+
|
| 125 |
+
Returns a callable, that takes an iterable to "wrap".
|
| 126 |
+
"""
|
| 127 |
+
if bar_type == "on":
|
| 128 |
+
return functools.partial(
|
| 129 |
+
_rich_download_progress_bar,
|
| 130 |
+
bar_type=bar_type,
|
| 131 |
+
size=size,
|
| 132 |
+
initial_progress=initial_progress,
|
| 133 |
+
)
|
| 134 |
+
elif bar_type == "raw":
|
| 135 |
+
return functools.partial(
|
| 136 |
+
_raw_progress_bar,
|
| 137 |
+
size=size,
|
| 138 |
+
initial_progress=initial_progress,
|
| 139 |
+
)
|
| 140 |
+
else:
|
| 141 |
+
return iter # no-op, when passed an iterator
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def get_install_progress_renderer(
|
| 145 |
+
*, bar_type: BarType, total: int
|
| 146 |
+
) -> ProgressRenderer[InstallRequirement]:
|
| 147 |
+
"""Get an object that can be used to render the install progress.
|
| 148 |
+
Returns a callable, that takes an iterable to "wrap".
|
| 149 |
+
"""
|
| 150 |
+
if bar_type == "on":
|
| 151 |
+
return functools.partial(_rich_install_progress_bar, total=total)
|
| 152 |
+
else:
|
| 153 |
+
return iter
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/req_command.py
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Contains the RequirementCommand base class.
|
| 2 |
+
|
| 3 |
+
This class is in a separate module so the commands that do not always
|
| 4 |
+
need PackageFinder capability don't unnecessarily import the
|
| 5 |
+
PackageFinder machinery and all its vendored dependencies, etc.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import logging
|
| 11 |
+
import os
|
| 12 |
+
from functools import partial
|
| 13 |
+
from optparse import Values
|
| 14 |
+
from typing import Any, Callable, TypeVar
|
| 15 |
+
|
| 16 |
+
from pip._internal.build_env import (
|
| 17 |
+
BuildEnvironmentInstaller,
|
| 18 |
+
InprocessBuildEnvironmentInstaller,
|
| 19 |
+
SubprocessBuildEnvironmentInstaller,
|
| 20 |
+
)
|
| 21 |
+
from pip._internal.cache import WheelCache
|
| 22 |
+
from pip._internal.cli import cmdoptions
|
| 23 |
+
from pip._internal.cli.cmdoptions import make_target_python
|
| 24 |
+
from pip._internal.cli.index_command import IndexGroupCommand
|
| 25 |
+
from pip._internal.cli.index_command import SessionCommandMixin as SessionCommandMixin
|
| 26 |
+
from pip._internal.exceptions import (
|
| 27 |
+
CommandError,
|
| 28 |
+
PreviousBuildDirError,
|
| 29 |
+
UnsupportedPythonVersion,
|
| 30 |
+
)
|
| 31 |
+
from pip._internal.index.collector import LinkCollector
|
| 32 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 33 |
+
from pip._internal.models.selection_prefs import SelectionPreferences
|
| 34 |
+
from pip._internal.models.target_python import TargetPython
|
| 35 |
+
from pip._internal.network.session import PipSession
|
| 36 |
+
from pip._internal.operations.build.build_tracker import BuildTracker
|
| 37 |
+
from pip._internal.operations.prepare import RequirementPreparer
|
| 38 |
+
from pip._internal.req.constructors import (
|
| 39 |
+
install_req_from_editable,
|
| 40 |
+
install_req_from_line,
|
| 41 |
+
install_req_from_parsed_requirement,
|
| 42 |
+
install_req_from_req_string,
|
| 43 |
+
)
|
| 44 |
+
from pip._internal.req.pep723 import PEP723Exception, pep723_metadata
|
| 45 |
+
from pip._internal.req.req_dependency_group import parse_dependency_groups
|
| 46 |
+
from pip._internal.req.req_file import parse_requirements
|
| 47 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 48 |
+
from pip._internal.resolution.base import BaseResolver
|
| 49 |
+
from pip._internal.utils.packaging import check_requires_python
|
| 50 |
+
from pip._internal.utils.temp_dir import (
|
| 51 |
+
TempDirectory,
|
| 52 |
+
TempDirectoryTypeRegistry,
|
| 53 |
+
tempdir_kinds,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
logger = logging.getLogger(__name__)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def should_ignore_regular_constraints(options: Values) -> bool:
|
| 60 |
+
"""
|
| 61 |
+
Check if regular constraints should be ignored because
|
| 62 |
+
we are in a isolated build process and build constraints
|
| 63 |
+
feature is enabled but no build constraints were passed.
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
return os.environ.get("_PIP_IN_BUILD_IGNORE_CONSTRAINTS") == "1"
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
KEEPABLE_TEMPDIR_TYPES = [
|
| 70 |
+
tempdir_kinds.BUILD_ENV,
|
| 71 |
+
tempdir_kinds.EPHEM_WHEEL_CACHE,
|
| 72 |
+
tempdir_kinds.REQ_BUILD,
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
_CommandT = TypeVar("_CommandT", bound="RequirementCommand")
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def with_cleanup(
|
| 80 |
+
func: Callable[[_CommandT, Values, list[str]], int],
|
| 81 |
+
) -> Callable[[_CommandT, Values, list[str]], int]:
|
| 82 |
+
"""Decorator for common logic related to managing temporary
|
| 83 |
+
directories.
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
def configure_tempdir_registry(registry: TempDirectoryTypeRegistry) -> None:
|
| 87 |
+
for t in KEEPABLE_TEMPDIR_TYPES:
|
| 88 |
+
registry.set_delete(t, False)
|
| 89 |
+
|
| 90 |
+
def wrapper(self: _CommandT, options: Values, args: list[str]) -> int:
|
| 91 |
+
assert self.tempdir_registry is not None
|
| 92 |
+
if options.no_clean:
|
| 93 |
+
configure_tempdir_registry(self.tempdir_registry)
|
| 94 |
+
|
| 95 |
+
try:
|
| 96 |
+
return func(self, options, args)
|
| 97 |
+
except PreviousBuildDirError:
|
| 98 |
+
# This kind of conflict can occur when the user passes an explicit
|
| 99 |
+
# build directory with a pre-existing folder. In that case we do
|
| 100 |
+
# not want to accidentally remove it.
|
| 101 |
+
configure_tempdir_registry(self.tempdir_registry)
|
| 102 |
+
raise
|
| 103 |
+
|
| 104 |
+
return wrapper
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def parse_constraint_files(
|
| 108 |
+
constraint_files: list[str],
|
| 109 |
+
finder: PackageFinder,
|
| 110 |
+
options: Values,
|
| 111 |
+
session: PipSession,
|
| 112 |
+
) -> list[InstallRequirement]:
|
| 113 |
+
requirements = []
|
| 114 |
+
for filename in constraint_files:
|
| 115 |
+
for parsed_req in parse_requirements(
|
| 116 |
+
filename,
|
| 117 |
+
constraint=True,
|
| 118 |
+
finder=finder,
|
| 119 |
+
options=options,
|
| 120 |
+
session=session,
|
| 121 |
+
):
|
| 122 |
+
req_to_add = install_req_from_parsed_requirement(
|
| 123 |
+
parsed_req,
|
| 124 |
+
isolated=options.isolated_mode,
|
| 125 |
+
user_supplied=False,
|
| 126 |
+
)
|
| 127 |
+
requirements.append(req_to_add)
|
| 128 |
+
|
| 129 |
+
return requirements
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class RequirementCommand(IndexGroupCommand):
|
| 133 |
+
def __init__(self, *args: Any, **kw: Any) -> None:
|
| 134 |
+
super().__init__(*args, **kw)
|
| 135 |
+
|
| 136 |
+
self.cmd_opts.add_option(cmdoptions.dependency_groups())
|
| 137 |
+
self.cmd_opts.add_option(cmdoptions.no_clean())
|
| 138 |
+
|
| 139 |
+
@staticmethod
|
| 140 |
+
def determine_resolver_variant(options: Values) -> str:
|
| 141 |
+
"""Determines which resolver should be used, based on the given options."""
|
| 142 |
+
if "legacy-resolver" in options.deprecated_features_enabled:
|
| 143 |
+
return "legacy"
|
| 144 |
+
|
| 145 |
+
return "resolvelib"
|
| 146 |
+
|
| 147 |
+
@classmethod
|
| 148 |
+
def make_requirement_preparer(
|
| 149 |
+
cls,
|
| 150 |
+
temp_build_dir: TempDirectory,
|
| 151 |
+
options: Values,
|
| 152 |
+
build_tracker: BuildTracker,
|
| 153 |
+
session: PipSession,
|
| 154 |
+
finder: PackageFinder,
|
| 155 |
+
use_user_site: bool,
|
| 156 |
+
download_dir: str | None = None,
|
| 157 |
+
verbosity: int = 0,
|
| 158 |
+
) -> RequirementPreparer:
|
| 159 |
+
"""
|
| 160 |
+
Create a RequirementPreparer instance for the given parameters.
|
| 161 |
+
"""
|
| 162 |
+
temp_build_dir_path = temp_build_dir.path
|
| 163 |
+
assert temp_build_dir_path is not None
|
| 164 |
+
legacy_resolver = False
|
| 165 |
+
|
| 166 |
+
resolver_variant = cls.determine_resolver_variant(options)
|
| 167 |
+
if resolver_variant == "resolvelib":
|
| 168 |
+
lazy_wheel = "fast-deps" in options.features_enabled
|
| 169 |
+
if lazy_wheel:
|
| 170 |
+
logger.warning(
|
| 171 |
+
"pip is using lazily downloaded wheels using HTTP "
|
| 172 |
+
"range requests to obtain dependency information. "
|
| 173 |
+
"This experimental feature is enabled through "
|
| 174 |
+
"--use-feature=fast-deps and it is not ready for "
|
| 175 |
+
"production."
|
| 176 |
+
)
|
| 177 |
+
else:
|
| 178 |
+
legacy_resolver = True
|
| 179 |
+
lazy_wheel = False
|
| 180 |
+
if "fast-deps" in options.features_enabled:
|
| 181 |
+
logger.warning(
|
| 182 |
+
"fast-deps has no effect when used with the legacy resolver."
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
# Handle build constraints
|
| 186 |
+
build_constraints = getattr(options, "build_constraints", [])
|
| 187 |
+
build_constraint_feature_enabled = (
|
| 188 |
+
"build-constraint" in options.features_enabled
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
env_installer: BuildEnvironmentInstaller
|
| 192 |
+
if "inprocess-build-deps" in options.features_enabled:
|
| 193 |
+
build_constraint_reqs = parse_constraint_files(
|
| 194 |
+
build_constraints, finder, options, session
|
| 195 |
+
)
|
| 196 |
+
env_installer = InprocessBuildEnvironmentInstaller(
|
| 197 |
+
finder=finder,
|
| 198 |
+
build_tracker=build_tracker,
|
| 199 |
+
build_constraints=build_constraint_reqs,
|
| 200 |
+
verbosity=verbosity,
|
| 201 |
+
wheel_cache=WheelCache(options.cache_dir),
|
| 202 |
+
)
|
| 203 |
+
else:
|
| 204 |
+
env_installer = SubprocessBuildEnvironmentInstaller(
|
| 205 |
+
finder,
|
| 206 |
+
build_constraints=build_constraints,
|
| 207 |
+
build_constraint_feature_enabled=build_constraint_feature_enabled,
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
return RequirementPreparer(
|
| 211 |
+
build_dir=temp_build_dir_path,
|
| 212 |
+
src_dir=options.src_dir,
|
| 213 |
+
download_dir=download_dir,
|
| 214 |
+
build_isolation=options.build_isolation,
|
| 215 |
+
build_isolation_installer=env_installer,
|
| 216 |
+
check_build_deps=options.check_build_deps,
|
| 217 |
+
build_tracker=build_tracker,
|
| 218 |
+
session=session,
|
| 219 |
+
progress_bar=options.progress_bar,
|
| 220 |
+
finder=finder,
|
| 221 |
+
require_hashes=options.require_hashes,
|
| 222 |
+
use_user_site=use_user_site,
|
| 223 |
+
lazy_wheel=lazy_wheel,
|
| 224 |
+
verbosity=verbosity,
|
| 225 |
+
legacy_resolver=legacy_resolver,
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
@classmethod
|
| 229 |
+
def make_resolver(
|
| 230 |
+
cls,
|
| 231 |
+
preparer: RequirementPreparer,
|
| 232 |
+
finder: PackageFinder,
|
| 233 |
+
options: Values,
|
| 234 |
+
wheel_cache: WheelCache | None = None,
|
| 235 |
+
use_user_site: bool = False,
|
| 236 |
+
ignore_installed: bool = True,
|
| 237 |
+
ignore_requires_python: bool = False,
|
| 238 |
+
force_reinstall: bool = False,
|
| 239 |
+
upgrade_strategy: str = "to-satisfy-only",
|
| 240 |
+
py_version_info: tuple[int, ...] | None = None,
|
| 241 |
+
) -> BaseResolver:
|
| 242 |
+
"""
|
| 243 |
+
Create a Resolver instance for the given parameters.
|
| 244 |
+
"""
|
| 245 |
+
make_install_req = partial(
|
| 246 |
+
install_req_from_req_string,
|
| 247 |
+
isolated=options.isolated_mode,
|
| 248 |
+
)
|
| 249 |
+
resolver_variant = cls.determine_resolver_variant(options)
|
| 250 |
+
# The long import name and duplicated invocation is needed to convince
|
| 251 |
+
# Mypy into correctly typechecking. Otherwise it would complain the
|
| 252 |
+
# "Resolver" class being redefined.
|
| 253 |
+
if resolver_variant == "resolvelib":
|
| 254 |
+
import pip._internal.resolution.resolvelib.resolver
|
| 255 |
+
|
| 256 |
+
return pip._internal.resolution.resolvelib.resolver.Resolver(
|
| 257 |
+
preparer=preparer,
|
| 258 |
+
finder=finder,
|
| 259 |
+
wheel_cache=wheel_cache,
|
| 260 |
+
make_install_req=make_install_req,
|
| 261 |
+
use_user_site=use_user_site,
|
| 262 |
+
ignore_dependencies=options.ignore_dependencies,
|
| 263 |
+
ignore_installed=ignore_installed,
|
| 264 |
+
ignore_requires_python=ignore_requires_python,
|
| 265 |
+
force_reinstall=force_reinstall,
|
| 266 |
+
upgrade_strategy=upgrade_strategy,
|
| 267 |
+
py_version_info=py_version_info,
|
| 268 |
+
)
|
| 269 |
+
import pip._internal.resolution.legacy.resolver
|
| 270 |
+
|
| 271 |
+
return pip._internal.resolution.legacy.resolver.Resolver(
|
| 272 |
+
preparer=preparer,
|
| 273 |
+
finder=finder,
|
| 274 |
+
wheel_cache=wheel_cache,
|
| 275 |
+
make_install_req=make_install_req,
|
| 276 |
+
use_user_site=use_user_site,
|
| 277 |
+
ignore_dependencies=options.ignore_dependencies,
|
| 278 |
+
ignore_installed=ignore_installed,
|
| 279 |
+
ignore_requires_python=ignore_requires_python,
|
| 280 |
+
force_reinstall=force_reinstall,
|
| 281 |
+
upgrade_strategy=upgrade_strategy,
|
| 282 |
+
py_version_info=py_version_info,
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
def get_requirements(
|
| 286 |
+
self,
|
| 287 |
+
args: list[str],
|
| 288 |
+
options: Values,
|
| 289 |
+
finder: PackageFinder,
|
| 290 |
+
session: PipSession,
|
| 291 |
+
) -> list[InstallRequirement]:
|
| 292 |
+
"""
|
| 293 |
+
Parse command-line arguments into the corresponding requirements.
|
| 294 |
+
"""
|
| 295 |
+
requirements: list[InstallRequirement] = []
|
| 296 |
+
|
| 297 |
+
if not should_ignore_regular_constraints(options):
|
| 298 |
+
constraints = parse_constraint_files(
|
| 299 |
+
options.constraints, finder, options, session
|
| 300 |
+
)
|
| 301 |
+
requirements.extend(constraints)
|
| 302 |
+
|
| 303 |
+
for req in args:
|
| 304 |
+
if not req.strip():
|
| 305 |
+
continue
|
| 306 |
+
req_to_add = install_req_from_line(
|
| 307 |
+
req,
|
| 308 |
+
comes_from=None,
|
| 309 |
+
isolated=options.isolated_mode,
|
| 310 |
+
user_supplied=True,
|
| 311 |
+
config_settings=getattr(options, "config_settings", None),
|
| 312 |
+
)
|
| 313 |
+
requirements.append(req_to_add)
|
| 314 |
+
|
| 315 |
+
if options.dependency_groups:
|
| 316 |
+
for req in parse_dependency_groups(options.dependency_groups):
|
| 317 |
+
req_to_add = install_req_from_req_string(
|
| 318 |
+
req,
|
| 319 |
+
isolated=options.isolated_mode,
|
| 320 |
+
user_supplied=True,
|
| 321 |
+
)
|
| 322 |
+
requirements.append(req_to_add)
|
| 323 |
+
|
| 324 |
+
for req in options.editables:
|
| 325 |
+
req_to_add = install_req_from_editable(
|
| 326 |
+
req,
|
| 327 |
+
user_supplied=True,
|
| 328 |
+
isolated=options.isolated_mode,
|
| 329 |
+
config_settings=getattr(options, "config_settings", None),
|
| 330 |
+
)
|
| 331 |
+
requirements.append(req_to_add)
|
| 332 |
+
|
| 333 |
+
# NOTE: options.require_hashes may be set if --require-hashes is True
|
| 334 |
+
for filename in options.requirements:
|
| 335 |
+
for parsed_req in parse_requirements(
|
| 336 |
+
filename, finder=finder, options=options, session=session
|
| 337 |
+
):
|
| 338 |
+
req_to_add = install_req_from_parsed_requirement(
|
| 339 |
+
parsed_req,
|
| 340 |
+
isolated=options.isolated_mode,
|
| 341 |
+
user_supplied=True,
|
| 342 |
+
config_settings=(
|
| 343 |
+
parsed_req.options.get("config_settings")
|
| 344 |
+
if parsed_req.options
|
| 345 |
+
else None
|
| 346 |
+
),
|
| 347 |
+
)
|
| 348 |
+
requirements.append(req_to_add)
|
| 349 |
+
|
| 350 |
+
if options.requirements_from_scripts:
|
| 351 |
+
if len(options.requirements_from_scripts) > 1:
|
| 352 |
+
raise CommandError("--requirements-from-script can only be given once")
|
| 353 |
+
|
| 354 |
+
script = options.requirements_from_scripts[0]
|
| 355 |
+
try:
|
| 356 |
+
script_metadata = pep723_metadata(script)
|
| 357 |
+
except PEP723Exception as exc:
|
| 358 |
+
raise CommandError(exc.msg)
|
| 359 |
+
|
| 360 |
+
script_requires_python = script_metadata.get("requires-python", "")
|
| 361 |
+
|
| 362 |
+
if script_requires_python and not options.ignore_requires_python:
|
| 363 |
+
target_python = make_target_python(options)
|
| 364 |
+
|
| 365 |
+
if not check_requires_python(
|
| 366 |
+
requires_python=script_requires_python,
|
| 367 |
+
version_info=target_python.py_version_info,
|
| 368 |
+
):
|
| 369 |
+
raise UnsupportedPythonVersion(
|
| 370 |
+
f"Script {script!r} requires a different Python: "
|
| 371 |
+
f"{target_python.py_version} not in {script_requires_python!r}"
|
| 372 |
+
)
|
| 373 |
+
|
| 374 |
+
for req in script_metadata.get("dependencies", []):
|
| 375 |
+
req_to_add = install_req_from_req_string(
|
| 376 |
+
req,
|
| 377 |
+
isolated=options.isolated_mode,
|
| 378 |
+
user_supplied=True,
|
| 379 |
+
)
|
| 380 |
+
requirements.append(req_to_add)
|
| 381 |
+
|
| 382 |
+
# If any requirement has hash options, enable hash checking.
|
| 383 |
+
if any(req.has_hash_options for req in requirements):
|
| 384 |
+
options.require_hashes = True
|
| 385 |
+
|
| 386 |
+
if not (
|
| 387 |
+
args
|
| 388 |
+
or options.editables
|
| 389 |
+
or options.requirements
|
| 390 |
+
or options.dependency_groups
|
| 391 |
+
or options.requirements_from_scripts
|
| 392 |
+
):
|
| 393 |
+
opts = {"name": self.name}
|
| 394 |
+
if options.find_links:
|
| 395 |
+
raise CommandError(
|
| 396 |
+
"You must give at least one requirement to {name} "
|
| 397 |
+
'(maybe you meant "pip {name} {links}"?)'.format(
|
| 398 |
+
**dict(opts, links=" ".join(options.find_links))
|
| 399 |
+
)
|
| 400 |
+
)
|
| 401 |
+
else:
|
| 402 |
+
raise CommandError(
|
| 403 |
+
"You must give at least one requirement to {name} "
|
| 404 |
+
'(see "pip help {name}")'.format(**opts)
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
return requirements
|
| 408 |
+
|
| 409 |
+
@staticmethod
|
| 410 |
+
def trace_basic_info(finder: PackageFinder) -> None:
|
| 411 |
+
"""
|
| 412 |
+
Trace basic information about the provided objects.
|
| 413 |
+
"""
|
| 414 |
+
# Display where finder is looking for packages
|
| 415 |
+
search_scope = finder.search_scope
|
| 416 |
+
locations = search_scope.get_formatted_locations()
|
| 417 |
+
if locations:
|
| 418 |
+
logger.info(locations)
|
| 419 |
+
|
| 420 |
+
def _build_package_finder(
|
| 421 |
+
self,
|
| 422 |
+
options: Values,
|
| 423 |
+
session: PipSession,
|
| 424 |
+
target_python: TargetPython | None = None,
|
| 425 |
+
ignore_requires_python: bool | None = None,
|
| 426 |
+
) -> PackageFinder:
|
| 427 |
+
"""
|
| 428 |
+
Create a package finder appropriate to this requirement command.
|
| 429 |
+
|
| 430 |
+
:param ignore_requires_python: Whether to ignore incompatible
|
| 431 |
+
"Requires-Python" values in links. Defaults to False.
|
| 432 |
+
"""
|
| 433 |
+
link_collector = LinkCollector.create(session, options=options)
|
| 434 |
+
selection_prefs = SelectionPreferences(
|
| 435 |
+
allow_yanked=True,
|
| 436 |
+
format_control=options.format_control,
|
| 437 |
+
release_control=options.release_control,
|
| 438 |
+
prefer_binary=options.prefer_binary,
|
| 439 |
+
ignore_requires_python=ignore_requires_python,
|
| 440 |
+
)
|
| 441 |
+
|
| 442 |
+
return PackageFinder.create(
|
| 443 |
+
link_collector=link_collector,
|
| 444 |
+
selection_prefs=selection_prefs,
|
| 445 |
+
target_python=target_python,
|
| 446 |
+
uploaded_prior_to=options.uploaded_prior_to,
|
| 447 |
+
)
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/spinners.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import itertools
|
| 5 |
+
import logging
|
| 6 |
+
import sys
|
| 7 |
+
import time
|
| 8 |
+
from collections.abc import Generator
|
| 9 |
+
from typing import IO, Final
|
| 10 |
+
|
| 11 |
+
from pip._vendor.rich.console import (
|
| 12 |
+
Console,
|
| 13 |
+
ConsoleOptions,
|
| 14 |
+
RenderableType,
|
| 15 |
+
RenderResult,
|
| 16 |
+
)
|
| 17 |
+
from pip._vendor.rich.live import Live
|
| 18 |
+
from pip._vendor.rich.measure import Measurement
|
| 19 |
+
from pip._vendor.rich.text import Text
|
| 20 |
+
|
| 21 |
+
from pip._internal.utils.compat import WINDOWS
|
| 22 |
+
from pip._internal.utils.logging import get_console, get_indentation
|
| 23 |
+
|
| 24 |
+
logger = logging.getLogger(__name__)
|
| 25 |
+
|
| 26 |
+
SPINNER_CHARS: Final = r"-\|/"
|
| 27 |
+
SPINS_PER_SECOND: Final = 8
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class SpinnerInterface:
|
| 31 |
+
def spin(self) -> None:
|
| 32 |
+
raise NotImplementedError()
|
| 33 |
+
|
| 34 |
+
def finish(self, final_status: str) -> None:
|
| 35 |
+
raise NotImplementedError()
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class InteractiveSpinner(SpinnerInterface):
|
| 39 |
+
def __init__(
|
| 40 |
+
self,
|
| 41 |
+
message: str,
|
| 42 |
+
file: IO[str] | None = None,
|
| 43 |
+
spin_chars: str = SPINNER_CHARS,
|
| 44 |
+
# Empirically, 8 updates/second looks nice
|
| 45 |
+
min_update_interval_seconds: float = 1 / SPINS_PER_SECOND,
|
| 46 |
+
):
|
| 47 |
+
self._message = message
|
| 48 |
+
if file is None:
|
| 49 |
+
file = sys.stdout
|
| 50 |
+
self._file = file
|
| 51 |
+
self._rate_limiter = RateLimiter(min_update_interval_seconds)
|
| 52 |
+
self._finished = False
|
| 53 |
+
|
| 54 |
+
self._spin_cycle = itertools.cycle(spin_chars)
|
| 55 |
+
|
| 56 |
+
self._file.write(" " * get_indentation() + self._message + " ... ")
|
| 57 |
+
self._width = 0
|
| 58 |
+
|
| 59 |
+
def _write(self, status: str) -> None:
|
| 60 |
+
assert not self._finished
|
| 61 |
+
# Erase what we wrote before by backspacing to the beginning, writing
|
| 62 |
+
# spaces to overwrite the old text, and then backspacing again
|
| 63 |
+
backup = "\b" * self._width
|
| 64 |
+
self._file.write(backup + " " * self._width + backup)
|
| 65 |
+
# Now we have a blank slate to add our status
|
| 66 |
+
self._file.write(status)
|
| 67 |
+
self._width = len(status)
|
| 68 |
+
self._file.flush()
|
| 69 |
+
self._rate_limiter.reset()
|
| 70 |
+
|
| 71 |
+
def spin(self) -> None:
|
| 72 |
+
if self._finished:
|
| 73 |
+
return
|
| 74 |
+
if not self._rate_limiter.ready():
|
| 75 |
+
return
|
| 76 |
+
self._write(next(self._spin_cycle))
|
| 77 |
+
|
| 78 |
+
def finish(self, final_status: str) -> None:
|
| 79 |
+
if self._finished:
|
| 80 |
+
return
|
| 81 |
+
self._write(final_status)
|
| 82 |
+
self._file.write("\n")
|
| 83 |
+
self._file.flush()
|
| 84 |
+
self._finished = True
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
# Used for dumb terminals, non-interactive installs (no tty), etc.
|
| 88 |
+
# We still print updates occasionally (once every 60 seconds by default) to
|
| 89 |
+
# act as a keep-alive for systems like Travis-CI that take lack-of-output as
|
| 90 |
+
# an indication that a task has frozen.
|
| 91 |
+
class NonInteractiveSpinner(SpinnerInterface):
|
| 92 |
+
def __init__(self, message: str, min_update_interval_seconds: float = 60.0) -> None:
|
| 93 |
+
self._message = message
|
| 94 |
+
self._finished = False
|
| 95 |
+
self._rate_limiter = RateLimiter(min_update_interval_seconds)
|
| 96 |
+
self._update("started")
|
| 97 |
+
|
| 98 |
+
def _update(self, status: str) -> None:
|
| 99 |
+
assert not self._finished
|
| 100 |
+
self._rate_limiter.reset()
|
| 101 |
+
logger.info("%s: %s", self._message, status)
|
| 102 |
+
|
| 103 |
+
def spin(self) -> None:
|
| 104 |
+
if self._finished:
|
| 105 |
+
return
|
| 106 |
+
if not self._rate_limiter.ready():
|
| 107 |
+
return
|
| 108 |
+
self._update("still running...")
|
| 109 |
+
|
| 110 |
+
def finish(self, final_status: str) -> None:
|
| 111 |
+
if self._finished:
|
| 112 |
+
return
|
| 113 |
+
self._update(f"finished with status '{final_status}'")
|
| 114 |
+
self._finished = True
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
class RateLimiter:
|
| 118 |
+
def __init__(self, min_update_interval_seconds: float) -> None:
|
| 119 |
+
self._min_update_interval_seconds = min_update_interval_seconds
|
| 120 |
+
self._last_update: float = 0
|
| 121 |
+
|
| 122 |
+
def ready(self) -> bool:
|
| 123 |
+
now = time.time()
|
| 124 |
+
delta = now - self._last_update
|
| 125 |
+
return delta >= self._min_update_interval_seconds
|
| 126 |
+
|
| 127 |
+
def reset(self) -> None:
|
| 128 |
+
self._last_update = time.time()
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
@contextlib.contextmanager
|
| 132 |
+
def open_spinner(message: str) -> Generator[SpinnerInterface, None, None]:
|
| 133 |
+
# Interactive spinner goes directly to sys.stdout rather than being routed
|
| 134 |
+
# through the logging system, but it acts like it has level INFO,
|
| 135 |
+
# i.e. it's only displayed if we're at level INFO or better.
|
| 136 |
+
# Non-interactive spinner goes through the logging system, so it is always
|
| 137 |
+
# in sync with logging configuration.
|
| 138 |
+
if sys.stdout.isatty() and logger.getEffectiveLevel() <= logging.INFO:
|
| 139 |
+
spinner: SpinnerInterface = InteractiveSpinner(message)
|
| 140 |
+
else:
|
| 141 |
+
spinner = NonInteractiveSpinner(message)
|
| 142 |
+
try:
|
| 143 |
+
with hidden_cursor(sys.stdout):
|
| 144 |
+
yield spinner
|
| 145 |
+
except KeyboardInterrupt:
|
| 146 |
+
spinner.finish("canceled")
|
| 147 |
+
raise
|
| 148 |
+
except Exception:
|
| 149 |
+
spinner.finish("error")
|
| 150 |
+
raise
|
| 151 |
+
else:
|
| 152 |
+
spinner.finish("done")
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
class _PipRichSpinner:
|
| 156 |
+
"""
|
| 157 |
+
Custom rich spinner that matches the style of the legacy spinners.
|
| 158 |
+
|
| 159 |
+
(*) Updates will be handled in a background thread by a rich live panel
|
| 160 |
+
which will call render() automatically at the appropriate time.
|
| 161 |
+
"""
|
| 162 |
+
|
| 163 |
+
def __init__(self, label: str) -> None:
|
| 164 |
+
self.label = label
|
| 165 |
+
self._spin_cycle = itertools.cycle(SPINNER_CHARS)
|
| 166 |
+
self._spinner_text = ""
|
| 167 |
+
self._finished = False
|
| 168 |
+
self._indent = get_indentation() * " "
|
| 169 |
+
|
| 170 |
+
def __rich_console__(
|
| 171 |
+
self, console: Console, options: ConsoleOptions
|
| 172 |
+
) -> RenderResult:
|
| 173 |
+
yield self.render()
|
| 174 |
+
|
| 175 |
+
def __rich_measure__(
|
| 176 |
+
self, console: Console, options: ConsoleOptions
|
| 177 |
+
) -> Measurement:
|
| 178 |
+
text = self.render()
|
| 179 |
+
return Measurement.get(console, options, text)
|
| 180 |
+
|
| 181 |
+
def render(self) -> RenderableType:
|
| 182 |
+
if not self._finished:
|
| 183 |
+
self._spinner_text = next(self._spin_cycle)
|
| 184 |
+
|
| 185 |
+
return Text.assemble(self._indent, self.label, " ... ", self._spinner_text)
|
| 186 |
+
|
| 187 |
+
def finish(self, status: str) -> None:
|
| 188 |
+
"""Stop spinning and set a final status message."""
|
| 189 |
+
self._spinner_text = status
|
| 190 |
+
self._finished = True
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
@contextlib.contextmanager
|
| 194 |
+
def open_rich_spinner(label: str, console: Console | None = None) -> Generator[None]:
|
| 195 |
+
if not logger.isEnabledFor(logging.INFO):
|
| 196 |
+
# Don't show spinner if --quiet is given.
|
| 197 |
+
yield
|
| 198 |
+
return
|
| 199 |
+
|
| 200 |
+
console = console or get_console()
|
| 201 |
+
spinner = _PipRichSpinner(label)
|
| 202 |
+
with Live(spinner, refresh_per_second=SPINS_PER_SECOND, console=console):
|
| 203 |
+
try:
|
| 204 |
+
yield
|
| 205 |
+
except KeyboardInterrupt:
|
| 206 |
+
spinner.finish("canceled")
|
| 207 |
+
raise
|
| 208 |
+
except Exception:
|
| 209 |
+
spinner.finish("error")
|
| 210 |
+
raise
|
| 211 |
+
else:
|
| 212 |
+
spinner.finish("done")
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
HIDE_CURSOR = "\x1b[?25l"
|
| 216 |
+
SHOW_CURSOR = "\x1b[?25h"
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
@contextlib.contextmanager
|
| 220 |
+
def hidden_cursor(file: IO[str]) -> Generator[None, None, None]:
|
| 221 |
+
# The Windows terminal does not support the hide/show cursor ANSI codes,
|
| 222 |
+
# even via colorama. So don't even try.
|
| 223 |
+
if WINDOWS:
|
| 224 |
+
yield
|
| 225 |
+
# We don't want to clutter the output with control characters if we're
|
| 226 |
+
# writing to a file, or if the user is running with --quiet.
|
| 227 |
+
# See https://github.com/pypa/pip/issues/3418
|
| 228 |
+
elif not file.isatty() or logger.getEffectiveLevel() > logging.INFO:
|
| 229 |
+
yield
|
| 230 |
+
else:
|
| 231 |
+
file.write(HIDE_CURSOR)
|
| 232 |
+
try:
|
| 233 |
+
yield
|
| 234 |
+
finally:
|
| 235 |
+
file.write(SHOW_CURSOR)
|
.venv/lib/python3.12/site-packages/pip/_internal/cli/status_codes.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
SUCCESS = 0
|
| 2 |
+
ERROR = 1
|
| 3 |
+
UNKNOWN_ERROR = 2
|
| 4 |
+
VIRTUALENV_NOT_FOUND = 3
|
| 5 |
+
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ations
|
| 6 |
+
|
| 7 |
+
import importlib
|
| 8 |
+
from collections import namedtuple
|
| 9 |
+
from typing import Any
|
| 10 |
+
|
| 11 |
+
from pip._internal.cli.base_command import Command
|
| 12 |
+
|
| 13 |
+
CommandInfo = namedtuple("CommandInfo", "module_path, class_name, summary")
|
| 14 |
+
|
| 15 |
+
# This dictionary does a bunch of heavy lifting for help output:
|
| 16 |
+
# - Enables avoiding additional (costly) imports for presenting `--help`.
|
| 17 |
+
# - The ordering matters for help display.
|
| 18 |
+
#
|
| 19 |
+
# Even though the module path starts with the same "pip._internal.commands"
|
| 20 |
+
# prefix, the full path makes testing easier (specifically when modifying
|
| 21 |
+
# `commands_dict` in test setup / teardown).
|
| 22 |
+
commands_dict: dict[str, CommandInfo] = {
|
| 23 |
+
"install": CommandInfo(
|
| 24 |
+
"pip._internal.commands.install",
|
| 25 |
+
"InstallCommand",
|
| 26 |
+
"Install packages.",
|
| 27 |
+
),
|
| 28 |
+
"lock": CommandInfo(
|
| 29 |
+
"pip._internal.commands.lock",
|
| 30 |
+
"LockCommand",
|
| 31 |
+
"Generate a lock file.",
|
| 32 |
+
),
|
| 33 |
+
"download": CommandInfo(
|
| 34 |
+
"pip._internal.commands.download",
|
| 35 |
+
"DownloadCommand",
|
| 36 |
+
"Download packages.",
|
| 37 |
+
),
|
| 38 |
+
"uninstall": CommandInfo(
|
| 39 |
+
"pip._internal.commands.uninstall",
|
| 40 |
+
"UninstallCommand",
|
| 41 |
+
"Uninstall packages.",
|
| 42 |
+
),
|
| 43 |
+
"freeze": CommandInfo(
|
| 44 |
+
"pip._internal.commands.freeze",
|
| 45 |
+
"FreezeCommand",
|
| 46 |
+
"Output installed packages in requirements format.",
|
| 47 |
+
),
|
| 48 |
+
"inspect": CommandInfo(
|
| 49 |
+
"pip._internal.commands.inspect",
|
| 50 |
+
"InspectCommand",
|
| 51 |
+
"Inspect the python environment.",
|
| 52 |
+
),
|
| 53 |
+
"list": CommandInfo(
|
| 54 |
+
"pip._internal.commands.list",
|
| 55 |
+
"ListCommand",
|
| 56 |
+
"List installed packages.",
|
| 57 |
+
),
|
| 58 |
+
"show": CommandInfo(
|
| 59 |
+
"pip._internal.commands.show",
|
| 60 |
+
"ShowCommand",
|
| 61 |
+
"Show information about installed packages.",
|
| 62 |
+
),
|
| 63 |
+
"check": CommandInfo(
|
| 64 |
+
"pip._internal.commands.check",
|
| 65 |
+
"CheckCommand",
|
| 66 |
+
"Verify installed packages have compatible dependencies.",
|
| 67 |
+
),
|
| 68 |
+
"config": CommandInfo(
|
| 69 |
+
"pip._internal.commands.configuration",
|
| 70 |
+
"ConfigurationCommand",
|
| 71 |
+
"Manage local and global configuration.",
|
| 72 |
+
),
|
| 73 |
+
"search": CommandInfo(
|
| 74 |
+
"pip._internal.commands.search",
|
| 75 |
+
"SearchCommand",
|
| 76 |
+
"Search PyPI for packages.",
|
| 77 |
+
),
|
| 78 |
+
"cache": CommandInfo(
|
| 79 |
+
"pip._internal.commands.cache",
|
| 80 |
+
"CacheCommand",
|
| 81 |
+
"Inspect and manage pip's wheel cache.",
|
| 82 |
+
),
|
| 83 |
+
"index": CommandInfo(
|
| 84 |
+
"pip._internal.commands.index",
|
| 85 |
+
"IndexCommand",
|
| 86 |
+
"Inspect information available from package indexes.",
|
| 87 |
+
),
|
| 88 |
+
"wheel": CommandInfo(
|
| 89 |
+
"pip._internal.commands.wheel",
|
| 90 |
+
"WheelCommand",
|
| 91 |
+
"Build wheels from your requirements.",
|
| 92 |
+
),
|
| 93 |
+
"hash": CommandInfo(
|
| 94 |
+
"pip._internal.commands.hash",
|
| 95 |
+
"HashCommand",
|
| 96 |
+
"Compute hashes of package archives.",
|
| 97 |
+
),
|
| 98 |
+
"completion": CommandInfo(
|
| 99 |
+
"pip._internal.commands.completion",
|
| 100 |
+
"CompletionCommand",
|
| 101 |
+
"A helper command used for command completion.",
|
| 102 |
+
),
|
| 103 |
+
"debug": CommandInfo(
|
| 104 |
+
"pip._internal.commands.debug",
|
| 105 |
+
"DebugCommand",
|
| 106 |
+
"Show information useful for debugging.",
|
| 107 |
+
),
|
| 108 |
+
"help": CommandInfo(
|
| 109 |
+
"pip._internal.commands.help",
|
| 110 |
+
"HelpCommand",
|
| 111 |
+
"Show help for commands.",
|
| 112 |
+
),
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def create_command(name: str, **kwargs: Any) -> Command:
|
| 117 |
+
"""
|
| 118 |
+
Create an instance of the Command class with the given name.
|
| 119 |
+
"""
|
| 120 |
+
module_path, class_name, summary = commands_dict[name]
|
| 121 |
+
module = importlib.import_module(module_path)
|
| 122 |
+
command_class = getattr(module, class_name)
|
| 123 |
+
command = command_class(name=name, summary=summary, **kwargs)
|
| 124 |
+
|
| 125 |
+
return command
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def get_similar_commands(name: str) -> str | None:
|
| 129 |
+
"""Command name auto-correct."""
|
| 130 |
+
from difflib import get_close_matches
|
| 131 |
+
|
| 132 |
+
name = name.lower()
|
| 133 |
+
|
| 134 |
+
close_commands = get_close_matches(name, commands_dict.keys())
|
| 135 |
+
|
| 136 |
+
if close_commands:
|
| 137 |
+
return close_commands[0]
|
| 138 |
+
else:
|
| 139 |
+
return None
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/cache.py
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import textwrap
|
| 3 |
+
from optparse import Values
|
| 4 |
+
from typing import Callable
|
| 5 |
+
|
| 6 |
+
from pip._internal.cli.base_command import Command
|
| 7 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 8 |
+
from pip._internal.exceptions import CommandError, PipError
|
| 9 |
+
from pip._internal.utils import filesystem
|
| 10 |
+
from pip._internal.utils.logging import getLogger
|
| 11 |
+
from pip._internal.utils.misc import format_size
|
| 12 |
+
|
| 13 |
+
logger = getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class CacheCommand(Command):
|
| 17 |
+
"""
|
| 18 |
+
Inspect and manage pip's wheel cache.
|
| 19 |
+
|
| 20 |
+
Subcommands:
|
| 21 |
+
|
| 22 |
+
- dir: Show the cache directory.
|
| 23 |
+
- info: Show information about the cache.
|
| 24 |
+
- list: List filenames of packages stored in the cache.
|
| 25 |
+
- remove: Remove one or more package from the cache.
|
| 26 |
+
- purge: Remove all items from the cache.
|
| 27 |
+
|
| 28 |
+
``<pattern>`` can be a glob expression or a package name.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
ignore_require_venv = True
|
| 32 |
+
usage = """
|
| 33 |
+
%prog dir
|
| 34 |
+
%prog info
|
| 35 |
+
%prog list [<pattern>] [--format=[human, abspath]]
|
| 36 |
+
%prog remove <pattern>
|
| 37 |
+
%prog purge
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
def add_options(self) -> None:
|
| 41 |
+
self.cmd_opts.add_option(
|
| 42 |
+
"--format",
|
| 43 |
+
action="store",
|
| 44 |
+
dest="list_format",
|
| 45 |
+
default="human",
|
| 46 |
+
choices=("human", "abspath"),
|
| 47 |
+
help="Select the output format among: human (default) or abspath",
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 51 |
+
|
| 52 |
+
def handler_map(self) -> dict[str, Callable[[Values, list[str]], None]]:
|
| 53 |
+
return {
|
| 54 |
+
"dir": self.get_cache_dir,
|
| 55 |
+
"info": self.get_cache_info,
|
| 56 |
+
"list": self.list_cache_items,
|
| 57 |
+
"remove": self.remove_cache_items,
|
| 58 |
+
"purge": self.purge_cache,
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 62 |
+
handler_map = self.handler_map()
|
| 63 |
+
|
| 64 |
+
if not options.cache_dir:
|
| 65 |
+
logger.error("pip cache commands can not function since cache is disabled.")
|
| 66 |
+
return ERROR
|
| 67 |
+
|
| 68 |
+
# Determine action
|
| 69 |
+
if not args or args[0] not in handler_map:
|
| 70 |
+
logger.error(
|
| 71 |
+
"Need an action (%s) to perform.",
|
| 72 |
+
", ".join(sorted(handler_map)),
|
| 73 |
+
)
|
| 74 |
+
return ERROR
|
| 75 |
+
|
| 76 |
+
action = args[0]
|
| 77 |
+
|
| 78 |
+
# Error handling happens here, not in the action-handlers.
|
| 79 |
+
try:
|
| 80 |
+
handler_map[action](options, args[1:])
|
| 81 |
+
except PipError as e:
|
| 82 |
+
logger.error(e.args[0])
|
| 83 |
+
return ERROR
|
| 84 |
+
|
| 85 |
+
return SUCCESS
|
| 86 |
+
|
| 87 |
+
def get_cache_dir(self, options: Values, args: list[str]) -> None:
|
| 88 |
+
if args:
|
| 89 |
+
raise CommandError("Too many arguments")
|
| 90 |
+
|
| 91 |
+
logger.info(options.cache_dir)
|
| 92 |
+
|
| 93 |
+
def get_cache_info(self, options: Values, args: list[str]) -> None:
|
| 94 |
+
if args:
|
| 95 |
+
raise CommandError("Too many arguments")
|
| 96 |
+
|
| 97 |
+
num_http_files = len(self._find_http_files(options))
|
| 98 |
+
num_packages = len(self._find_wheels(options, "*"))
|
| 99 |
+
|
| 100 |
+
http_cache_location = self._cache_dir(options, "http-v2")
|
| 101 |
+
old_http_cache_location = self._cache_dir(options, "http")
|
| 102 |
+
wheels_cache_location = self._cache_dir(options, "wheels")
|
| 103 |
+
http_cache_size = filesystem.format_size(
|
| 104 |
+
filesystem.directory_size(http_cache_location)
|
| 105 |
+
+ filesystem.directory_size(old_http_cache_location)
|
| 106 |
+
)
|
| 107 |
+
wheels_cache_size = filesystem.format_directory_size(wheels_cache_location)
|
| 108 |
+
|
| 109 |
+
message = (
|
| 110 |
+
textwrap.dedent(
|
| 111 |
+
"""
|
| 112 |
+
Package index page cache location (pip v23.3+): {http_cache_location}
|
| 113 |
+
Package index page cache location (older pips): {old_http_cache_location}
|
| 114 |
+
Package index page cache size: {http_cache_size}
|
| 115 |
+
Number of HTTP files: {num_http_files}
|
| 116 |
+
Locally built wheels location: {wheels_cache_location}
|
| 117 |
+
Locally built wheels size: {wheels_cache_size}
|
| 118 |
+
Number of locally built wheels: {package_count}
|
| 119 |
+
""" # noqa: E501
|
| 120 |
+
)
|
| 121 |
+
.format(
|
| 122 |
+
http_cache_location=http_cache_location,
|
| 123 |
+
old_http_cache_location=old_http_cache_location,
|
| 124 |
+
http_cache_size=http_cache_size,
|
| 125 |
+
num_http_files=num_http_files,
|
| 126 |
+
wheels_cache_location=wheels_cache_location,
|
| 127 |
+
package_count=num_packages,
|
| 128 |
+
wheels_cache_size=wheels_cache_size,
|
| 129 |
+
)
|
| 130 |
+
.strip()
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
logger.info(message)
|
| 134 |
+
|
| 135 |
+
def list_cache_items(self, options: Values, args: list[str]) -> None:
|
| 136 |
+
if len(args) > 1:
|
| 137 |
+
raise CommandError("Too many arguments")
|
| 138 |
+
|
| 139 |
+
if args:
|
| 140 |
+
pattern = args[0]
|
| 141 |
+
else:
|
| 142 |
+
pattern = "*"
|
| 143 |
+
|
| 144 |
+
files = self._find_wheels(options, pattern)
|
| 145 |
+
if options.list_format == "human":
|
| 146 |
+
self.format_for_human(files)
|
| 147 |
+
else:
|
| 148 |
+
self.format_for_abspath(files)
|
| 149 |
+
|
| 150 |
+
def format_for_human(self, files: list[str]) -> None:
|
| 151 |
+
if not files:
|
| 152 |
+
logger.info("No locally built wheels cached.")
|
| 153 |
+
return
|
| 154 |
+
|
| 155 |
+
results = []
|
| 156 |
+
for filename in files:
|
| 157 |
+
wheel = os.path.basename(filename)
|
| 158 |
+
size = filesystem.format_file_size(filename)
|
| 159 |
+
results.append(f" - {wheel} ({size})")
|
| 160 |
+
logger.info("Cache contents:\n")
|
| 161 |
+
logger.info("\n".join(sorted(results)))
|
| 162 |
+
|
| 163 |
+
def format_for_abspath(self, files: list[str]) -> None:
|
| 164 |
+
if files:
|
| 165 |
+
logger.info("\n".join(sorted(files)))
|
| 166 |
+
|
| 167 |
+
def remove_cache_items(self, options: Values, args: list[str]) -> None:
|
| 168 |
+
if len(args) > 1:
|
| 169 |
+
raise CommandError("Too many arguments")
|
| 170 |
+
|
| 171 |
+
if not args:
|
| 172 |
+
raise CommandError("Please provide a pattern")
|
| 173 |
+
|
| 174 |
+
files = self._find_wheels(options, args[0])
|
| 175 |
+
|
| 176 |
+
no_matching_msg = "No matching packages"
|
| 177 |
+
if args[0] == "*":
|
| 178 |
+
# Only fetch http files if no specific pattern given
|
| 179 |
+
files += self._find_http_files(options)
|
| 180 |
+
else:
|
| 181 |
+
# Add the pattern to the log message
|
| 182 |
+
no_matching_msg += f' for pattern "{args[0]}"'
|
| 183 |
+
|
| 184 |
+
if not files:
|
| 185 |
+
logger.warning(no_matching_msg)
|
| 186 |
+
|
| 187 |
+
bytes_removed = 0
|
| 188 |
+
for filename in files:
|
| 189 |
+
bytes_removed += os.stat(filename).st_size
|
| 190 |
+
os.unlink(filename)
|
| 191 |
+
logger.verbose("Removed %s", filename)
|
| 192 |
+
|
| 193 |
+
http_dirs = filesystem.subdirs_without_files(self._cache_dir(options, "http"))
|
| 194 |
+
wheel_dirs = filesystem.subdirs_without_wheels(
|
| 195 |
+
self._cache_dir(options, "wheels")
|
| 196 |
+
)
|
| 197 |
+
dirs = [*http_dirs, *wheel_dirs]
|
| 198 |
+
|
| 199 |
+
for subdir in dirs:
|
| 200 |
+
try:
|
| 201 |
+
for file in subdir.iterdir():
|
| 202 |
+
file.unlink(missing_ok=True)
|
| 203 |
+
subdir.rmdir()
|
| 204 |
+
except FileNotFoundError:
|
| 205 |
+
# If the directory is already gone, that's fine.
|
| 206 |
+
pass
|
| 207 |
+
logger.verbose("Removed %s", subdir)
|
| 208 |
+
|
| 209 |
+
# selfcheck.json is no longer used by pip.
|
| 210 |
+
selfcheck_json = self._cache_dir(options, "selfcheck.json")
|
| 211 |
+
if os.path.isfile(selfcheck_json):
|
| 212 |
+
os.remove(selfcheck_json)
|
| 213 |
+
logger.verbose("Removed legacy selfcheck.json file")
|
| 214 |
+
|
| 215 |
+
logger.info("Files removed: %s (%s)", len(files), format_size(bytes_removed))
|
| 216 |
+
logger.info("Directories removed: %s", len(dirs))
|
| 217 |
+
|
| 218 |
+
def purge_cache(self, options: Values, args: list[str]) -> None:
|
| 219 |
+
if args:
|
| 220 |
+
raise CommandError("Too many arguments")
|
| 221 |
+
|
| 222 |
+
return self.remove_cache_items(options, ["*"])
|
| 223 |
+
|
| 224 |
+
def _cache_dir(self, options: Values, subdir: str) -> str:
|
| 225 |
+
return os.path.join(options.cache_dir, subdir)
|
| 226 |
+
|
| 227 |
+
def _find_http_files(self, options: Values) -> list[str]:
|
| 228 |
+
old_http_dir = self._cache_dir(options, "http")
|
| 229 |
+
new_http_dir = self._cache_dir(options, "http-v2")
|
| 230 |
+
return filesystem.find_files(old_http_dir, "*") + filesystem.find_files(
|
| 231 |
+
new_http_dir, "*"
|
| 232 |
+
)
|
| 233 |
+
|
| 234 |
+
def _find_wheels(self, options: Values, pattern: str) -> list[str]:
|
| 235 |
+
wheel_dir = self._cache_dir(options, "wheels")
|
| 236 |
+
|
| 237 |
+
# The wheel filename format, as specified in PEP 427, is:
|
| 238 |
+
# {distribution}-{version}(-{build})?-{python}-{abi}-{platform}.whl
|
| 239 |
+
#
|
| 240 |
+
# Additionally, non-alphanumeric values in the distribution are
|
| 241 |
+
# normalized to underscores (_), meaning hyphens can never occur
|
| 242 |
+
# before `-{version}`.
|
| 243 |
+
#
|
| 244 |
+
# Given that information:
|
| 245 |
+
# - If the pattern we're given contains a hyphen (-), the user is
|
| 246 |
+
# providing at least the version. Thus, we can just append `*.whl`
|
| 247 |
+
# to match the rest of it.
|
| 248 |
+
# - If the pattern we're given doesn't contain a hyphen (-), the
|
| 249 |
+
# user is only providing the name. Thus, we append `-*.whl` to
|
| 250 |
+
# match the hyphen before the version, followed by anything else.
|
| 251 |
+
#
|
| 252 |
+
# PEP 427: https://www.python.org/dev/peps/pep-0427/
|
| 253 |
+
pattern = pattern + ("*.whl" if "-" in pattern else "-*.whl")
|
| 254 |
+
|
| 255 |
+
return filesystem.find_files(wheel_dir, pattern)
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/check.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from optparse import Values
|
| 3 |
+
|
| 4 |
+
from pip._internal.cli.base_command import Command
|
| 5 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 6 |
+
from pip._internal.metadata import get_default_environment
|
| 7 |
+
from pip._internal.operations.check import (
|
| 8 |
+
check_package_set,
|
| 9 |
+
check_unsupported,
|
| 10 |
+
create_package_set_from_installed,
|
| 11 |
+
)
|
| 12 |
+
from pip._internal.utils.compatibility_tags import get_supported
|
| 13 |
+
from pip._internal.utils.misc import write_output
|
| 14 |
+
|
| 15 |
+
logger = logging.getLogger(__name__)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class CheckCommand(Command):
|
| 19 |
+
"""Verify installed packages have compatible dependencies."""
|
| 20 |
+
|
| 21 |
+
ignore_require_venv = True
|
| 22 |
+
usage = """
|
| 23 |
+
%prog [options]"""
|
| 24 |
+
|
| 25 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 26 |
+
package_set, parsing_probs = create_package_set_from_installed()
|
| 27 |
+
missing, conflicting = check_package_set(package_set)
|
| 28 |
+
unsupported = list(
|
| 29 |
+
check_unsupported(
|
| 30 |
+
get_default_environment().iter_installed_distributions(),
|
| 31 |
+
get_supported(),
|
| 32 |
+
)
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
for project_name in missing:
|
| 36 |
+
version = package_set[project_name].version
|
| 37 |
+
for dependency in missing[project_name]:
|
| 38 |
+
write_output(
|
| 39 |
+
"%s %s requires %s, which is not installed.",
|
| 40 |
+
project_name,
|
| 41 |
+
version,
|
| 42 |
+
dependency[0],
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
for project_name in conflicting:
|
| 46 |
+
version = package_set[project_name].version
|
| 47 |
+
for dep_name, dep_version, req in conflicting[project_name]:
|
| 48 |
+
write_output(
|
| 49 |
+
"%s %s has requirement %s, but you have %s %s.",
|
| 50 |
+
project_name,
|
| 51 |
+
version,
|
| 52 |
+
req,
|
| 53 |
+
dep_name,
|
| 54 |
+
dep_version,
|
| 55 |
+
)
|
| 56 |
+
for package in unsupported:
|
| 57 |
+
write_output(
|
| 58 |
+
"%s %s is not supported on this platform",
|
| 59 |
+
package.raw_name,
|
| 60 |
+
package.version,
|
| 61 |
+
)
|
| 62 |
+
if missing or conflicting or parsing_probs or unsupported:
|
| 63 |
+
return ERROR
|
| 64 |
+
else:
|
| 65 |
+
write_output("No broken requirements found.")
|
| 66 |
+
return SUCCESS
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/completion.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import textwrap
|
| 3 |
+
from optparse import Values
|
| 4 |
+
|
| 5 |
+
from pip._internal.cli.base_command import Command
|
| 6 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 7 |
+
from pip._internal.utils.misc import get_prog
|
| 8 |
+
|
| 9 |
+
BASE_COMPLETION = """
|
| 10 |
+
# pip {shell} completion start{script}# pip {shell} completion end
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
COMPLETION_SCRIPTS = {
|
| 14 |
+
"bash": """
|
| 15 |
+
_pip_completion()
|
| 16 |
+
{{
|
| 17 |
+
local IFS=$' \\t\\n'
|
| 18 |
+
COMPREPLY=( $( COMP_WORDS="${{COMP_WORDS[*]}}" \\
|
| 19 |
+
COMP_CWORD=$COMP_CWORD \\
|
| 20 |
+
PIP_AUTO_COMPLETE=1 "$1" 2>/dev/null ) )
|
| 21 |
+
}}
|
| 22 |
+
complete -o default -F _pip_completion {prog}
|
| 23 |
+
""",
|
| 24 |
+
"zsh": """
|
| 25 |
+
#compdef -P pip[0-9.]#
|
| 26 |
+
__pip() {{
|
| 27 |
+
compadd $( COMP_WORDS="$words[*]" \\
|
| 28 |
+
COMP_CWORD=$((CURRENT-1)) \\
|
| 29 |
+
PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )
|
| 30 |
+
}}
|
| 31 |
+
if [[ $zsh_eval_context[-1] == loadautofunc ]]; then
|
| 32 |
+
# autoload from fpath, call function directly
|
| 33 |
+
__pip "$@"
|
| 34 |
+
else
|
| 35 |
+
# eval/source/. command, register function for later
|
| 36 |
+
compdef __pip -P 'pip[0-9.]#'
|
| 37 |
+
fi
|
| 38 |
+
""",
|
| 39 |
+
"fish": """
|
| 40 |
+
function __fish_complete_pip
|
| 41 |
+
set -lx COMP_WORDS \\
|
| 42 |
+
(commandline --current-process --tokenize --cut-at-cursor) \\
|
| 43 |
+
(commandline --current-token --cut-at-cursor)
|
| 44 |
+
set -lx COMP_CWORD (math (count $COMP_WORDS) - 1)
|
| 45 |
+
set -lx PIP_AUTO_COMPLETE 1
|
| 46 |
+
set -l completions
|
| 47 |
+
if string match -q '2.*' $version
|
| 48 |
+
set completions (eval $COMP_WORDS[1])
|
| 49 |
+
else
|
| 50 |
+
set completions ($COMP_WORDS[1])
|
| 51 |
+
end
|
| 52 |
+
string split \\ -- $completions
|
| 53 |
+
end
|
| 54 |
+
complete -fa "(__fish_complete_pip)" -c {prog}
|
| 55 |
+
""",
|
| 56 |
+
"powershell": """
|
| 57 |
+
if ((Test-Path Function:\\TabExpansion) -and -not `
|
| 58 |
+
(Test-Path Function:\\_pip_completeBackup)) {{
|
| 59 |
+
Rename-Item Function:\\TabExpansion _pip_completeBackup
|
| 60 |
+
}}
|
| 61 |
+
function TabExpansion($line, $lastWord) {{
|
| 62 |
+
$lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()
|
| 63 |
+
if ($lastBlock.StartsWith("{prog} ")) {{
|
| 64 |
+
$Env:COMP_WORDS=$lastBlock
|
| 65 |
+
$Env:COMP_CWORD=$lastBlock.Split().Length - 1
|
| 66 |
+
$Env:PIP_AUTO_COMPLETE=1
|
| 67 |
+
(& {prog}).Split()
|
| 68 |
+
Remove-Item Env:COMP_WORDS
|
| 69 |
+
Remove-Item Env:COMP_CWORD
|
| 70 |
+
Remove-Item Env:PIP_AUTO_COMPLETE
|
| 71 |
+
}}
|
| 72 |
+
elseif (Test-Path Function:\\_pip_completeBackup) {{
|
| 73 |
+
# Fall back on existing tab expansion
|
| 74 |
+
_pip_completeBackup $line $lastWord
|
| 75 |
+
}}
|
| 76 |
+
}}
|
| 77 |
+
""",
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class CompletionCommand(Command):
|
| 82 |
+
"""A helper command to be used for command completion."""
|
| 83 |
+
|
| 84 |
+
ignore_require_venv = True
|
| 85 |
+
|
| 86 |
+
def add_options(self) -> None:
|
| 87 |
+
self.cmd_opts.add_option(
|
| 88 |
+
"--bash",
|
| 89 |
+
"-b",
|
| 90 |
+
action="store_const",
|
| 91 |
+
const="bash",
|
| 92 |
+
dest="shell",
|
| 93 |
+
help="Emit completion code for bash",
|
| 94 |
+
)
|
| 95 |
+
self.cmd_opts.add_option(
|
| 96 |
+
"--zsh",
|
| 97 |
+
"-z",
|
| 98 |
+
action="store_const",
|
| 99 |
+
const="zsh",
|
| 100 |
+
dest="shell",
|
| 101 |
+
help="Emit completion code for zsh",
|
| 102 |
+
)
|
| 103 |
+
self.cmd_opts.add_option(
|
| 104 |
+
"--fish",
|
| 105 |
+
"-f",
|
| 106 |
+
action="store_const",
|
| 107 |
+
const="fish",
|
| 108 |
+
dest="shell",
|
| 109 |
+
help="Emit completion code for fish",
|
| 110 |
+
)
|
| 111 |
+
self.cmd_opts.add_option(
|
| 112 |
+
"--powershell",
|
| 113 |
+
"-p",
|
| 114 |
+
action="store_const",
|
| 115 |
+
const="powershell",
|
| 116 |
+
dest="shell",
|
| 117 |
+
help="Emit completion code for powershell",
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 121 |
+
|
| 122 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 123 |
+
"""Prints the completion code of the given shell"""
|
| 124 |
+
shells = COMPLETION_SCRIPTS.keys()
|
| 125 |
+
shell_options = ["--" + shell for shell in sorted(shells)]
|
| 126 |
+
if options.shell in shells:
|
| 127 |
+
script = textwrap.dedent(
|
| 128 |
+
COMPLETION_SCRIPTS.get(options.shell, "").format(prog=get_prog())
|
| 129 |
+
)
|
| 130 |
+
print(BASE_COMPLETION.format(script=script, shell=options.shell))
|
| 131 |
+
return SUCCESS
|
| 132 |
+
else:
|
| 133 |
+
sys.stderr.write(
|
| 134 |
+
"ERROR: You must pass {}\n".format(" or ".join(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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import subprocess
|
| 6 |
+
from optparse import Values
|
| 7 |
+
from typing import Any, Callable
|
| 8 |
+
|
| 9 |
+
from pip._internal.cli.base_command import Command
|
| 10 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 11 |
+
from pip._internal.configuration import (
|
| 12 |
+
Configuration,
|
| 13 |
+
Kind,
|
| 14 |
+
get_configuration_files,
|
| 15 |
+
kinds,
|
| 16 |
+
)
|
| 17 |
+
from pip._internal.exceptions import PipError
|
| 18 |
+
from pip._internal.utils.logging import indent_log
|
| 19 |
+
from pip._internal.utils.misc import get_prog, write_output
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class ConfigurationCommand(Command):
|
| 25 |
+
"""
|
| 26 |
+
Manage local and global configuration.
|
| 27 |
+
|
| 28 |
+
Subcommands:
|
| 29 |
+
|
| 30 |
+
- list: List the active configuration (or from the file specified)
|
| 31 |
+
- edit: Edit the configuration file in an editor
|
| 32 |
+
- get: Get the value associated with command.option
|
| 33 |
+
- set: Set the command.option=value
|
| 34 |
+
- unset: Unset the value associated with command.option
|
| 35 |
+
- debug: List the configuration files and values defined under them
|
| 36 |
+
|
| 37 |
+
Configuration keys should be dot separated command and option name,
|
| 38 |
+
with the special prefix "global" affecting any command. For example,
|
| 39 |
+
"pip config set global.index-url https://example.org/" would configure
|
| 40 |
+
the index url for all commands, but "pip config set download.timeout 10"
|
| 41 |
+
would configure a 10 second timeout only for "pip download" commands.
|
| 42 |
+
|
| 43 |
+
If none of --user, --global and --site are passed, a virtual
|
| 44 |
+
environment configuration file is used if one is active and the file
|
| 45 |
+
exists. Otherwise, all modifications happen to the user file by
|
| 46 |
+
default.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
ignore_require_venv = True
|
| 50 |
+
usage = """
|
| 51 |
+
%prog [<file-option>] list
|
| 52 |
+
%prog [<file-option>] [--editor <editor-path>] edit
|
| 53 |
+
|
| 54 |
+
%prog [<file-option>] get command.option
|
| 55 |
+
%prog [<file-option>] set command.option value
|
| 56 |
+
%prog [<file-option>] unset command.option
|
| 57 |
+
%prog [<file-option>] debug
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
def add_options(self) -> None:
|
| 61 |
+
self.cmd_opts.add_option(
|
| 62 |
+
"--editor",
|
| 63 |
+
dest="editor",
|
| 64 |
+
action="store",
|
| 65 |
+
default=None,
|
| 66 |
+
help=(
|
| 67 |
+
"Editor to use to edit the file. Uses VISUAL or EDITOR "
|
| 68 |
+
"environment variables if not provided."
|
| 69 |
+
),
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
self.cmd_opts.add_option(
|
| 73 |
+
"--global",
|
| 74 |
+
dest="global_file",
|
| 75 |
+
action="store_true",
|
| 76 |
+
default=False,
|
| 77 |
+
help="Use the system-wide configuration file only",
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
self.cmd_opts.add_option(
|
| 81 |
+
"--user",
|
| 82 |
+
dest="user_file",
|
| 83 |
+
action="store_true",
|
| 84 |
+
default=False,
|
| 85 |
+
help="Use the user configuration file only",
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
self.cmd_opts.add_option(
|
| 89 |
+
"--site",
|
| 90 |
+
dest="site_file",
|
| 91 |
+
action="store_true",
|
| 92 |
+
default=False,
|
| 93 |
+
help="Use the current environment configuration file only",
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 97 |
+
|
| 98 |
+
def handler_map(self) -> dict[str, Callable[[Values, list[str]], None]]:
|
| 99 |
+
return {
|
| 100 |
+
"list": self.list_values,
|
| 101 |
+
"edit": self.open_in_editor,
|
| 102 |
+
"get": self.get_name,
|
| 103 |
+
"set": self.set_name_value,
|
| 104 |
+
"unset": self.unset_name,
|
| 105 |
+
"debug": self.list_config_values,
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 109 |
+
handler_map = self.handler_map()
|
| 110 |
+
|
| 111 |
+
# Determine action
|
| 112 |
+
if not args or args[0] not in handler_map:
|
| 113 |
+
logger.error(
|
| 114 |
+
"Need an action (%s) to perform.",
|
| 115 |
+
", ".join(sorted(handler_map)),
|
| 116 |
+
)
|
| 117 |
+
return ERROR
|
| 118 |
+
|
| 119 |
+
action = args[0]
|
| 120 |
+
|
| 121 |
+
# Determine which configuration files are to be loaded
|
| 122 |
+
# Depends on whether the command is modifying.
|
| 123 |
+
try:
|
| 124 |
+
load_only = self._determine_file(
|
| 125 |
+
options, need_value=(action in ["get", "set", "unset", "edit"])
|
| 126 |
+
)
|
| 127 |
+
except PipError as e:
|
| 128 |
+
logger.error(e.args[0])
|
| 129 |
+
return ERROR
|
| 130 |
+
|
| 131 |
+
# Load a new configuration
|
| 132 |
+
self.configuration = Configuration(
|
| 133 |
+
isolated=options.isolated_mode, load_only=load_only
|
| 134 |
+
)
|
| 135 |
+
self.configuration.load()
|
| 136 |
+
|
| 137 |
+
# Error handling happens here, not in the action-handlers.
|
| 138 |
+
try:
|
| 139 |
+
handler_map[action](options, args[1:])
|
| 140 |
+
except PipError as e:
|
| 141 |
+
logger.error(e.args[0])
|
| 142 |
+
return ERROR
|
| 143 |
+
|
| 144 |
+
return SUCCESS
|
| 145 |
+
|
| 146 |
+
def _determine_file(self, options: Values, need_value: bool) -> Kind | None:
|
| 147 |
+
file_options = [
|
| 148 |
+
key
|
| 149 |
+
for key, value in (
|
| 150 |
+
(kinds.USER, options.user_file),
|
| 151 |
+
(kinds.GLOBAL, options.global_file),
|
| 152 |
+
(kinds.SITE, options.site_file),
|
| 153 |
+
)
|
| 154 |
+
if value
|
| 155 |
+
]
|
| 156 |
+
|
| 157 |
+
if not file_options:
|
| 158 |
+
if not need_value:
|
| 159 |
+
return None
|
| 160 |
+
# Default to user, unless there's a site file.
|
| 161 |
+
elif any(
|
| 162 |
+
os.path.exists(site_config_file)
|
| 163 |
+
for site_config_file in get_configuration_files()[kinds.SITE]
|
| 164 |
+
):
|
| 165 |
+
return kinds.SITE
|
| 166 |
+
else:
|
| 167 |
+
return kinds.USER
|
| 168 |
+
elif len(file_options) == 1:
|
| 169 |
+
return file_options[0]
|
| 170 |
+
|
| 171 |
+
raise PipError(
|
| 172 |
+
"Need exactly one file to operate upon "
|
| 173 |
+
"(--user, --site, --global) to perform."
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
def list_values(self, options: Values, args: list[str]) -> None:
|
| 177 |
+
self._get_n_args(args, "list", n=0)
|
| 178 |
+
|
| 179 |
+
for key, value in sorted(self.configuration.items()):
|
| 180 |
+
for key, value in sorted(value.items()):
|
| 181 |
+
write_output("%s=%r", key, value)
|
| 182 |
+
|
| 183 |
+
def get_name(self, options: Values, args: list[str]) -> None:
|
| 184 |
+
key = self._get_n_args(args, "get [name]", n=1)
|
| 185 |
+
value = self.configuration.get_value(key)
|
| 186 |
+
|
| 187 |
+
write_output("%s", value)
|
| 188 |
+
|
| 189 |
+
def set_name_value(self, options: Values, args: list[str]) -> None:
|
| 190 |
+
key, value = self._get_n_args(args, "set [name] [value]", n=2)
|
| 191 |
+
self.configuration.set_value(key, value)
|
| 192 |
+
|
| 193 |
+
self._save_configuration()
|
| 194 |
+
|
| 195 |
+
def unset_name(self, options: Values, args: list[str]) -> None:
|
| 196 |
+
key = self._get_n_args(args, "unset [name]", n=1)
|
| 197 |
+
self.configuration.unset_value(key)
|
| 198 |
+
|
| 199 |
+
self._save_configuration()
|
| 200 |
+
|
| 201 |
+
def list_config_values(self, options: Values, args: list[str]) -> None:
|
| 202 |
+
"""List config key-value pairs across different config files"""
|
| 203 |
+
self._get_n_args(args, "debug", n=0)
|
| 204 |
+
|
| 205 |
+
self.print_env_var_values()
|
| 206 |
+
# Iterate over config files and print if they exist, and the
|
| 207 |
+
# key-value pairs present in them if they do
|
| 208 |
+
for variant, files in sorted(self.configuration.iter_config_files()):
|
| 209 |
+
write_output("%s:", variant)
|
| 210 |
+
for fname in files:
|
| 211 |
+
with indent_log():
|
| 212 |
+
file_exists = os.path.exists(fname)
|
| 213 |
+
write_output("%s, exists: %r", fname, file_exists)
|
| 214 |
+
if file_exists:
|
| 215 |
+
self.print_config_file_values(variant, fname)
|
| 216 |
+
|
| 217 |
+
def print_config_file_values(self, variant: Kind, fname: str) -> None:
|
| 218 |
+
"""Get key-value pairs from the file of a variant"""
|
| 219 |
+
for name, value in self.configuration.get_values_in_config(variant).items():
|
| 220 |
+
with indent_log():
|
| 221 |
+
if name == fname:
|
| 222 |
+
for confname, confvalue in value.items():
|
| 223 |
+
write_output("%s: %s", confname, confvalue)
|
| 224 |
+
|
| 225 |
+
def print_env_var_values(self) -> None:
|
| 226 |
+
"""Get key-values pairs present as environment variables"""
|
| 227 |
+
write_output("%s:", "env_var")
|
| 228 |
+
with indent_log():
|
| 229 |
+
for key, value in sorted(self.configuration.get_environ_vars()):
|
| 230 |
+
env_var = f"PIP_{key.upper()}"
|
| 231 |
+
write_output("%s=%r", env_var, value)
|
| 232 |
+
|
| 233 |
+
def open_in_editor(self, options: Values, args: list[str]) -> None:
|
| 234 |
+
editor = self._determine_editor(options)
|
| 235 |
+
|
| 236 |
+
fname = self.configuration.get_file_to_edit()
|
| 237 |
+
if fname is None:
|
| 238 |
+
raise PipError("Could not determine appropriate file.")
|
| 239 |
+
elif '"' in fname:
|
| 240 |
+
# This shouldn't happen, unless we see a username like that.
|
| 241 |
+
# If that happens, we'd appreciate a pull request fixing this.
|
| 242 |
+
raise PipError(
|
| 243 |
+
f'Can not open an editor for a file name containing "\n{fname}'
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
try:
|
| 247 |
+
subprocess.check_call(f'{editor} "{fname}"', shell=True)
|
| 248 |
+
except FileNotFoundError as e:
|
| 249 |
+
if not e.filename:
|
| 250 |
+
e.filename = editor
|
| 251 |
+
raise
|
| 252 |
+
except subprocess.CalledProcessError as e:
|
| 253 |
+
raise PipError(f"Editor Subprocess exited with exit code {e.returncode}")
|
| 254 |
+
|
| 255 |
+
def _get_n_args(self, args: list[str], example: str, n: int) -> Any:
|
| 256 |
+
"""Helper to make sure the command got the right number of arguments"""
|
| 257 |
+
if len(args) != n:
|
| 258 |
+
msg = (
|
| 259 |
+
f"Got unexpected number of arguments, expected {n}. "
|
| 260 |
+
f'(example: "{get_prog()} config {example}")'
|
| 261 |
+
)
|
| 262 |
+
raise PipError(msg)
|
| 263 |
+
|
| 264 |
+
if n == 1:
|
| 265 |
+
return args[0]
|
| 266 |
+
else:
|
| 267 |
+
return args
|
| 268 |
+
|
| 269 |
+
def _save_configuration(self) -> None:
|
| 270 |
+
# We successfully ran a modifying command. Need to save the
|
| 271 |
+
# configuration.
|
| 272 |
+
try:
|
| 273 |
+
self.configuration.save()
|
| 274 |
+
except Exception:
|
| 275 |
+
logger.exception(
|
| 276 |
+
"Unable to save configuration. Please report this as a bug."
|
| 277 |
+
)
|
| 278 |
+
raise PipError("Internal Error.")
|
| 279 |
+
|
| 280 |
+
def _determine_editor(self, options: Values) -> str:
|
| 281 |
+
if options.editor is not None:
|
| 282 |
+
return options.editor
|
| 283 |
+
elif "VISUAL" in os.environ:
|
| 284 |
+
return os.environ["VISUAL"]
|
| 285 |
+
elif "EDITOR" in os.environ:
|
| 286 |
+
return os.environ["EDITOR"]
|
| 287 |
+
else:
|
| 288 |
+
raise PipError("Could not determine editor to use.")
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/debug.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import locale
|
| 4 |
+
import logging
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
from optparse import Values
|
| 8 |
+
from types import ModuleType
|
| 9 |
+
from typing import Any
|
| 10 |
+
|
| 11 |
+
import pip._vendor
|
| 12 |
+
from pip._vendor.certifi import where
|
| 13 |
+
from pip._vendor.packaging.version import parse as parse_version
|
| 14 |
+
|
| 15 |
+
from pip._internal.cli import cmdoptions
|
| 16 |
+
from pip._internal.cli.base_command import Command
|
| 17 |
+
from pip._internal.cli.cmdoptions import make_target_python
|
| 18 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 19 |
+
from pip._internal.configuration import Configuration
|
| 20 |
+
from pip._internal.metadata import get_environment
|
| 21 |
+
from pip._internal.utils.compat import open_text_resource
|
| 22 |
+
from pip._internal.utils.logging import indent_log
|
| 23 |
+
from pip._internal.utils.misc import get_pip_version
|
| 24 |
+
|
| 25 |
+
logger = logging.getLogger(__name__)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def show_value(name: str, value: Any) -> None:
|
| 29 |
+
logger.info("%s: %s", name, value)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def show_sys_implementation() -> None:
|
| 33 |
+
logger.info("sys.implementation:")
|
| 34 |
+
implementation_name = sys.implementation.name
|
| 35 |
+
with indent_log():
|
| 36 |
+
show_value("name", implementation_name)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def create_vendor_txt_map() -> dict[str, str]:
|
| 40 |
+
with open_text_resource("pip._vendor", "vendor.txt") as f:
|
| 41 |
+
# Purge non version specifying lines.
|
| 42 |
+
# Also, remove any space prefix or suffixes (including comments).
|
| 43 |
+
lines = [
|
| 44 |
+
line.strip().split(" ", 1)[0] for line in f.readlines() if "==" in line
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
# Transform into "module" -> version dict.
|
| 48 |
+
return dict(line.split("==", 1) for line in lines)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def get_module_from_module_name(module_name: str) -> ModuleType | None:
|
| 52 |
+
# Module name can be uppercase in vendor.txt for some reason...
|
| 53 |
+
module_name = module_name.lower().replace("-", "_")
|
| 54 |
+
# PATCH: setuptools is actually only pkg_resources.
|
| 55 |
+
if module_name == "setuptools":
|
| 56 |
+
module_name = "pkg_resources"
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
__import__(f"pip._vendor.{module_name}", globals(), locals(), level=0)
|
| 60 |
+
return getattr(pip._vendor, module_name)
|
| 61 |
+
except ImportError:
|
| 62 |
+
# We allow 'truststore' to fail to import due
|
| 63 |
+
# to being unavailable on Python 3.9 and earlier.
|
| 64 |
+
if module_name == "truststore" and sys.version_info < (3, 10):
|
| 65 |
+
return None
|
| 66 |
+
raise
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def get_vendor_version_from_module(module_name: str) -> str | None:
|
| 70 |
+
module = get_module_from_module_name(module_name)
|
| 71 |
+
version = getattr(module, "__version__", None)
|
| 72 |
+
|
| 73 |
+
if module and not version:
|
| 74 |
+
# Try to find version in debundled module info.
|
| 75 |
+
assert module.__file__ is not None
|
| 76 |
+
env = get_environment([os.path.dirname(module.__file__)])
|
| 77 |
+
dist = env.get_distribution(module_name)
|
| 78 |
+
if dist:
|
| 79 |
+
version = str(dist.version)
|
| 80 |
+
|
| 81 |
+
return version
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def show_actual_vendor_versions(vendor_txt_versions: dict[str, str]) -> None:
|
| 85 |
+
"""Log the actual version and print extra info if there is
|
| 86 |
+
a conflict or if the actual version could not be imported.
|
| 87 |
+
"""
|
| 88 |
+
for module_name, expected_version in vendor_txt_versions.items():
|
| 89 |
+
extra_message = ""
|
| 90 |
+
actual_version = get_vendor_version_from_module(module_name)
|
| 91 |
+
if not actual_version:
|
| 92 |
+
extra_message = (
|
| 93 |
+
" (Unable to locate actual module version, using"
|
| 94 |
+
" vendor.txt specified version)"
|
| 95 |
+
)
|
| 96 |
+
actual_version = expected_version
|
| 97 |
+
elif parse_version(actual_version) != parse_version(expected_version):
|
| 98 |
+
extra_message = (
|
| 99 |
+
" (CONFLICT: vendor.txt suggests version should"
|
| 100 |
+
f" be {expected_version})"
|
| 101 |
+
)
|
| 102 |
+
logger.info("%s==%s%s", module_name, actual_version, extra_message)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def show_vendor_versions() -> None:
|
| 106 |
+
logger.info("vendored library versions:")
|
| 107 |
+
|
| 108 |
+
vendor_txt_versions = create_vendor_txt_map()
|
| 109 |
+
with indent_log():
|
| 110 |
+
show_actual_vendor_versions(vendor_txt_versions)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def show_tags(options: Values) -> None:
|
| 114 |
+
tag_limit = 10
|
| 115 |
+
|
| 116 |
+
target_python = make_target_python(options)
|
| 117 |
+
tags = target_python.get_sorted_tags()
|
| 118 |
+
|
| 119 |
+
# Display the target options that were explicitly provided.
|
| 120 |
+
formatted_target = target_python.format_given()
|
| 121 |
+
suffix = ""
|
| 122 |
+
if formatted_target:
|
| 123 |
+
suffix = f" (target: {formatted_target})"
|
| 124 |
+
|
| 125 |
+
msg = f"Compatible tags: {len(tags)}{suffix}"
|
| 126 |
+
logger.info(msg)
|
| 127 |
+
|
| 128 |
+
if options.verbose < 1 and len(tags) > tag_limit:
|
| 129 |
+
tags_limited = True
|
| 130 |
+
tags = tags[:tag_limit]
|
| 131 |
+
else:
|
| 132 |
+
tags_limited = False
|
| 133 |
+
|
| 134 |
+
with indent_log():
|
| 135 |
+
for tag in tags:
|
| 136 |
+
logger.info(str(tag))
|
| 137 |
+
|
| 138 |
+
if tags_limited:
|
| 139 |
+
msg = f"...\n[First {tag_limit} tags shown. Pass --verbose to show all.]"
|
| 140 |
+
logger.info(msg)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def ca_bundle_info(config: Configuration) -> str:
|
| 144 |
+
levels = {key.split(".", 1)[0] for key, _ in config.items()}
|
| 145 |
+
if not levels:
|
| 146 |
+
return "Not specified"
|
| 147 |
+
|
| 148 |
+
levels_that_override_global = ["install", "wheel", "download"]
|
| 149 |
+
global_overriding_level = [
|
| 150 |
+
level for level in levels if level in levels_that_override_global
|
| 151 |
+
]
|
| 152 |
+
if not global_overriding_level:
|
| 153 |
+
return "global"
|
| 154 |
+
|
| 155 |
+
if "global" in levels:
|
| 156 |
+
levels.remove("global")
|
| 157 |
+
return ", ".join(levels)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class DebugCommand(Command):
|
| 161 |
+
"""
|
| 162 |
+
Display debug information.
|
| 163 |
+
"""
|
| 164 |
+
|
| 165 |
+
usage = """
|
| 166 |
+
%prog <options>"""
|
| 167 |
+
ignore_require_venv = True
|
| 168 |
+
|
| 169 |
+
def add_options(self) -> None:
|
| 170 |
+
cmdoptions.add_target_python_options(self.cmd_opts)
|
| 171 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 172 |
+
self.parser.config.load()
|
| 173 |
+
|
| 174 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 175 |
+
logger.warning(
|
| 176 |
+
"This command is only meant for debugging. "
|
| 177 |
+
"Do not use this with automation for parsing and getting these "
|
| 178 |
+
"details, since the output and options of this command may "
|
| 179 |
+
"change without notice."
|
| 180 |
+
)
|
| 181 |
+
show_value("pip version", get_pip_version())
|
| 182 |
+
show_value("sys.version", sys.version)
|
| 183 |
+
show_value("sys.executable", sys.executable)
|
| 184 |
+
show_value("sys.getdefaultencoding", sys.getdefaultencoding())
|
| 185 |
+
show_value("sys.getfilesystemencoding", sys.getfilesystemencoding())
|
| 186 |
+
show_value(
|
| 187 |
+
"locale.getpreferredencoding",
|
| 188 |
+
locale.getpreferredencoding(),
|
| 189 |
+
)
|
| 190 |
+
show_value("sys.platform", sys.platform)
|
| 191 |
+
show_sys_implementation()
|
| 192 |
+
|
| 193 |
+
show_value("'cert' config value", ca_bundle_info(self.parser.config))
|
| 194 |
+
show_value("REQUESTS_CA_BUNDLE", os.environ.get("REQUESTS_CA_BUNDLE"))
|
| 195 |
+
show_value("CURL_CA_BUNDLE", os.environ.get("CURL_CA_BUNDLE"))
|
| 196 |
+
show_value("pip._vendor.certifi.where()", where())
|
| 197 |
+
show_value("pip._vendor.DEBUNDLED", pip._vendor.DEBUNDLED)
|
| 198 |
+
|
| 199 |
+
show_vendor_versions()
|
| 200 |
+
|
| 201 |
+
show_tags(options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
| 5 |
+
from pip._internal.cli import cmdoptions
|
| 6 |
+
from pip._internal.cli.cmdoptions import make_target_python
|
| 7 |
+
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
|
| 8 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 9 |
+
from pip._internal.operations.build.build_tracker import get_build_tracker
|
| 10 |
+
from pip._internal.utils.misc import ensure_dir, normalize_path, write_output
|
| 11 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 12 |
+
|
| 13 |
+
logger = logging.getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class DownloadCommand(RequirementCommand):
|
| 17 |
+
"""
|
| 18 |
+
Download packages from:
|
| 19 |
+
|
| 20 |
+
- PyPI (and other indexes) using requirement specifiers.
|
| 21 |
+
- VCS project urls.
|
| 22 |
+
- Local project directories.
|
| 23 |
+
- Local or remote source archives.
|
| 24 |
+
|
| 25 |
+
pip also supports downloading from "requirements files", which provide
|
| 26 |
+
an easy way to specify a whole environment to be downloaded.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
usage = """
|
| 30 |
+
%prog [options] <requirement specifier> [package-index-options] ...
|
| 31 |
+
%prog [options] -r <requirements file> [package-index-options] ...
|
| 32 |
+
%prog [options] <vcs project url> ...
|
| 33 |
+
%prog [options] <local project path> ...
|
| 34 |
+
%prog [options] <archive url/path> ..."""
|
| 35 |
+
|
| 36 |
+
def add_options(self) -> None:
|
| 37 |
+
self.cmd_opts.add_option(cmdoptions.constraints())
|
| 38 |
+
self.cmd_opts.add_option(cmdoptions.build_constraints())
|
| 39 |
+
self.cmd_opts.add_option(cmdoptions.requirements())
|
| 40 |
+
self.cmd_opts.add_option(cmdoptions.requirements_from_scripts())
|
| 41 |
+
self.cmd_opts.add_option(cmdoptions.no_deps())
|
| 42 |
+
self.cmd_opts.add_option(cmdoptions.src())
|
| 43 |
+
self.cmd_opts.add_option(cmdoptions.require_hashes())
|
| 44 |
+
self.cmd_opts.add_option(cmdoptions.progress_bar())
|
| 45 |
+
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
|
| 46 |
+
self.cmd_opts.add_option(cmdoptions.use_pep517())
|
| 47 |
+
self.cmd_opts.add_option(cmdoptions.check_build_deps())
|
| 48 |
+
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
| 49 |
+
|
| 50 |
+
self.cmd_opts.add_option(
|
| 51 |
+
"-d",
|
| 52 |
+
"--dest",
|
| 53 |
+
"--destination-dir",
|
| 54 |
+
"--destination-directory",
|
| 55 |
+
dest="download_dir",
|
| 56 |
+
metavar="dir",
|
| 57 |
+
default=os.curdir,
|
| 58 |
+
help="Download packages into <dir>.",
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
cmdoptions.add_target_python_options(self.cmd_opts)
|
| 62 |
+
|
| 63 |
+
index_opts = cmdoptions.make_option_group(
|
| 64 |
+
cmdoptions.index_group,
|
| 65 |
+
self.parser,
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
selection_opts = cmdoptions.make_option_group(
|
| 69 |
+
cmdoptions.package_selection_group,
|
| 70 |
+
self.parser,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
self.parser.insert_option_group(0, index_opts)
|
| 74 |
+
self.parser.insert_option_group(0, selection_opts)
|
| 75 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 76 |
+
|
| 77 |
+
@with_cleanup
|
| 78 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 79 |
+
options.ignore_installed = True
|
| 80 |
+
# editable doesn't really make sense for `pip download`, but the bowels
|
| 81 |
+
# of the RequirementSet code require that property.
|
| 82 |
+
options.editables = []
|
| 83 |
+
|
| 84 |
+
cmdoptions.check_dist_restriction(options)
|
| 85 |
+
cmdoptions.check_build_constraints(options)
|
| 86 |
+
cmdoptions.check_release_control_exclusive(options)
|
| 87 |
+
|
| 88 |
+
options.download_dir = normalize_path(options.download_dir)
|
| 89 |
+
ensure_dir(options.download_dir)
|
| 90 |
+
|
| 91 |
+
session = self.get_default_session(options)
|
| 92 |
+
|
| 93 |
+
target_python = make_target_python(options)
|
| 94 |
+
finder = self._build_package_finder(
|
| 95 |
+
options=options,
|
| 96 |
+
session=session,
|
| 97 |
+
target_python=target_python,
|
| 98 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
build_tracker = self.enter_context(get_build_tracker())
|
| 102 |
+
|
| 103 |
+
directory = TempDirectory(
|
| 104 |
+
delete=not options.no_clean,
|
| 105 |
+
kind="download",
|
| 106 |
+
globally_managed=True,
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
reqs = self.get_requirements(args, options, finder, session)
|
| 110 |
+
|
| 111 |
+
preparer = self.make_requirement_preparer(
|
| 112 |
+
temp_build_dir=directory,
|
| 113 |
+
options=options,
|
| 114 |
+
build_tracker=build_tracker,
|
| 115 |
+
session=session,
|
| 116 |
+
finder=finder,
|
| 117 |
+
download_dir=options.download_dir,
|
| 118 |
+
use_user_site=False,
|
| 119 |
+
verbosity=self.verbosity,
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
resolver = self.make_resolver(
|
| 123 |
+
preparer=preparer,
|
| 124 |
+
finder=finder,
|
| 125 |
+
options=options,
|
| 126 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 127 |
+
py_version_info=options.python_version,
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
self.trace_basic_info(finder)
|
| 131 |
+
|
| 132 |
+
requirement_set = resolver.resolve(reqs, check_supported_wheels=True)
|
| 133 |
+
|
| 134 |
+
preparer.prepare_linked_requirements_more(requirement_set.requirements.values())
|
| 135 |
+
|
| 136 |
+
downloaded: list[str] = []
|
| 137 |
+
for req in requirement_set.requirements.values():
|
| 138 |
+
if req.satisfied_by is None:
|
| 139 |
+
assert req.name is not None
|
| 140 |
+
preparer.save_linked_requirement(req)
|
| 141 |
+
downloaded.append(req.name)
|
| 142 |
+
|
| 143 |
+
if downloaded:
|
| 144 |
+
write_output("Successfully downloaded %s", " ".join(downloaded))
|
| 145 |
+
|
| 146 |
+
return SUCCESS
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/freeze.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from optparse import Values
|
| 3 |
+
|
| 4 |
+
from pip._internal.cli import cmdoptions
|
| 5 |
+
from pip._internal.cli.base_command import Command
|
| 6 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 7 |
+
from pip._internal.operations.freeze import freeze
|
| 8 |
+
from pip._internal.utils.compat import stdlib_pkgs
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def _should_suppress_build_backends() -> bool:
|
| 12 |
+
return sys.version_info < (3, 12)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _dev_pkgs() -> set[str]:
|
| 16 |
+
pkgs = {"pip"}
|
| 17 |
+
|
| 18 |
+
if _should_suppress_build_backends():
|
| 19 |
+
pkgs |= {"setuptools", "distribute", "wheel"}
|
| 20 |
+
|
| 21 |
+
return pkgs
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class FreezeCommand(Command):
|
| 25 |
+
"""
|
| 26 |
+
Output installed packages in requirements format.
|
| 27 |
+
|
| 28 |
+
packages are listed in a case-insensitive sorted order.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
ignore_require_venv = True
|
| 32 |
+
usage = """
|
| 33 |
+
%prog [options]"""
|
| 34 |
+
|
| 35 |
+
def add_options(self) -> None:
|
| 36 |
+
self.cmd_opts.add_option(
|
| 37 |
+
"-r",
|
| 38 |
+
"--requirement",
|
| 39 |
+
dest="requirements",
|
| 40 |
+
action="append",
|
| 41 |
+
default=[],
|
| 42 |
+
metavar="file",
|
| 43 |
+
help=(
|
| 44 |
+
"Use the order in the given requirements file and its "
|
| 45 |
+
"comments when generating output. This option can be "
|
| 46 |
+
"used multiple times."
|
| 47 |
+
),
|
| 48 |
+
)
|
| 49 |
+
self.cmd_opts.add_option(
|
| 50 |
+
"-l",
|
| 51 |
+
"--local",
|
| 52 |
+
dest="local",
|
| 53 |
+
action="store_true",
|
| 54 |
+
default=False,
|
| 55 |
+
help=(
|
| 56 |
+
"If in a virtualenv that has global access, do not output "
|
| 57 |
+
"globally-installed packages."
|
| 58 |
+
),
|
| 59 |
+
)
|
| 60 |
+
self.cmd_opts.add_option(
|
| 61 |
+
"--user",
|
| 62 |
+
dest="user",
|
| 63 |
+
action="store_true",
|
| 64 |
+
default=False,
|
| 65 |
+
help="Only output packages installed in user-site.",
|
| 66 |
+
)
|
| 67 |
+
self.cmd_opts.add_option(cmdoptions.list_path())
|
| 68 |
+
self.cmd_opts.add_option(
|
| 69 |
+
"--all",
|
| 70 |
+
dest="freeze_all",
|
| 71 |
+
action="store_true",
|
| 72 |
+
help=(
|
| 73 |
+
"Do not skip these packages in the output:"
|
| 74 |
+
" {}".format(", ".join(_dev_pkgs()))
|
| 75 |
+
),
|
| 76 |
+
)
|
| 77 |
+
self.cmd_opts.add_option(
|
| 78 |
+
"--exclude-editable",
|
| 79 |
+
dest="exclude_editable",
|
| 80 |
+
action="store_true",
|
| 81 |
+
help="Exclude editable package from output.",
|
| 82 |
+
)
|
| 83 |
+
self.cmd_opts.add_option(cmdoptions.list_exclude())
|
| 84 |
+
|
| 85 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 86 |
+
|
| 87 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 88 |
+
skip = set(stdlib_pkgs)
|
| 89 |
+
if not options.freeze_all:
|
| 90 |
+
skip.update(_dev_pkgs())
|
| 91 |
+
|
| 92 |
+
if options.excludes:
|
| 93 |
+
skip.update(options.excludes)
|
| 94 |
+
|
| 95 |
+
cmdoptions.check_list_path_option(options)
|
| 96 |
+
|
| 97 |
+
for line in freeze(
|
| 98 |
+
requirement=options.requirements,
|
| 99 |
+
local_only=options.local,
|
| 100 |
+
user_only=options.user,
|
| 101 |
+
paths=options.path,
|
| 102 |
+
isolated=options.isolated_mode,
|
| 103 |
+
skip=skip,
|
| 104 |
+
exclude_editable=options.exclude_editable,
|
| 105 |
+
):
|
| 106 |
+
sys.stdout.write(line + "\n")
|
| 107 |
+
return SUCCESS
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/hash.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
+
import logging
|
| 3 |
+
import sys
|
| 4 |
+
from optparse import Values
|
| 5 |
+
|
| 6 |
+
from pip._internal.cli.base_command import Command
|
| 7 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 8 |
+
from pip._internal.utils.hashes import FAVORITE_HASH, STRONG_HASHES
|
| 9 |
+
from pip._internal.utils.misc import read_chunks, write_output
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class HashCommand(Command):
|
| 15 |
+
"""
|
| 16 |
+
Compute a hash of a local package archive.
|
| 17 |
+
|
| 18 |
+
These can be used with --hash in a requirements file to do repeatable
|
| 19 |
+
installs.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
usage = "%prog [options] <file> ..."
|
| 23 |
+
ignore_require_venv = True
|
| 24 |
+
|
| 25 |
+
def add_options(self) -> None:
|
| 26 |
+
self.cmd_opts.add_option(
|
| 27 |
+
"-a",
|
| 28 |
+
"--algorithm",
|
| 29 |
+
dest="algorithm",
|
| 30 |
+
choices=STRONG_HASHES,
|
| 31 |
+
action="store",
|
| 32 |
+
default=FAVORITE_HASH,
|
| 33 |
+
help="The hash algorithm to use: one of {}".format(
|
| 34 |
+
", ".join(STRONG_HASHES)
|
| 35 |
+
),
|
| 36 |
+
)
|
| 37 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 38 |
+
|
| 39 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 40 |
+
if not args:
|
| 41 |
+
self.parser.print_usage(sys.stderr)
|
| 42 |
+
return ERROR
|
| 43 |
+
|
| 44 |
+
algorithm = options.algorithm
|
| 45 |
+
for path in args:
|
| 46 |
+
write_output(
|
| 47 |
+
"%s:\n--hash=%s:%s", path, algorithm, _hash_of_file(path, algorithm)
|
| 48 |
+
)
|
| 49 |
+
return SUCCESS
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def _hash_of_file(path: str, algorithm: str) -> str:
|
| 53 |
+
"""Return the hash digest of a file."""
|
| 54 |
+
with open(path, "rb") as archive:
|
| 55 |
+
hash = hashlib.new(algorithm)
|
| 56 |
+
for chunk in read_chunks(archive):
|
| 57 |
+
hash.update(chunk)
|
| 58 |
+
return hash.hexdigest()
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/help.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from optparse import Values
|
| 2 |
+
|
| 3 |
+
from pip._internal.cli.base_command import Command
|
| 4 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 5 |
+
from pip._internal.exceptions import CommandError
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class HelpCommand(Command):
|
| 9 |
+
"""Show help for commands"""
|
| 10 |
+
|
| 11 |
+
usage = """
|
| 12 |
+
%prog <command>"""
|
| 13 |
+
ignore_require_venv = True
|
| 14 |
+
|
| 15 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 16 |
+
from pip._internal.commands import (
|
| 17 |
+
commands_dict,
|
| 18 |
+
create_command,
|
| 19 |
+
get_similar_commands,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
# 'pip help' with no args is handled by pip.__init__.parseopt()
|
| 24 |
+
cmd_name = args[0] # the command we need help for
|
| 25 |
+
except IndexError:
|
| 26 |
+
return SUCCESS
|
| 27 |
+
|
| 28 |
+
if cmd_name not in commands_dict:
|
| 29 |
+
guess = get_similar_commands(cmd_name)
|
| 30 |
+
|
| 31 |
+
msg = [f'unknown command "{cmd_name}"']
|
| 32 |
+
if guess:
|
| 33 |
+
msg.append(f'maybe you meant "{guess}"')
|
| 34 |
+
|
| 35 |
+
raise CommandError(" - ".join(msg))
|
| 36 |
+
|
| 37 |
+
command = create_command(cmd_name)
|
| 38 |
+
command.parser.print_help()
|
| 39 |
+
|
| 40 |
+
return SUCCESS
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/index.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import logging
|
| 5 |
+
from collections.abc import Iterable
|
| 6 |
+
from optparse import Values
|
| 7 |
+
from typing import Any, Callable
|
| 8 |
+
|
| 9 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 10 |
+
from pip._vendor.packaging.version import Version
|
| 11 |
+
|
| 12 |
+
from pip._internal.cli import cmdoptions
|
| 13 |
+
from pip._internal.cli.req_command import IndexGroupCommand
|
| 14 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 15 |
+
from pip._internal.commands.search import (
|
| 16 |
+
get_installed_distribution,
|
| 17 |
+
print_dist_installation_info,
|
| 18 |
+
)
|
| 19 |
+
from pip._internal.exceptions import CommandError, DistributionNotFound, PipError
|
| 20 |
+
from pip._internal.index.collector import LinkCollector
|
| 21 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 22 |
+
from pip._internal.models.selection_prefs import SelectionPreferences
|
| 23 |
+
from pip._internal.models.target_python import TargetPython
|
| 24 |
+
from pip._internal.network.session import PipSession
|
| 25 |
+
from pip._internal.utils.misc import write_output
|
| 26 |
+
|
| 27 |
+
logger = logging.getLogger(__name__)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class IndexCommand(IndexGroupCommand):
|
| 31 |
+
"""
|
| 32 |
+
Inspect information available from package indexes.
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
ignore_require_venv = True
|
| 36 |
+
usage = """
|
| 37 |
+
%prog versions <package>
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
def add_options(self) -> None:
|
| 41 |
+
cmdoptions.add_target_python_options(self.cmd_opts)
|
| 42 |
+
|
| 43 |
+
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
| 44 |
+
self.cmd_opts.add_option(cmdoptions.json())
|
| 45 |
+
|
| 46 |
+
index_opts = cmdoptions.make_option_group(
|
| 47 |
+
cmdoptions.index_group,
|
| 48 |
+
self.parser,
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
selection_opts = cmdoptions.make_option_group(
|
| 52 |
+
cmdoptions.package_selection_group,
|
| 53 |
+
self.parser,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
self.parser.insert_option_group(0, index_opts)
|
| 57 |
+
self.parser.insert_option_group(0, selection_opts)
|
| 58 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 59 |
+
|
| 60 |
+
def handler_map(self) -> dict[str, Callable[[Values, list[str]], None]]:
|
| 61 |
+
return {
|
| 62 |
+
"versions": self.get_available_package_versions,
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 66 |
+
cmdoptions.check_release_control_exclusive(options)
|
| 67 |
+
|
| 68 |
+
handler_map = self.handler_map()
|
| 69 |
+
|
| 70 |
+
# Determine action
|
| 71 |
+
if not args or args[0] not in handler_map:
|
| 72 |
+
logger.error(
|
| 73 |
+
"Need an action (%s) to perform.",
|
| 74 |
+
", ".join(sorted(handler_map)),
|
| 75 |
+
)
|
| 76 |
+
return ERROR
|
| 77 |
+
|
| 78 |
+
action = args[0]
|
| 79 |
+
|
| 80 |
+
# Error handling happens here, not in the action-handlers.
|
| 81 |
+
try:
|
| 82 |
+
handler_map[action](options, args[1:])
|
| 83 |
+
except PipError as e:
|
| 84 |
+
logger.error(e.args[0])
|
| 85 |
+
return ERROR
|
| 86 |
+
|
| 87 |
+
return SUCCESS
|
| 88 |
+
|
| 89 |
+
def _build_package_finder(
|
| 90 |
+
self,
|
| 91 |
+
options: Values,
|
| 92 |
+
session: PipSession,
|
| 93 |
+
target_python: TargetPython | None = None,
|
| 94 |
+
ignore_requires_python: bool | None = None,
|
| 95 |
+
) -> PackageFinder:
|
| 96 |
+
"""
|
| 97 |
+
Create a package finder appropriate to the index command.
|
| 98 |
+
"""
|
| 99 |
+
link_collector = LinkCollector.create(session, options=options)
|
| 100 |
+
|
| 101 |
+
# Pass allow_yanked=False to ignore yanked versions.
|
| 102 |
+
selection_prefs = SelectionPreferences(
|
| 103 |
+
allow_yanked=False,
|
| 104 |
+
release_control=options.release_control,
|
| 105 |
+
format_control=options.format_control,
|
| 106 |
+
ignore_requires_python=ignore_requires_python,
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
return PackageFinder.create(
|
| 110 |
+
link_collector=link_collector,
|
| 111 |
+
selection_prefs=selection_prefs,
|
| 112 |
+
target_python=target_python,
|
| 113 |
+
uploaded_prior_to=options.uploaded_prior_to,
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
def get_available_package_versions(self, options: Values, args: list[Any]) -> None:
|
| 117 |
+
if len(args) != 1:
|
| 118 |
+
raise CommandError("You need to specify exactly one argument")
|
| 119 |
+
|
| 120 |
+
target_python = cmdoptions.make_target_python(options)
|
| 121 |
+
query = args[0]
|
| 122 |
+
|
| 123 |
+
with self._build_session(options) as session:
|
| 124 |
+
finder = self._build_package_finder(
|
| 125 |
+
options=options,
|
| 126 |
+
session=session,
|
| 127 |
+
target_python=target_python,
|
| 128 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
versions: Iterable[Version] = (
|
| 132 |
+
candidate.version for candidate in finder.find_all_candidates(query)
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
if self.should_exclude_prerelease(options, canonicalize_name(query)):
|
| 136 |
+
versions = (
|
| 137 |
+
version for version in versions if not version.is_prerelease
|
| 138 |
+
)
|
| 139 |
+
versions = set(versions)
|
| 140 |
+
|
| 141 |
+
if not versions:
|
| 142 |
+
raise DistributionNotFound(
|
| 143 |
+
f"No matching distribution found for {query}"
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
formatted_versions = [str(ver) for ver in sorted(versions, reverse=True)]
|
| 147 |
+
latest = formatted_versions[0]
|
| 148 |
+
|
| 149 |
+
dist = get_installed_distribution(query)
|
| 150 |
+
|
| 151 |
+
if options.json:
|
| 152 |
+
structured_output = {
|
| 153 |
+
"name": query,
|
| 154 |
+
"versions": formatted_versions,
|
| 155 |
+
"latest": latest,
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
if dist is not None:
|
| 159 |
+
structured_output["installed_version"] = str(dist.version)
|
| 160 |
+
|
| 161 |
+
write_output(json.dumps(structured_output))
|
| 162 |
+
|
| 163 |
+
else:
|
| 164 |
+
write_output(f"{query} ({latest})")
|
| 165 |
+
write_output("Available versions: {}".format(", ".join(formatted_versions)))
|
| 166 |
+
print_dist_installation_info(latest, dist)
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/inspect.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from optparse import Values
|
| 3 |
+
from typing import Any
|
| 4 |
+
|
| 5 |
+
from pip._vendor.packaging.markers import default_environment
|
| 6 |
+
from pip._vendor.rich import print_json
|
| 7 |
+
|
| 8 |
+
from pip import __version__
|
| 9 |
+
from pip._internal.cli import cmdoptions
|
| 10 |
+
from pip._internal.cli.base_command import Command
|
| 11 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 12 |
+
from pip._internal.metadata import BaseDistribution, get_environment
|
| 13 |
+
from pip._internal.utils.compat import stdlib_pkgs
|
| 14 |
+
from pip._internal.utils.urls import path_to_url
|
| 15 |
+
|
| 16 |
+
logger = logging.getLogger(__name__)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class InspectCommand(Command):
|
| 20 |
+
"""
|
| 21 |
+
Inspect the content of a Python environment and produce a report in JSON format.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
ignore_require_venv = True
|
| 25 |
+
usage = """
|
| 26 |
+
%prog [options]"""
|
| 27 |
+
|
| 28 |
+
def add_options(self) -> None:
|
| 29 |
+
self.cmd_opts.add_option(
|
| 30 |
+
"--local",
|
| 31 |
+
action="store_true",
|
| 32 |
+
default=False,
|
| 33 |
+
help=(
|
| 34 |
+
"If in a virtualenv that has global access, do not list "
|
| 35 |
+
"globally-installed packages."
|
| 36 |
+
),
|
| 37 |
+
)
|
| 38 |
+
self.cmd_opts.add_option(
|
| 39 |
+
"--user",
|
| 40 |
+
dest="user",
|
| 41 |
+
action="store_true",
|
| 42 |
+
default=False,
|
| 43 |
+
help="Only output packages installed in user-site.",
|
| 44 |
+
)
|
| 45 |
+
self.cmd_opts.add_option(cmdoptions.list_path())
|
| 46 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 47 |
+
|
| 48 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 49 |
+
cmdoptions.check_list_path_option(options)
|
| 50 |
+
dists = get_environment(options.path).iter_installed_distributions(
|
| 51 |
+
local_only=options.local,
|
| 52 |
+
user_only=options.user,
|
| 53 |
+
skip=set(stdlib_pkgs),
|
| 54 |
+
)
|
| 55 |
+
output = {
|
| 56 |
+
"version": "1",
|
| 57 |
+
"pip_version": __version__,
|
| 58 |
+
"installed": [self._dist_to_dict(dist) for dist in dists],
|
| 59 |
+
"environment": default_environment(),
|
| 60 |
+
# TODO tags? scheme?
|
| 61 |
+
}
|
| 62 |
+
print_json(data=output)
|
| 63 |
+
return SUCCESS
|
| 64 |
+
|
| 65 |
+
def _dist_to_dict(self, dist: BaseDistribution) -> dict[str, Any]:
|
| 66 |
+
res: dict[str, Any] = {
|
| 67 |
+
"metadata": dist.metadata_dict,
|
| 68 |
+
"metadata_location": dist.info_location,
|
| 69 |
+
}
|
| 70 |
+
# direct_url. Note that we don't have download_info (as in the installation
|
| 71 |
+
# report) since it is not recorded in installed metadata.
|
| 72 |
+
direct_url = dist.direct_url
|
| 73 |
+
if direct_url is not None:
|
| 74 |
+
res["direct_url"] = direct_url.to_dict()
|
| 75 |
+
else:
|
| 76 |
+
# Emulate direct_url for legacy editable installs.
|
| 77 |
+
editable_project_location = dist.editable_project_location
|
| 78 |
+
if editable_project_location is not None:
|
| 79 |
+
res["direct_url"] = {
|
| 80 |
+
"url": path_to_url(editable_project_location),
|
| 81 |
+
"dir_info": {
|
| 82 |
+
"editable": True,
|
| 83 |
+
},
|
| 84 |
+
}
|
| 85 |
+
# installer
|
| 86 |
+
installer = dist.installer
|
| 87 |
+
if dist.installer:
|
| 88 |
+
res["installer"] = installer
|
| 89 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PPRESS_HELP, Values
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 13 |
+
from pip._vendor.requests.exceptions import InvalidProxyURL
|
| 14 |
+
from pip._vendor.rich import print_json
|
| 15 |
+
|
| 16 |
+
# Eagerly import self_outdated_check to avoid crashes. Otherwise,
|
| 17 |
+
# this module would be imported *after* pip was replaced, resulting
|
| 18 |
+
# in crashes if the new self_outdated_check module was incompatible
|
| 19 |
+
# with the rest of pip that's already imported, or allowing a
|
| 20 |
+
# wheel to execute arbitrary code on install by replacing
|
| 21 |
+
# self_outdated_check.
|
| 22 |
+
import pip._internal.self_outdated_check # noqa: F401
|
| 23 |
+
from pip._internal.cache import WheelCache
|
| 24 |
+
from pip._internal.cli import cmdoptions
|
| 25 |
+
from pip._internal.cli.cmdoptions import make_target_python
|
| 26 |
+
from pip._internal.cli.req_command import (
|
| 27 |
+
RequirementCommand,
|
| 28 |
+
with_cleanup,
|
| 29 |
+
)
|
| 30 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 31 |
+
from pip._internal.exceptions import (
|
| 32 |
+
CommandError,
|
| 33 |
+
InstallationError,
|
| 34 |
+
InstallWheelBuildError,
|
| 35 |
+
)
|
| 36 |
+
from pip._internal.locations import get_scheme
|
| 37 |
+
from pip._internal.metadata import BaseEnvironment, get_environment
|
| 38 |
+
from pip._internal.models.installation_report import InstallationReport
|
| 39 |
+
from pip._internal.operations.build.build_tracker import get_build_tracker
|
| 40 |
+
from pip._internal.operations.check import ConflictDetails, check_install_conflicts
|
| 41 |
+
from pip._internal.req import InstallationResult, install_given_reqs
|
| 42 |
+
from pip._internal.req.req_install import (
|
| 43 |
+
InstallRequirement,
|
| 44 |
+
)
|
| 45 |
+
from pip._internal.utils.compat import WINDOWS
|
| 46 |
+
from pip._internal.utils.filesystem import test_writable_dir
|
| 47 |
+
from pip._internal.utils.logging import getLogger
|
| 48 |
+
from pip._internal.utils.misc import (
|
| 49 |
+
check_externally_managed,
|
| 50 |
+
ensure_dir,
|
| 51 |
+
get_pip_version,
|
| 52 |
+
protect_pip_from_modification_on_windows,
|
| 53 |
+
warn_if_run_as_root,
|
| 54 |
+
write_output,
|
| 55 |
+
)
|
| 56 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 57 |
+
from pip._internal.utils.virtualenv import (
|
| 58 |
+
running_under_virtualenv,
|
| 59 |
+
virtualenv_no_global,
|
| 60 |
+
)
|
| 61 |
+
from pip._internal.wheel_builder import build
|
| 62 |
+
|
| 63 |
+
logger = getLogger(__name__)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class InstallCommand(RequirementCommand):
|
| 67 |
+
"""
|
| 68 |
+
Install packages from:
|
| 69 |
+
|
| 70 |
+
- PyPI (and other indexes) using requirement specifiers.
|
| 71 |
+
- VCS project urls.
|
| 72 |
+
- Local project directories.
|
| 73 |
+
- Local or remote source archives.
|
| 74 |
+
|
| 75 |
+
pip also supports installing from "requirements files", which provide
|
| 76 |
+
an easy way to specify a whole environment to be installed.
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
usage = """
|
| 80 |
+
%prog [options] <requirement specifier> [package-index-options] ...
|
| 81 |
+
%prog [options] -r <requirements file> [package-index-options] ...
|
| 82 |
+
%prog [options] [-e] <vcs project url> ...
|
| 83 |
+
%prog [options] [-e] <local project path> ...
|
| 84 |
+
%prog [options] <archive url/path> ..."""
|
| 85 |
+
|
| 86 |
+
def add_options(self) -> None:
|
| 87 |
+
self.cmd_opts.add_option(cmdoptions.requirements())
|
| 88 |
+
self.cmd_opts.add_option(cmdoptions.constraints())
|
| 89 |
+
self.cmd_opts.add_option(cmdoptions.build_constraints())
|
| 90 |
+
self.cmd_opts.add_option(cmdoptions.requirements_from_scripts())
|
| 91 |
+
self.cmd_opts.add_option(cmdoptions.no_deps())
|
| 92 |
+
|
| 93 |
+
self.cmd_opts.add_option(cmdoptions.editable())
|
| 94 |
+
self.cmd_opts.add_option(
|
| 95 |
+
"--dry-run",
|
| 96 |
+
action="store_true",
|
| 97 |
+
dest="dry_run",
|
| 98 |
+
default=False,
|
| 99 |
+
help=(
|
| 100 |
+
"Don't actually install anything, just print what would be. "
|
| 101 |
+
"Can be used in combination with --ignore-installed "
|
| 102 |
+
"to 'resolve' the requirements."
|
| 103 |
+
),
|
| 104 |
+
)
|
| 105 |
+
self.cmd_opts.add_option(
|
| 106 |
+
"-t",
|
| 107 |
+
"--target",
|
| 108 |
+
dest="target_dir",
|
| 109 |
+
metavar="dir",
|
| 110 |
+
default=None,
|
| 111 |
+
help=(
|
| 112 |
+
"Install packages into <dir>. "
|
| 113 |
+
"By default this will not replace existing files/folders in "
|
| 114 |
+
"<dir>. Use --upgrade to replace existing packages in <dir> "
|
| 115 |
+
"with new versions."
|
| 116 |
+
),
|
| 117 |
+
)
|
| 118 |
+
cmdoptions.add_target_python_options(self.cmd_opts)
|
| 119 |
+
|
| 120 |
+
self.cmd_opts.add_option(
|
| 121 |
+
"--user",
|
| 122 |
+
dest="use_user_site",
|
| 123 |
+
action="store_true",
|
| 124 |
+
help=(
|
| 125 |
+
"Install to the Python user install directory for your "
|
| 126 |
+
"platform. Typically ~/.local/, or %APPDATA%\\Python on "
|
| 127 |
+
"Windows. (See the Python documentation for site.USER_BASE "
|
| 128 |
+
"for full details.)"
|
| 129 |
+
),
|
| 130 |
+
)
|
| 131 |
+
self.cmd_opts.add_option(
|
| 132 |
+
"--no-user",
|
| 133 |
+
dest="use_user_site",
|
| 134 |
+
action="store_false",
|
| 135 |
+
help=SUPPRESS_HELP,
|
| 136 |
+
)
|
| 137 |
+
self.cmd_opts.add_option(
|
| 138 |
+
"--root",
|
| 139 |
+
dest="root_path",
|
| 140 |
+
metavar="dir",
|
| 141 |
+
default=None,
|
| 142 |
+
help="Install everything relative to this alternate root directory.",
|
| 143 |
+
)
|
| 144 |
+
self.cmd_opts.add_option(
|
| 145 |
+
"--prefix",
|
| 146 |
+
dest="prefix_path",
|
| 147 |
+
metavar="dir",
|
| 148 |
+
default=None,
|
| 149 |
+
help=(
|
| 150 |
+
"Installation prefix where lib, bin and other top-level "
|
| 151 |
+
"folders are placed. Note that the resulting installation may "
|
| 152 |
+
"contain scripts and other resources which reference the "
|
| 153 |
+
"Python interpreter of pip, and not that of ``--prefix``. "
|
| 154 |
+
"See also the ``--python`` option if the intention is to "
|
| 155 |
+
"install packages into another (possibly pip-free) "
|
| 156 |
+
"environment."
|
| 157 |
+
),
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
self.cmd_opts.add_option(cmdoptions.src())
|
| 161 |
+
|
| 162 |
+
self.cmd_opts.add_option(
|
| 163 |
+
"-U",
|
| 164 |
+
"--upgrade",
|
| 165 |
+
dest="upgrade",
|
| 166 |
+
action="store_true",
|
| 167 |
+
help=(
|
| 168 |
+
"Upgrade all specified packages to the newest available "
|
| 169 |
+
"version. The handling of dependencies depends on the "
|
| 170 |
+
"upgrade-strategy used."
|
| 171 |
+
),
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
self.cmd_opts.add_option(
|
| 175 |
+
"--upgrade-strategy",
|
| 176 |
+
dest="upgrade_strategy",
|
| 177 |
+
default="only-if-needed",
|
| 178 |
+
choices=["only-if-needed", "eager"],
|
| 179 |
+
help=(
|
| 180 |
+
"Determines how dependency upgrading should be handled "
|
| 181 |
+
"[default: %default]. "
|
| 182 |
+
'"eager" - dependencies are upgraded regardless of '
|
| 183 |
+
"whether the currently installed version satisfies the "
|
| 184 |
+
"requirements of the upgraded package(s). "
|
| 185 |
+
'"only-if-needed" - are upgraded only when they do not '
|
| 186 |
+
"satisfy the requirements of the upgraded package(s)."
|
| 187 |
+
),
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
+
self.cmd_opts.add_option(
|
| 191 |
+
"--force-reinstall",
|
| 192 |
+
dest="force_reinstall",
|
| 193 |
+
action="store_true",
|
| 194 |
+
help="Reinstall all packages even if they are already up-to-date.",
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
self.cmd_opts.add_option(
|
| 198 |
+
"-I",
|
| 199 |
+
"--ignore-installed",
|
| 200 |
+
dest="ignore_installed",
|
| 201 |
+
action="store_true",
|
| 202 |
+
help=(
|
| 203 |
+
"Ignore the installed packages, overwriting them. "
|
| 204 |
+
"This can break your system if the existing package "
|
| 205 |
+
"is of a different version or was installed "
|
| 206 |
+
"with a different package manager!"
|
| 207 |
+
),
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
| 211 |
+
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
|
| 212 |
+
self.cmd_opts.add_option(cmdoptions.use_pep517())
|
| 213 |
+
self.cmd_opts.add_option(cmdoptions.check_build_deps())
|
| 214 |
+
self.cmd_opts.add_option(cmdoptions.override_externally_managed())
|
| 215 |
+
|
| 216 |
+
self.cmd_opts.add_option(cmdoptions.config_settings())
|
| 217 |
+
|
| 218 |
+
self.cmd_opts.add_option(
|
| 219 |
+
"--compile",
|
| 220 |
+
action="store_true",
|
| 221 |
+
dest="compile",
|
| 222 |
+
default=True,
|
| 223 |
+
help="Compile Python source files to bytecode",
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
self.cmd_opts.add_option(
|
| 227 |
+
"--no-compile",
|
| 228 |
+
action="store_false",
|
| 229 |
+
dest="compile",
|
| 230 |
+
help="Do not compile Python source files to bytecode",
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
self.cmd_opts.add_option(
|
| 234 |
+
"--no-warn-script-location",
|
| 235 |
+
action="store_false",
|
| 236 |
+
dest="warn_script_location",
|
| 237 |
+
default=True,
|
| 238 |
+
help="Do not warn when installing scripts outside PATH",
|
| 239 |
+
)
|
| 240 |
+
self.cmd_opts.add_option(
|
| 241 |
+
"--no-warn-conflicts",
|
| 242 |
+
action="store_false",
|
| 243 |
+
dest="warn_about_conflicts",
|
| 244 |
+
default=True,
|
| 245 |
+
help="Do not warn about broken dependencies",
|
| 246 |
+
)
|
| 247 |
+
self.cmd_opts.add_option(cmdoptions.require_hashes())
|
| 248 |
+
self.cmd_opts.add_option(cmdoptions.progress_bar())
|
| 249 |
+
self.cmd_opts.add_option(cmdoptions.root_user_action())
|
| 250 |
+
|
| 251 |
+
index_opts = cmdoptions.make_option_group(
|
| 252 |
+
cmdoptions.index_group,
|
| 253 |
+
self.parser,
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
selection_opts = cmdoptions.make_option_group(
|
| 257 |
+
cmdoptions.package_selection_group,
|
| 258 |
+
self.parser,
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
+
self.parser.insert_option_group(0, index_opts)
|
| 262 |
+
self.parser.insert_option_group(0, selection_opts)
|
| 263 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 264 |
+
|
| 265 |
+
self.cmd_opts.add_option(
|
| 266 |
+
"--report",
|
| 267 |
+
dest="json_report_file",
|
| 268 |
+
metavar="file",
|
| 269 |
+
default=None,
|
| 270 |
+
help=(
|
| 271 |
+
"Generate a JSON file describing what pip did to install "
|
| 272 |
+
"the provided requirements. "
|
| 273 |
+
"Can be used in combination with --dry-run and --ignore-installed "
|
| 274 |
+
"to 'resolve' the requirements. "
|
| 275 |
+
"When - is used as file name it writes to stdout. "
|
| 276 |
+
"When writing to stdout, please combine with the --quiet option "
|
| 277 |
+
"to avoid mixing pip logging output with JSON output."
|
| 278 |
+
),
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
@with_cleanup
|
| 282 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 283 |
+
if options.use_user_site and options.target_dir is not None:
|
| 284 |
+
raise CommandError("Can not combine '--user' and '--target'")
|
| 285 |
+
|
| 286 |
+
# Check whether the environment we're installing into is externally
|
| 287 |
+
# managed, as specified in PEP 668. Specifying --root, --target, or
|
| 288 |
+
# --prefix disables the check, since there's no reliable way to locate
|
| 289 |
+
# the EXTERNALLY-MANAGED file for those cases. An exception is also
|
| 290 |
+
# made specifically for "--dry-run --report" for convenience.
|
| 291 |
+
installing_into_current_environment = (
|
| 292 |
+
not (options.dry_run and options.json_report_file)
|
| 293 |
+
and options.root_path is None
|
| 294 |
+
and options.target_dir is None
|
| 295 |
+
and options.prefix_path is None
|
| 296 |
+
)
|
| 297 |
+
if (
|
| 298 |
+
installing_into_current_environment
|
| 299 |
+
and not options.override_externally_managed
|
| 300 |
+
):
|
| 301 |
+
check_externally_managed()
|
| 302 |
+
|
| 303 |
+
upgrade_strategy = "to-satisfy-only"
|
| 304 |
+
if options.upgrade:
|
| 305 |
+
upgrade_strategy = options.upgrade_strategy
|
| 306 |
+
|
| 307 |
+
cmdoptions.check_build_constraints(options)
|
| 308 |
+
cmdoptions.check_dist_restriction(options, check_target=True)
|
| 309 |
+
cmdoptions.check_release_control_exclusive(options)
|
| 310 |
+
|
| 311 |
+
logger.verbose("Using %s", get_pip_version())
|
| 312 |
+
options.use_user_site = decide_user_install(
|
| 313 |
+
options.use_user_site,
|
| 314 |
+
prefix_path=options.prefix_path,
|
| 315 |
+
target_dir=options.target_dir,
|
| 316 |
+
root_path=options.root_path,
|
| 317 |
+
isolated_mode=options.isolated_mode,
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
target_temp_dir: TempDirectory | None = None
|
| 321 |
+
target_temp_dir_path: str | None = None
|
| 322 |
+
if options.target_dir:
|
| 323 |
+
options.ignore_installed = True
|
| 324 |
+
options.target_dir = os.path.abspath(options.target_dir)
|
| 325 |
+
if (
|
| 326 |
+
# fmt: off
|
| 327 |
+
os.path.exists(options.target_dir) and
|
| 328 |
+
not os.path.isdir(options.target_dir)
|
| 329 |
+
# fmt: on
|
| 330 |
+
):
|
| 331 |
+
raise CommandError(
|
| 332 |
+
"Target path exists but is not a directory, will not continue."
|
| 333 |
+
)
|
| 334 |
+
|
| 335 |
+
# Create a target directory for using with the target option
|
| 336 |
+
target_temp_dir = TempDirectory(kind="target")
|
| 337 |
+
target_temp_dir_path = target_temp_dir.path
|
| 338 |
+
self.enter_context(target_temp_dir)
|
| 339 |
+
|
| 340 |
+
session = self.get_default_session(options)
|
| 341 |
+
|
| 342 |
+
target_python = make_target_python(options)
|
| 343 |
+
finder = self._build_package_finder(
|
| 344 |
+
options=options,
|
| 345 |
+
session=session,
|
| 346 |
+
target_python=target_python,
|
| 347 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 348 |
+
)
|
| 349 |
+
build_tracker = self.enter_context(get_build_tracker())
|
| 350 |
+
|
| 351 |
+
directory = TempDirectory(
|
| 352 |
+
delete=not options.no_clean,
|
| 353 |
+
kind="install",
|
| 354 |
+
globally_managed=True,
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
try:
|
| 358 |
+
reqs = self.get_requirements(args, options, finder, session)
|
| 359 |
+
|
| 360 |
+
wheel_cache = WheelCache(options.cache_dir)
|
| 361 |
+
|
| 362 |
+
# Only when installing is it permitted to use PEP 660.
|
| 363 |
+
# In other circumstances (pip wheel, pip download) we generate
|
| 364 |
+
# regular (i.e. non editable) metadata and wheels.
|
| 365 |
+
for req in reqs:
|
| 366 |
+
req.permit_editable_wheels = True
|
| 367 |
+
|
| 368 |
+
preparer = self.make_requirement_preparer(
|
| 369 |
+
temp_build_dir=directory,
|
| 370 |
+
options=options,
|
| 371 |
+
build_tracker=build_tracker,
|
| 372 |
+
session=session,
|
| 373 |
+
finder=finder,
|
| 374 |
+
use_user_site=options.use_user_site,
|
| 375 |
+
verbosity=self.verbosity,
|
| 376 |
+
)
|
| 377 |
+
resolver = self.make_resolver(
|
| 378 |
+
preparer=preparer,
|
| 379 |
+
finder=finder,
|
| 380 |
+
options=options,
|
| 381 |
+
wheel_cache=wheel_cache,
|
| 382 |
+
use_user_site=options.use_user_site,
|
| 383 |
+
ignore_installed=options.ignore_installed,
|
| 384 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 385 |
+
force_reinstall=options.force_reinstall,
|
| 386 |
+
upgrade_strategy=upgrade_strategy,
|
| 387 |
+
py_version_info=options.python_version,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
self.trace_basic_info(finder)
|
| 391 |
+
|
| 392 |
+
requirement_set = resolver.resolve(
|
| 393 |
+
reqs, check_supported_wheels=not options.target_dir
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
if options.json_report_file:
|
| 397 |
+
report = InstallationReport(requirement_set.requirements_to_install)
|
| 398 |
+
if options.json_report_file == "-":
|
| 399 |
+
print_json(data=report.to_dict())
|
| 400 |
+
else:
|
| 401 |
+
with open(options.json_report_file, "w", encoding="utf-8") as f:
|
| 402 |
+
json.dump(report.to_dict(), f, indent=2, ensure_ascii=False)
|
| 403 |
+
|
| 404 |
+
if options.dry_run:
|
| 405 |
+
would_install_items = sorted(
|
| 406 |
+
(r.metadata["name"], r.metadata["version"])
|
| 407 |
+
for r in requirement_set.requirements_to_install
|
| 408 |
+
)
|
| 409 |
+
if would_install_items:
|
| 410 |
+
write_output(
|
| 411 |
+
"Would install %s",
|
| 412 |
+
" ".join("-".join(item) for item in would_install_items),
|
| 413 |
+
)
|
| 414 |
+
return SUCCESS
|
| 415 |
+
|
| 416 |
+
# If there is any more preparation to do for the actual installation, do
|
| 417 |
+
# so now. This includes actually downloading the files in the case that
|
| 418 |
+
# we have been using PEP-658 metadata so far.
|
| 419 |
+
preparer.prepare_linked_requirements_more(
|
| 420 |
+
requirement_set.requirements.values()
|
| 421 |
+
)
|
| 422 |
+
|
| 423 |
+
try:
|
| 424 |
+
pip_req = requirement_set.get_requirement("pip")
|
| 425 |
+
except KeyError:
|
| 426 |
+
modifying_pip = False
|
| 427 |
+
else:
|
| 428 |
+
# If we're not replacing an already installed pip,
|
| 429 |
+
# we're not modifying it.
|
| 430 |
+
modifying_pip = pip_req.satisfied_by is None
|
| 431 |
+
protect_pip_from_modification_on_windows(modifying_pip=modifying_pip)
|
| 432 |
+
|
| 433 |
+
reqs_to_build = [
|
| 434 |
+
r for r in requirement_set.requirements_to_install if not r.is_wheel
|
| 435 |
+
]
|
| 436 |
+
|
| 437 |
+
_, build_failures = build(
|
| 438 |
+
reqs_to_build,
|
| 439 |
+
wheel_cache=wheel_cache,
|
| 440 |
+
verify=True,
|
| 441 |
+
)
|
| 442 |
+
|
| 443 |
+
if build_failures:
|
| 444 |
+
raise InstallWheelBuildError(build_failures)
|
| 445 |
+
|
| 446 |
+
to_install = resolver.get_installation_order(requirement_set)
|
| 447 |
+
|
| 448 |
+
# Check for conflicts in the package set we're installing.
|
| 449 |
+
conflicts: ConflictDetails | None = None
|
| 450 |
+
should_warn_about_conflicts = (
|
| 451 |
+
not options.ignore_dependencies and options.warn_about_conflicts
|
| 452 |
+
)
|
| 453 |
+
if should_warn_about_conflicts:
|
| 454 |
+
conflicts = self._determine_conflicts(to_install)
|
| 455 |
+
|
| 456 |
+
# Don't warn about script install locations if
|
| 457 |
+
# --target or --prefix has been specified
|
| 458 |
+
warn_script_location = options.warn_script_location
|
| 459 |
+
if options.target_dir or options.prefix_path:
|
| 460 |
+
warn_script_location = False
|
| 461 |
+
|
| 462 |
+
installed = install_given_reqs(
|
| 463 |
+
to_install,
|
| 464 |
+
root=options.root_path,
|
| 465 |
+
home=target_temp_dir_path,
|
| 466 |
+
prefix=options.prefix_path,
|
| 467 |
+
warn_script_location=warn_script_location,
|
| 468 |
+
use_user_site=options.use_user_site,
|
| 469 |
+
pycompile=options.compile,
|
| 470 |
+
progress_bar=options.progress_bar,
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
lib_locations = get_lib_location_guesses(
|
| 474 |
+
user=options.use_user_site,
|
| 475 |
+
home=target_temp_dir_path,
|
| 476 |
+
root=options.root_path,
|
| 477 |
+
prefix=options.prefix_path,
|
| 478 |
+
isolated=options.isolated_mode,
|
| 479 |
+
)
|
| 480 |
+
env = get_environment(lib_locations)
|
| 481 |
+
|
| 482 |
+
if conflicts is not None:
|
| 483 |
+
self._warn_about_conflicts(
|
| 484 |
+
conflicts,
|
| 485 |
+
resolver_variant=self.determine_resolver_variant(options),
|
| 486 |
+
)
|
| 487 |
+
if summary := installed_packages_summary(installed, env):
|
| 488 |
+
write_output(summary)
|
| 489 |
+
except OSError as error:
|
| 490 |
+
show_traceback = self.verbosity >= 1
|
| 491 |
+
|
| 492 |
+
message = create_os_error_message(
|
| 493 |
+
error,
|
| 494 |
+
show_traceback,
|
| 495 |
+
options.use_user_site,
|
| 496 |
+
)
|
| 497 |
+
logger.error(message, exc_info=show_traceback)
|
| 498 |
+
|
| 499 |
+
return ERROR
|
| 500 |
+
|
| 501 |
+
if options.target_dir:
|
| 502 |
+
assert target_temp_dir
|
| 503 |
+
self._handle_target_dir(
|
| 504 |
+
options.target_dir, target_temp_dir, options.upgrade
|
| 505 |
+
)
|
| 506 |
+
if options.root_user_action == "warn":
|
| 507 |
+
warn_if_run_as_root()
|
| 508 |
+
return SUCCESS
|
| 509 |
+
|
| 510 |
+
def _handle_target_dir(
|
| 511 |
+
self, target_dir: str, target_temp_dir: TempDirectory, upgrade: bool
|
| 512 |
+
) -> None:
|
| 513 |
+
ensure_dir(target_dir)
|
| 514 |
+
|
| 515 |
+
# Checking both purelib and platlib directories for installed
|
| 516 |
+
# packages to be moved to target directory
|
| 517 |
+
lib_dir_list = []
|
| 518 |
+
|
| 519 |
+
# Checking both purelib and platlib directories for installed
|
| 520 |
+
# packages to be moved to target directory
|
| 521 |
+
scheme = get_scheme("", home=target_temp_dir.path)
|
| 522 |
+
purelib_dir = scheme.purelib
|
| 523 |
+
platlib_dir = scheme.platlib
|
| 524 |
+
data_dir = scheme.data
|
| 525 |
+
|
| 526 |
+
if os.path.exists(purelib_dir):
|
| 527 |
+
lib_dir_list.append(purelib_dir)
|
| 528 |
+
if os.path.exists(platlib_dir) and platlib_dir != purelib_dir:
|
| 529 |
+
lib_dir_list.append(platlib_dir)
|
| 530 |
+
if os.path.exists(data_dir):
|
| 531 |
+
lib_dir_list.append(data_dir)
|
| 532 |
+
|
| 533 |
+
for lib_dir in lib_dir_list:
|
| 534 |
+
for item in os.listdir(lib_dir):
|
| 535 |
+
if lib_dir == data_dir:
|
| 536 |
+
ddir = os.path.join(data_dir, item)
|
| 537 |
+
if any(s.startswith(ddir) for s in lib_dir_list[:-1]):
|
| 538 |
+
continue
|
| 539 |
+
target_item_dir = os.path.join(target_dir, item)
|
| 540 |
+
if os.path.exists(target_item_dir):
|
| 541 |
+
if not upgrade:
|
| 542 |
+
logger.warning(
|
| 543 |
+
"Target directory %s already exists. Specify "
|
| 544 |
+
"--upgrade to force replacement.",
|
| 545 |
+
target_item_dir,
|
| 546 |
+
)
|
| 547 |
+
continue
|
| 548 |
+
if os.path.islink(target_item_dir):
|
| 549 |
+
logger.warning(
|
| 550 |
+
"Target directory %s already exists and is "
|
| 551 |
+
"a link. pip will not automatically replace "
|
| 552 |
+
"links, please remove if replacement is "
|
| 553 |
+
"desired.",
|
| 554 |
+
target_item_dir,
|
| 555 |
+
)
|
| 556 |
+
continue
|
| 557 |
+
if os.path.isdir(target_item_dir):
|
| 558 |
+
shutil.rmtree(target_item_dir)
|
| 559 |
+
else:
|
| 560 |
+
os.remove(target_item_dir)
|
| 561 |
+
|
| 562 |
+
shutil.move(os.path.join(lib_dir, item), target_item_dir)
|
| 563 |
+
|
| 564 |
+
def _determine_conflicts(
|
| 565 |
+
self, to_install: list[InstallRequirement]
|
| 566 |
+
) -> ConflictDetails | None:
|
| 567 |
+
try:
|
| 568 |
+
return check_install_conflicts(to_install)
|
| 569 |
+
except Exception:
|
| 570 |
+
logger.exception(
|
| 571 |
+
"Error while checking for conflicts. Please file an issue on "
|
| 572 |
+
"pip's issue tracker: https://github.com/pypa/pip/issues/new"
|
| 573 |
+
)
|
| 574 |
+
return None
|
| 575 |
+
|
| 576 |
+
def _warn_about_conflicts(
|
| 577 |
+
self, conflict_details: ConflictDetails, resolver_variant: str
|
| 578 |
+
) -> None:
|
| 579 |
+
package_set, (missing, conflicting) = conflict_details
|
| 580 |
+
if not missing and not conflicting:
|
| 581 |
+
return
|
| 582 |
+
|
| 583 |
+
parts: list[str] = []
|
| 584 |
+
if resolver_variant == "legacy":
|
| 585 |
+
parts.append(
|
| 586 |
+
"pip's legacy dependency resolver does not consider dependency "
|
| 587 |
+
"conflicts when selecting packages. This behaviour is the "
|
| 588 |
+
"source of the following dependency conflicts."
|
| 589 |
+
)
|
| 590 |
+
else:
|
| 591 |
+
assert resolver_variant == "resolvelib"
|
| 592 |
+
parts.append(
|
| 593 |
+
"pip's dependency resolver does not currently take into account "
|
| 594 |
+
"all the packages that are installed. This behaviour is the "
|
| 595 |
+
"source of the following dependency conflicts."
|
| 596 |
+
)
|
| 597 |
+
|
| 598 |
+
# NOTE: There is some duplication here, with commands/check.py
|
| 599 |
+
for project_name in missing:
|
| 600 |
+
version = package_set[project_name][0]
|
| 601 |
+
for dependency in missing[project_name]:
|
| 602 |
+
message = (
|
| 603 |
+
f"{project_name} {version} requires {dependency[1]}, "
|
| 604 |
+
"which is not installed."
|
| 605 |
+
)
|
| 606 |
+
parts.append(message)
|
| 607 |
+
|
| 608 |
+
for project_name in conflicting:
|
| 609 |
+
version = package_set[project_name][0]
|
| 610 |
+
for dep_name, dep_version, req in conflicting[project_name]:
|
| 611 |
+
message = (
|
| 612 |
+
"{name} {version} requires {requirement}, but {you} have "
|
| 613 |
+
"{dep_name} {dep_version} which is incompatible."
|
| 614 |
+
).format(
|
| 615 |
+
name=project_name,
|
| 616 |
+
version=version,
|
| 617 |
+
requirement=req,
|
| 618 |
+
dep_name=dep_name,
|
| 619 |
+
dep_version=dep_version,
|
| 620 |
+
you=("you" if resolver_variant == "resolvelib" else "you'll"),
|
| 621 |
+
)
|
| 622 |
+
parts.append(message)
|
| 623 |
+
|
| 624 |
+
logger.critical("\n".join(parts))
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
def installed_packages_summary(
|
| 628 |
+
installed: list[InstallationResult], env: BaseEnvironment
|
| 629 |
+
) -> str:
|
| 630 |
+
# Format a summary of installed packages, with extra care to
|
| 631 |
+
# display a package name as it was requested by the user.
|
| 632 |
+
installed.sort(key=operator.attrgetter("name"))
|
| 633 |
+
summary = []
|
| 634 |
+
installed_versions = {}
|
| 635 |
+
for distribution in env.iter_all_distributions():
|
| 636 |
+
installed_versions[distribution.canonical_name] = distribution.version
|
| 637 |
+
for package in installed:
|
| 638 |
+
display_name = package.name
|
| 639 |
+
version = installed_versions.get(canonicalize_name(display_name), None)
|
| 640 |
+
if version:
|
| 641 |
+
text = f"{display_name}-{version}"
|
| 642 |
+
else:
|
| 643 |
+
text = display_name
|
| 644 |
+
summary.append(text)
|
| 645 |
+
|
| 646 |
+
if not summary:
|
| 647 |
+
return ""
|
| 648 |
+
return f"Successfully installed {' '.join(summary)}"
|
| 649 |
+
|
| 650 |
+
|
| 651 |
+
def get_lib_location_guesses(
|
| 652 |
+
user: bool = False,
|
| 653 |
+
home: str | None = None,
|
| 654 |
+
root: str | None = None,
|
| 655 |
+
isolated: bool = False,
|
| 656 |
+
prefix: str | None = None,
|
| 657 |
+
) -> list[str]:
|
| 658 |
+
scheme = get_scheme(
|
| 659 |
+
"",
|
| 660 |
+
user=user,
|
| 661 |
+
home=home,
|
| 662 |
+
root=root,
|
| 663 |
+
isolated=isolated,
|
| 664 |
+
prefix=prefix,
|
| 665 |
+
)
|
| 666 |
+
return [scheme.purelib, scheme.platlib]
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
def site_packages_writable(root: str | None, isolated: bool) -> bool:
|
| 670 |
+
return all(
|
| 671 |
+
test_writable_dir(d)
|
| 672 |
+
for d in set(get_lib_location_guesses(root=root, isolated=isolated))
|
| 673 |
+
)
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
def decide_user_install(
|
| 677 |
+
use_user_site: bool | None,
|
| 678 |
+
prefix_path: str | None = None,
|
| 679 |
+
target_dir: str | None = None,
|
| 680 |
+
root_path: str | None = None,
|
| 681 |
+
isolated_mode: bool = False,
|
| 682 |
+
) -> bool:
|
| 683 |
+
"""Determine whether to do a user install based on the input options.
|
| 684 |
+
|
| 685 |
+
If use_user_site is False, no additional checks are done.
|
| 686 |
+
If use_user_site is True, it is checked for compatibility with other
|
| 687 |
+
options.
|
| 688 |
+
If use_user_site is None, the default behaviour depends on the environment,
|
| 689 |
+
which is provided by the other arguments.
|
| 690 |
+
"""
|
| 691 |
+
# In some cases (config from tox), use_user_site can be set to an integer
|
| 692 |
+
# rather than a bool, which 'use_user_site is False' wouldn't catch.
|
| 693 |
+
if (use_user_site is not None) and (not use_user_site):
|
| 694 |
+
logger.debug("Non-user install by explicit request")
|
| 695 |
+
return False
|
| 696 |
+
|
| 697 |
+
# If we have been asked for a user install explicitly, check compatibility.
|
| 698 |
+
if use_user_site:
|
| 699 |
+
if prefix_path:
|
| 700 |
+
raise CommandError(
|
| 701 |
+
"Can not combine '--user' and '--prefix' as they imply "
|
| 702 |
+
"different installation locations"
|
| 703 |
+
)
|
| 704 |
+
if virtualenv_no_global():
|
| 705 |
+
raise InstallationError(
|
| 706 |
+
"Can not perform a '--user' install. User site-packages "
|
| 707 |
+
"are not visible in this virtualenv."
|
| 708 |
+
)
|
| 709 |
+
# Catch all remaining cases which honour the site.ENABLE_USER_SITE
|
| 710 |
+
# value, such as a plain Python installation (e.g. no virtualenv).
|
| 711 |
+
if not site.ENABLE_USER_SITE:
|
| 712 |
+
raise InstallationError(
|
| 713 |
+
"Can not perform a '--user' install. User site-packages "
|
| 714 |
+
"are disabled for this Python."
|
| 715 |
+
)
|
| 716 |
+
logger.debug("User install by explicit request")
|
| 717 |
+
return True
|
| 718 |
+
|
| 719 |
+
# If we are here, user installs have not been explicitly requested/avoided
|
| 720 |
+
assert use_user_site is None
|
| 721 |
+
|
| 722 |
+
# user install incompatible with --prefix/--target
|
| 723 |
+
if prefix_path or target_dir:
|
| 724 |
+
logger.debug("Non-user install due to --prefix or --target option")
|
| 725 |
+
return False
|
| 726 |
+
|
| 727 |
+
# If user installs are not enabled, choose a non-user install
|
| 728 |
+
if not site.ENABLE_USER_SITE:
|
| 729 |
+
logger.debug("Non-user install because user site-packages disabled")
|
| 730 |
+
return False
|
| 731 |
+
|
| 732 |
+
# If we have permission for a non-user install, do that,
|
| 733 |
+
# otherwise do a user install.
|
| 734 |
+
if site_packages_writable(root=root_path, isolated=isolated_mode):
|
| 735 |
+
logger.debug("Non-user install because site-packages writeable")
|
| 736 |
+
return False
|
| 737 |
+
|
| 738 |
+
logger.info(
|
| 739 |
+
"Defaulting to user installation because normal site-packages "
|
| 740 |
+
"is not writeable"
|
| 741 |
+
)
|
| 742 |
+
return True
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
def create_os_error_message(
|
| 746 |
+
error: OSError, show_traceback: bool, using_user_site: bool
|
| 747 |
+
) -> str:
|
| 748 |
+
"""Format an error message for an OSError
|
| 749 |
+
|
| 750 |
+
It may occur anytime during the execution of the install command.
|
| 751 |
+
"""
|
| 752 |
+
parts = []
|
| 753 |
+
|
| 754 |
+
# Mention the error if we are not going to show a traceback
|
| 755 |
+
parts.append("Could not install packages due to an OSError")
|
| 756 |
+
if not show_traceback:
|
| 757 |
+
parts.append(": ")
|
| 758 |
+
parts.append(str(error))
|
| 759 |
+
else:
|
| 760 |
+
parts.append(".")
|
| 761 |
+
|
| 762 |
+
# Spilt the error indication from a helper message (if any)
|
| 763 |
+
parts[-1] += "\n"
|
| 764 |
+
|
| 765 |
+
# Suggest useful actions to the user:
|
| 766 |
+
# (1) using user site-packages or (2) verifying the permissions
|
| 767 |
+
if error.errno == errno.EACCES:
|
| 768 |
+
user_option_part = "Consider using the `--user` option"
|
| 769 |
+
permissions_part = "Check the permissions"
|
| 770 |
+
|
| 771 |
+
if not running_under_virtualenv() and not using_user_site:
|
| 772 |
+
parts.extend(
|
| 773 |
+
[
|
| 774 |
+
user_option_part,
|
| 775 |
+
" or ",
|
| 776 |
+
permissions_part.lower(),
|
| 777 |
+
]
|
| 778 |
+
)
|
| 779 |
+
else:
|
| 780 |
+
parts.append(permissions_part)
|
| 781 |
+
parts.append(".\n")
|
| 782 |
+
|
| 783 |
+
# Suggest to check "pip config debug" in case of invalid proxy
|
| 784 |
+
if type(error) is InvalidProxyURL:
|
| 785 |
+
parts.append(
|
| 786 |
+
'Consider checking your local proxy configuration with "pip config debug"'
|
| 787 |
+
)
|
| 788 |
+
parts.append(".\n")
|
| 789 |
+
|
| 790 |
+
# On Windows, errors like EINVAL or ENOENT may occur
|
| 791 |
+
# if a file or folder name exceeds 255 characters,
|
| 792 |
+
# or if the full path exceeds 260 characters and long path support isn't enabled.
|
| 793 |
+
# This condition checks for such cases and adds a hint to the error output.
|
| 794 |
+
|
| 795 |
+
if WINDOWS and error.errno in (errno.EINVAL, errno.ENOENT) and error.filename:
|
| 796 |
+
if any(len(part) > 255 for part in Path(error.filename).parts):
|
| 797 |
+
parts.append(
|
| 798 |
+
"HINT: This error might be caused by a file or folder name exceeding "
|
| 799 |
+
"255 characters, which is a Windows limitation even if long paths "
|
| 800 |
+
"are enabled.\n "
|
| 801 |
+
)
|
| 802 |
+
if len(error.filename) > 260:
|
| 803 |
+
parts.append(
|
| 804 |
+
"HINT: This error might have occurred since "
|
| 805 |
+
"this system does not have Windows Long Path "
|
| 806 |
+
"support enabled. You can find information on "
|
| 807 |
+
"how to enable this at "
|
| 808 |
+
"https://pip.pypa.io/warnings/enable-long-paths\n"
|
| 809 |
+
)
|
| 810 |
+
return "".join(parts).strip() + "\n"
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/list.py
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import logging
|
| 5 |
+
from collections.abc import Generator, Sequence
|
| 6 |
+
from email.parser import Parser
|
| 7 |
+
from optparse import Values
|
| 8 |
+
from typing import TYPE_CHECKING, cast
|
| 9 |
+
|
| 10 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 11 |
+
from pip._vendor.packaging.version import InvalidVersion, Version
|
| 12 |
+
|
| 13 |
+
from pip._internal.cli import cmdoptions
|
| 14 |
+
from pip._internal.cli.index_command import IndexGroupCommand
|
| 15 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 16 |
+
from pip._internal.exceptions import CommandError
|
| 17 |
+
from pip._internal.metadata import BaseDistribution, get_environment
|
| 18 |
+
from pip._internal.models.selection_prefs import SelectionPreferences
|
| 19 |
+
from pip._internal.utils.compat import stdlib_pkgs
|
| 20 |
+
from pip._internal.utils.misc import tabulate, write_output
|
| 21 |
+
|
| 22 |
+
if TYPE_CHECKING:
|
| 23 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 24 |
+
from pip._internal.network.session import PipSession
|
| 25 |
+
|
| 26 |
+
class _DistWithLatestInfo(BaseDistribution):
|
| 27 |
+
"""Give the distribution object a couple of extra fields.
|
| 28 |
+
|
| 29 |
+
These will be populated during ``get_outdated()``. This is dirty but
|
| 30 |
+
makes the rest of the code much cleaner.
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
latest_version: Version
|
| 34 |
+
latest_filetype: str
|
| 35 |
+
|
| 36 |
+
_ProcessedDists = Sequence[_DistWithLatestInfo]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
logger = logging.getLogger(__name__)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class ListCommand(IndexGroupCommand):
|
| 43 |
+
"""
|
| 44 |
+
List installed packages, including editables.
|
| 45 |
+
|
| 46 |
+
Packages are listed in a case-insensitive sorted order.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
ignore_require_venv = True
|
| 50 |
+
usage = """
|
| 51 |
+
%prog [options]"""
|
| 52 |
+
|
| 53 |
+
def add_options(self) -> None:
|
| 54 |
+
self.cmd_opts.add_option(
|
| 55 |
+
"-o",
|
| 56 |
+
"--outdated",
|
| 57 |
+
action="store_true",
|
| 58 |
+
default=False,
|
| 59 |
+
help="List outdated packages",
|
| 60 |
+
)
|
| 61 |
+
self.cmd_opts.add_option(
|
| 62 |
+
"-u",
|
| 63 |
+
"--uptodate",
|
| 64 |
+
action="store_true",
|
| 65 |
+
default=False,
|
| 66 |
+
help="List uptodate packages",
|
| 67 |
+
)
|
| 68 |
+
self.cmd_opts.add_option(
|
| 69 |
+
"-e",
|
| 70 |
+
"--editable",
|
| 71 |
+
action="store_true",
|
| 72 |
+
default=False,
|
| 73 |
+
help="List editable projects.",
|
| 74 |
+
)
|
| 75 |
+
self.cmd_opts.add_option(
|
| 76 |
+
"-l",
|
| 77 |
+
"--local",
|
| 78 |
+
action="store_true",
|
| 79 |
+
default=False,
|
| 80 |
+
help=(
|
| 81 |
+
"If in a virtualenv that has global access, do not list "
|
| 82 |
+
"globally-installed packages."
|
| 83 |
+
),
|
| 84 |
+
)
|
| 85 |
+
self.cmd_opts.add_option(
|
| 86 |
+
"--user",
|
| 87 |
+
dest="user",
|
| 88 |
+
action="store_true",
|
| 89 |
+
default=False,
|
| 90 |
+
help="Only output packages installed in user-site.",
|
| 91 |
+
)
|
| 92 |
+
self.cmd_opts.add_option(cmdoptions.list_path())
|
| 93 |
+
|
| 94 |
+
self.cmd_opts.add_option(
|
| 95 |
+
"--format",
|
| 96 |
+
action="store",
|
| 97 |
+
dest="list_format",
|
| 98 |
+
default="columns",
|
| 99 |
+
choices=("columns", "freeze", "json"),
|
| 100 |
+
help=(
|
| 101 |
+
"Select the output format among: columns (default), freeze, or json. "
|
| 102 |
+
"The 'freeze' format cannot be used with the --outdated option."
|
| 103 |
+
),
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
self.cmd_opts.add_option(
|
| 107 |
+
"--not-required",
|
| 108 |
+
action="store_true",
|
| 109 |
+
dest="not_required",
|
| 110 |
+
help="List packages that are not dependencies of installed packages.",
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
self.cmd_opts.add_option(
|
| 114 |
+
"--exclude-editable",
|
| 115 |
+
action="store_false",
|
| 116 |
+
dest="include_editable",
|
| 117 |
+
help="Exclude editable package from output.",
|
| 118 |
+
)
|
| 119 |
+
self.cmd_opts.add_option(
|
| 120 |
+
"--include-editable",
|
| 121 |
+
action="store_true",
|
| 122 |
+
dest="include_editable",
|
| 123 |
+
help="Include editable package in output.",
|
| 124 |
+
default=True,
|
| 125 |
+
)
|
| 126 |
+
self.cmd_opts.add_option(cmdoptions.list_exclude())
|
| 127 |
+
index_opts = cmdoptions.make_option_group(cmdoptions.index_group, self.parser)
|
| 128 |
+
|
| 129 |
+
selection_opts = cmdoptions.make_option_group(
|
| 130 |
+
cmdoptions.package_selection_group,
|
| 131 |
+
self.parser,
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
self.parser.insert_option_group(0, index_opts)
|
| 135 |
+
self.parser.insert_option_group(0, selection_opts)
|
| 136 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 137 |
+
|
| 138 |
+
def handle_pip_version_check(self, options: Values) -> None:
|
| 139 |
+
if options.outdated or options.uptodate:
|
| 140 |
+
super().handle_pip_version_check(options)
|
| 141 |
+
|
| 142 |
+
def _build_package_finder(
|
| 143 |
+
self, options: Values, session: PipSession
|
| 144 |
+
) -> PackageFinder:
|
| 145 |
+
"""
|
| 146 |
+
Create a package finder appropriate to this list command.
|
| 147 |
+
"""
|
| 148 |
+
# Lazy import the heavy index modules as most list invocations won't need 'em.
|
| 149 |
+
from pip._internal.index.collector import LinkCollector
|
| 150 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 151 |
+
|
| 152 |
+
link_collector = LinkCollector.create(session, options=options)
|
| 153 |
+
|
| 154 |
+
# Pass allow_yanked=False to ignore yanked versions.
|
| 155 |
+
selection_prefs = SelectionPreferences(
|
| 156 |
+
allow_yanked=False,
|
| 157 |
+
release_control=options.release_control,
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
return PackageFinder.create(
|
| 161 |
+
link_collector=link_collector,
|
| 162 |
+
selection_prefs=selection_prefs,
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 166 |
+
cmdoptions.check_release_control_exclusive(options)
|
| 167 |
+
|
| 168 |
+
if options.outdated and options.uptodate:
|
| 169 |
+
raise CommandError("Options --outdated and --uptodate cannot be combined.")
|
| 170 |
+
|
| 171 |
+
if options.outdated and options.list_format == "freeze":
|
| 172 |
+
raise CommandError(
|
| 173 |
+
"List format 'freeze' cannot be used with the --outdated option."
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
cmdoptions.check_list_path_option(options)
|
| 177 |
+
|
| 178 |
+
skip = set(stdlib_pkgs)
|
| 179 |
+
if options.excludes:
|
| 180 |
+
skip.update(canonicalize_name(n) for n in options.excludes)
|
| 181 |
+
|
| 182 |
+
packages: _ProcessedDists = [
|
| 183 |
+
cast("_DistWithLatestInfo", d)
|
| 184 |
+
for d in get_environment(options.path).iter_installed_distributions(
|
| 185 |
+
local_only=options.local,
|
| 186 |
+
user_only=options.user,
|
| 187 |
+
editables_only=options.editable,
|
| 188 |
+
include_editables=options.include_editable,
|
| 189 |
+
skip=skip,
|
| 190 |
+
)
|
| 191 |
+
]
|
| 192 |
+
|
| 193 |
+
# get_not_required must be called firstly in order to find and
|
| 194 |
+
# filter out all dependencies correctly. Otherwise a package
|
| 195 |
+
# can't be identified as requirement because some parent packages
|
| 196 |
+
# could be filtered out before.
|
| 197 |
+
if options.not_required:
|
| 198 |
+
packages = self.get_not_required(packages, options)
|
| 199 |
+
|
| 200 |
+
if options.outdated:
|
| 201 |
+
packages = self.get_outdated(packages, options)
|
| 202 |
+
elif options.uptodate:
|
| 203 |
+
packages = self.get_uptodate(packages, options)
|
| 204 |
+
|
| 205 |
+
self.output_package_listing(packages, options)
|
| 206 |
+
return SUCCESS
|
| 207 |
+
|
| 208 |
+
def get_outdated(
|
| 209 |
+
self, packages: _ProcessedDists, options: Values
|
| 210 |
+
) -> _ProcessedDists:
|
| 211 |
+
return [
|
| 212 |
+
dist
|
| 213 |
+
for dist in self.iter_packages_latest_infos(packages, options)
|
| 214 |
+
if dist.latest_version > dist.version
|
| 215 |
+
]
|
| 216 |
+
|
| 217 |
+
def get_uptodate(
|
| 218 |
+
self, packages: _ProcessedDists, options: Values
|
| 219 |
+
) -> _ProcessedDists:
|
| 220 |
+
return [
|
| 221 |
+
dist
|
| 222 |
+
for dist in self.iter_packages_latest_infos(packages, options)
|
| 223 |
+
if dist.latest_version == dist.version
|
| 224 |
+
]
|
| 225 |
+
|
| 226 |
+
def get_not_required(
|
| 227 |
+
self, packages: _ProcessedDists, options: Values
|
| 228 |
+
) -> _ProcessedDists:
|
| 229 |
+
dep_keys = {
|
| 230 |
+
canonicalize_name(dep.name)
|
| 231 |
+
for dist in packages
|
| 232 |
+
for dep in (dist.iter_dependencies() or ())
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
# Create a set to remove duplicate packages, and cast it to a list
|
| 236 |
+
# to keep the return type consistent with get_outdated and
|
| 237 |
+
# get_uptodate
|
| 238 |
+
return list({pkg for pkg in packages if pkg.canonical_name not in dep_keys})
|
| 239 |
+
|
| 240 |
+
def iter_packages_latest_infos(
|
| 241 |
+
self, packages: _ProcessedDists, options: Values
|
| 242 |
+
) -> Generator[_DistWithLatestInfo, None, None]:
|
| 243 |
+
with self._build_session(options) as session:
|
| 244 |
+
finder = self._build_package_finder(options, session)
|
| 245 |
+
|
| 246 |
+
def latest_info(
|
| 247 |
+
dist: _DistWithLatestInfo,
|
| 248 |
+
) -> _DistWithLatestInfo | None:
|
| 249 |
+
all_candidates = finder.find_all_candidates(dist.canonical_name)
|
| 250 |
+
if self.should_exclude_prerelease(options, dist.canonical_name):
|
| 251 |
+
all_candidates = [
|
| 252 |
+
candidate
|
| 253 |
+
for candidate in all_candidates
|
| 254 |
+
if not candidate.version.is_prerelease
|
| 255 |
+
]
|
| 256 |
+
|
| 257 |
+
evaluator = finder.make_candidate_evaluator(
|
| 258 |
+
project_name=dist.canonical_name,
|
| 259 |
+
)
|
| 260 |
+
best_candidate = evaluator.sort_best_candidate(all_candidates)
|
| 261 |
+
if best_candidate is None:
|
| 262 |
+
return None
|
| 263 |
+
|
| 264 |
+
remote_version = best_candidate.version
|
| 265 |
+
if best_candidate.link.is_wheel:
|
| 266 |
+
typ = "wheel"
|
| 267 |
+
else:
|
| 268 |
+
typ = "sdist"
|
| 269 |
+
dist.latest_version = remote_version
|
| 270 |
+
dist.latest_filetype = typ
|
| 271 |
+
return dist
|
| 272 |
+
|
| 273 |
+
for dist in map(latest_info, packages):
|
| 274 |
+
if dist is not None:
|
| 275 |
+
yield dist
|
| 276 |
+
|
| 277 |
+
def output_package_listing(
|
| 278 |
+
self, packages: _ProcessedDists, options: Values
|
| 279 |
+
) -> None:
|
| 280 |
+
packages = sorted(
|
| 281 |
+
packages,
|
| 282 |
+
key=lambda dist: dist.canonical_name,
|
| 283 |
+
)
|
| 284 |
+
if options.list_format == "columns" and packages:
|
| 285 |
+
data, header = format_for_columns(packages, options)
|
| 286 |
+
self.output_package_listing_columns(data, header)
|
| 287 |
+
elif options.list_format == "freeze":
|
| 288 |
+
for dist in packages:
|
| 289 |
+
try:
|
| 290 |
+
req_string = f"{dist.raw_name}=={dist.version}"
|
| 291 |
+
except InvalidVersion:
|
| 292 |
+
req_string = f"{dist.raw_name}==={dist.raw_version}"
|
| 293 |
+
if options.verbose >= 1:
|
| 294 |
+
write_output("%s (%s)", req_string, dist.location)
|
| 295 |
+
else:
|
| 296 |
+
write_output(req_string)
|
| 297 |
+
elif options.list_format == "json":
|
| 298 |
+
write_output(format_for_json(packages, options))
|
| 299 |
+
|
| 300 |
+
def output_package_listing_columns(
|
| 301 |
+
self, data: list[list[str]], header: list[str]
|
| 302 |
+
) -> None:
|
| 303 |
+
# insert the header first: we need to know the size of column names
|
| 304 |
+
if len(data) > 0:
|
| 305 |
+
data.insert(0, header)
|
| 306 |
+
|
| 307 |
+
pkg_strings, sizes = tabulate(data)
|
| 308 |
+
|
| 309 |
+
# Create and add a separator.
|
| 310 |
+
if len(data) > 0:
|
| 311 |
+
pkg_strings.insert(1, " ".join("-" * x for x in sizes))
|
| 312 |
+
|
| 313 |
+
for val in pkg_strings:
|
| 314 |
+
write_output(val)
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
def format_for_columns(
|
| 318 |
+
pkgs: _ProcessedDists, options: Values
|
| 319 |
+
) -> tuple[list[list[str]], list[str]]:
|
| 320 |
+
"""
|
| 321 |
+
Convert the package data into something usable
|
| 322 |
+
by output_package_listing_columns.
|
| 323 |
+
"""
|
| 324 |
+
header = ["Package", "Version"]
|
| 325 |
+
|
| 326 |
+
running_outdated = options.outdated
|
| 327 |
+
if running_outdated:
|
| 328 |
+
header.extend(["Latest", "Type"])
|
| 329 |
+
|
| 330 |
+
def wheel_build_tag(dist: BaseDistribution) -> str | None:
|
| 331 |
+
try:
|
| 332 |
+
wheel_file = dist.read_text("WHEEL")
|
| 333 |
+
except FileNotFoundError:
|
| 334 |
+
return None
|
| 335 |
+
return Parser().parsestr(wheel_file).get("Build")
|
| 336 |
+
|
| 337 |
+
build_tags = [wheel_build_tag(p) for p in pkgs]
|
| 338 |
+
has_build_tags = any(build_tags)
|
| 339 |
+
if has_build_tags:
|
| 340 |
+
header.append("Build")
|
| 341 |
+
|
| 342 |
+
has_editables = any(x.editable for x in pkgs)
|
| 343 |
+
if has_editables:
|
| 344 |
+
header.append("Editable project location")
|
| 345 |
+
|
| 346 |
+
if options.verbose >= 1:
|
| 347 |
+
header.append("Location")
|
| 348 |
+
if options.verbose >= 1:
|
| 349 |
+
header.append("Installer")
|
| 350 |
+
|
| 351 |
+
data = []
|
| 352 |
+
for i, proj in enumerate(pkgs):
|
| 353 |
+
# if we're working on the 'outdated' list, separate out the
|
| 354 |
+
# latest_version and type
|
| 355 |
+
row = [proj.raw_name, proj.raw_version]
|
| 356 |
+
|
| 357 |
+
if running_outdated:
|
| 358 |
+
row.append(str(proj.latest_version))
|
| 359 |
+
row.append(proj.latest_filetype)
|
| 360 |
+
|
| 361 |
+
if has_build_tags:
|
| 362 |
+
row.append(build_tags[i] or "")
|
| 363 |
+
|
| 364 |
+
if has_editables:
|
| 365 |
+
row.append(proj.editable_project_location or "")
|
| 366 |
+
|
| 367 |
+
if options.verbose >= 1:
|
| 368 |
+
row.append(proj.location or "")
|
| 369 |
+
if options.verbose >= 1:
|
| 370 |
+
row.append(proj.installer)
|
| 371 |
+
|
| 372 |
+
data.append(row)
|
| 373 |
+
|
| 374 |
+
return data, header
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def format_for_json(packages: _ProcessedDists, options: Values) -> str:
|
| 378 |
+
data = []
|
| 379 |
+
for dist in packages:
|
| 380 |
+
try:
|
| 381 |
+
version = str(dist.version)
|
| 382 |
+
except InvalidVersion:
|
| 383 |
+
version = dist.raw_version
|
| 384 |
+
info = {
|
| 385 |
+
"name": dist.raw_name,
|
| 386 |
+
"version": version,
|
| 387 |
+
}
|
| 388 |
+
if options.verbose >= 1:
|
| 389 |
+
info["location"] = dist.location or ""
|
| 390 |
+
info["installer"] = dist.installer
|
| 391 |
+
if options.outdated:
|
| 392 |
+
info["latest_version"] = str(dist.latest_version)
|
| 393 |
+
info["latest_filetype"] = dist.latest_filetype
|
| 394 |
+
editable_project_location = dist.editable_project_location
|
| 395 |
+
if editable_project_location:
|
| 396 |
+
info["editable_project_location"] = editable_project_location
|
| 397 |
+
data.append(info)
|
| 398 |
+
return json.dumps(data)
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/lock.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from optparse import Values
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
from pip._vendor import tomli_w
|
| 6 |
+
from pip._vendor.packaging.pylock import is_valid_pylock_path
|
| 7 |
+
|
| 8 |
+
from pip._internal.cache import WheelCache
|
| 9 |
+
from pip._internal.cli import cmdoptions
|
| 10 |
+
from pip._internal.cli.req_command import (
|
| 11 |
+
RequirementCommand,
|
| 12 |
+
with_cleanup,
|
| 13 |
+
)
|
| 14 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 15 |
+
from pip._internal.operations.build.build_tracker import get_build_tracker
|
| 16 |
+
from pip._internal.utils.logging import getLogger
|
| 17 |
+
from pip._internal.utils.misc import (
|
| 18 |
+
get_pip_version,
|
| 19 |
+
)
|
| 20 |
+
from pip._internal.utils.pylock import pylock_from_install_requirements
|
| 21 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 22 |
+
|
| 23 |
+
logger = getLogger(__name__)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class LockCommand(RequirementCommand):
|
| 27 |
+
"""
|
| 28 |
+
EXPERIMENTAL - Lock packages and their dependencies from:
|
| 29 |
+
|
| 30 |
+
- PyPI (and other indexes) using requirement specifiers.
|
| 31 |
+
- VCS project urls.
|
| 32 |
+
- Local project directories.
|
| 33 |
+
- Local or remote source archives.
|
| 34 |
+
|
| 35 |
+
pip also supports locking from "requirements files", which provide an easy
|
| 36 |
+
way to specify a whole environment to be installed.
|
| 37 |
+
|
| 38 |
+
The generated lock file is only guaranteed to be valid for the current
|
| 39 |
+
python version and platform.
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
usage = """
|
| 43 |
+
%prog [options] [-e] <local project path> ...
|
| 44 |
+
%prog [options] <requirement specifier> [package-index-options] ...
|
| 45 |
+
%prog [options] -r <requirements file> [package-index-options] ...
|
| 46 |
+
%prog [options] <archive url/path> ..."""
|
| 47 |
+
|
| 48 |
+
def add_options(self) -> None:
|
| 49 |
+
self.cmd_opts.add_option(
|
| 50 |
+
cmdoptions.PipOption(
|
| 51 |
+
"--output",
|
| 52 |
+
"-o",
|
| 53 |
+
dest="output_file",
|
| 54 |
+
metavar="path",
|
| 55 |
+
type="path",
|
| 56 |
+
default="pylock.toml",
|
| 57 |
+
help="Lock file name (default=pylock.toml). Use - for stdout.",
|
| 58 |
+
)
|
| 59 |
+
)
|
| 60 |
+
self.cmd_opts.add_option(cmdoptions.requirements())
|
| 61 |
+
self.cmd_opts.add_option(cmdoptions.requirements_from_scripts())
|
| 62 |
+
self.cmd_opts.add_option(cmdoptions.constraints())
|
| 63 |
+
self.cmd_opts.add_option(cmdoptions.build_constraints())
|
| 64 |
+
self.cmd_opts.add_option(cmdoptions.no_deps())
|
| 65 |
+
|
| 66 |
+
self.cmd_opts.add_option(cmdoptions.editable())
|
| 67 |
+
|
| 68 |
+
self.cmd_opts.add_option(cmdoptions.src())
|
| 69 |
+
|
| 70 |
+
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
| 71 |
+
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
|
| 72 |
+
self.cmd_opts.add_option(cmdoptions.use_pep517())
|
| 73 |
+
self.cmd_opts.add_option(cmdoptions.check_build_deps())
|
| 74 |
+
|
| 75 |
+
self.cmd_opts.add_option(cmdoptions.config_settings())
|
| 76 |
+
|
| 77 |
+
self.cmd_opts.add_option(cmdoptions.require_hashes())
|
| 78 |
+
self.cmd_opts.add_option(cmdoptions.progress_bar())
|
| 79 |
+
|
| 80 |
+
index_opts = cmdoptions.make_option_group(
|
| 81 |
+
cmdoptions.index_group,
|
| 82 |
+
self.parser,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
selection_opts = cmdoptions.make_option_group(
|
| 86 |
+
cmdoptions.package_selection_group,
|
| 87 |
+
self.parser,
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
self.parser.insert_option_group(0, index_opts)
|
| 91 |
+
self.parser.insert_option_group(0, selection_opts)
|
| 92 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 93 |
+
|
| 94 |
+
@with_cleanup
|
| 95 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 96 |
+
logger.verbose("Using %s", get_pip_version())
|
| 97 |
+
|
| 98 |
+
logger.warning(
|
| 99 |
+
"pip lock is currently an experimental command. "
|
| 100 |
+
"It may be removed/changed in a future release "
|
| 101 |
+
"without prior warning."
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
cmdoptions.check_build_constraints(options)
|
| 105 |
+
cmdoptions.check_release_control_exclusive(options)
|
| 106 |
+
|
| 107 |
+
session = self.get_default_session(options)
|
| 108 |
+
|
| 109 |
+
finder = self._build_package_finder(
|
| 110 |
+
options=options,
|
| 111 |
+
session=session,
|
| 112 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 113 |
+
)
|
| 114 |
+
build_tracker = self.enter_context(get_build_tracker())
|
| 115 |
+
|
| 116 |
+
directory = TempDirectory(
|
| 117 |
+
delete=not options.no_clean,
|
| 118 |
+
kind="install",
|
| 119 |
+
globally_managed=True,
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
reqs = self.get_requirements(args, options, finder, session)
|
| 123 |
+
|
| 124 |
+
wheel_cache = WheelCache(options.cache_dir)
|
| 125 |
+
|
| 126 |
+
# Only when installing is it permitted to use PEP 660.
|
| 127 |
+
# In other circumstances (pip wheel, pip download) we generate
|
| 128 |
+
# regular (i.e. non editable) metadata and wheels.
|
| 129 |
+
for req in reqs:
|
| 130 |
+
req.permit_editable_wheels = True
|
| 131 |
+
|
| 132 |
+
preparer = self.make_requirement_preparer(
|
| 133 |
+
temp_build_dir=directory,
|
| 134 |
+
options=options,
|
| 135 |
+
build_tracker=build_tracker,
|
| 136 |
+
session=session,
|
| 137 |
+
finder=finder,
|
| 138 |
+
use_user_site=False,
|
| 139 |
+
verbosity=self.verbosity,
|
| 140 |
+
)
|
| 141 |
+
resolver = self.make_resolver(
|
| 142 |
+
preparer=preparer,
|
| 143 |
+
finder=finder,
|
| 144 |
+
options=options,
|
| 145 |
+
wheel_cache=wheel_cache,
|
| 146 |
+
use_user_site=False,
|
| 147 |
+
ignore_installed=True,
|
| 148 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 149 |
+
upgrade_strategy="to-satisfy-only",
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
self.trace_basic_info(finder)
|
| 153 |
+
|
| 154 |
+
requirement_set = resolver.resolve(reqs, check_supported_wheels=True)
|
| 155 |
+
|
| 156 |
+
if options.output_file == "-":
|
| 157 |
+
base_dir = Path.cwd()
|
| 158 |
+
else:
|
| 159 |
+
output_file_path = Path(options.output_file)
|
| 160 |
+
if not is_valid_pylock_path(output_file_path):
|
| 161 |
+
logger.warning(
|
| 162 |
+
"%s is not a valid lock file name.",
|
| 163 |
+
output_file_path,
|
| 164 |
+
)
|
| 165 |
+
base_dir = output_file_path.parent
|
| 166 |
+
pylock = pylock_from_install_requirements(
|
| 167 |
+
requirement_set.requirements.values(), base_dir=base_dir
|
| 168 |
+
)
|
| 169 |
+
pylock_toml = tomli_w.dumps(pylock.to_dict())
|
| 170 |
+
if options.output_file == "-":
|
| 171 |
+
sys.stdout.write(pylock_toml)
|
| 172 |
+
else:
|
| 173 |
+
output_file_path.write_text(pylock_toml, encoding="utf-8")
|
| 174 |
+
|
| 175 |
+
return SUCCESS
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/search.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import shutil
|
| 5 |
+
import sys
|
| 6 |
+
import textwrap
|
| 7 |
+
import xmlrpc.client
|
| 8 |
+
from collections import OrderedDict
|
| 9 |
+
from optparse import Values
|
| 10 |
+
from typing import TypedDict
|
| 11 |
+
|
| 12 |
+
from pip._vendor.packaging.version import parse as parse_version
|
| 13 |
+
|
| 14 |
+
from pip._internal.cli.base_command import Command
|
| 15 |
+
from pip._internal.cli.req_command import SessionCommandMixin
|
| 16 |
+
from pip._internal.cli.status_codes import NO_MATCHES_FOUND, SUCCESS
|
| 17 |
+
from pip._internal.exceptions import CommandError
|
| 18 |
+
from pip._internal.metadata import get_default_environment
|
| 19 |
+
from pip._internal.metadata.base import BaseDistribution
|
| 20 |
+
from pip._internal.models.index import PyPI
|
| 21 |
+
from pip._internal.network.xmlrpc import PipXmlrpcTransport
|
| 22 |
+
from pip._internal.utils.logging import indent_log
|
| 23 |
+
from pip._internal.utils.misc import write_output
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class TransformedHit(TypedDict):
|
| 27 |
+
name: str
|
| 28 |
+
summary: str
|
| 29 |
+
versions: list[str]
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
logger = logging.getLogger(__name__)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class SearchCommand(Command, SessionCommandMixin):
|
| 36 |
+
"""Search for PyPI packages whose name or summary contains <query>."""
|
| 37 |
+
|
| 38 |
+
usage = """
|
| 39 |
+
%prog [options] <query>"""
|
| 40 |
+
ignore_require_venv = True
|
| 41 |
+
|
| 42 |
+
def add_options(self) -> None:
|
| 43 |
+
self.cmd_opts.add_option(
|
| 44 |
+
"-i",
|
| 45 |
+
"--index",
|
| 46 |
+
dest="index",
|
| 47 |
+
metavar="URL",
|
| 48 |
+
default=PyPI.pypi_url,
|
| 49 |
+
help="Base URL of Python Package Index (default %default)",
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 53 |
+
|
| 54 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 55 |
+
if not args:
|
| 56 |
+
raise CommandError("Missing required argument (search query).")
|
| 57 |
+
query = args
|
| 58 |
+
pypi_hits = self.search(query, options)
|
| 59 |
+
hits = transform_hits(pypi_hits)
|
| 60 |
+
|
| 61 |
+
terminal_width = None
|
| 62 |
+
if sys.stdout.isatty():
|
| 63 |
+
terminal_width = shutil.get_terminal_size()[0]
|
| 64 |
+
|
| 65 |
+
print_results(hits, terminal_width=terminal_width)
|
| 66 |
+
if pypi_hits:
|
| 67 |
+
return SUCCESS
|
| 68 |
+
return NO_MATCHES_FOUND
|
| 69 |
+
|
| 70 |
+
def search(self, query: list[str], options: Values) -> list[dict[str, str]]:
|
| 71 |
+
index_url = options.index
|
| 72 |
+
|
| 73 |
+
session = self.get_default_session(options)
|
| 74 |
+
|
| 75 |
+
transport = PipXmlrpcTransport(index_url, session)
|
| 76 |
+
pypi = xmlrpc.client.ServerProxy(index_url, transport)
|
| 77 |
+
try:
|
| 78 |
+
hits = pypi.search({"name": query, "summary": query}, "or")
|
| 79 |
+
except xmlrpc.client.Fault as fault:
|
| 80 |
+
message = (
|
| 81 |
+
f"XMLRPC request failed [code: {fault.faultCode}]\n{fault.faultString}"
|
| 82 |
+
)
|
| 83 |
+
raise CommandError(message)
|
| 84 |
+
assert isinstance(hits, list)
|
| 85 |
+
return hits
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def transform_hits(hits: list[dict[str, str]]) -> list[TransformedHit]:
|
| 89 |
+
"""
|
| 90 |
+
The list from pypi is really a list of versions. We want a list of
|
| 91 |
+
packages with the list of versions stored inline. This converts the
|
| 92 |
+
list from pypi into one we can use.
|
| 93 |
+
"""
|
| 94 |
+
packages: dict[str, TransformedHit] = OrderedDict()
|
| 95 |
+
for hit in hits:
|
| 96 |
+
name = hit["name"]
|
| 97 |
+
summary = hit["summary"]
|
| 98 |
+
version = hit["version"]
|
| 99 |
+
|
| 100 |
+
if name not in packages.keys():
|
| 101 |
+
packages[name] = {
|
| 102 |
+
"name": name,
|
| 103 |
+
"summary": summary,
|
| 104 |
+
"versions": [version],
|
| 105 |
+
}
|
| 106 |
+
else:
|
| 107 |
+
packages[name]["versions"].append(version)
|
| 108 |
+
|
| 109 |
+
# if this is the highest version, replace summary and score
|
| 110 |
+
if version == highest_version(packages[name]["versions"]):
|
| 111 |
+
packages[name]["summary"] = summary
|
| 112 |
+
|
| 113 |
+
return list(packages.values())
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def print_dist_installation_info(latest: str, dist: BaseDistribution | None) -> None:
|
| 117 |
+
if dist is not None:
|
| 118 |
+
with indent_log():
|
| 119 |
+
if dist.version == latest:
|
| 120 |
+
write_output("INSTALLED: %s (latest)", dist.version)
|
| 121 |
+
else:
|
| 122 |
+
write_output("INSTALLED: %s", dist.version)
|
| 123 |
+
if parse_version(latest).pre:
|
| 124 |
+
write_output(
|
| 125 |
+
"LATEST: %s (pre-release; install"
|
| 126 |
+
" with `pip install --pre`)",
|
| 127 |
+
latest,
|
| 128 |
+
)
|
| 129 |
+
else:
|
| 130 |
+
write_output("LATEST: %s", latest)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def get_installed_distribution(name: str) -> BaseDistribution | None:
|
| 134 |
+
env = get_default_environment()
|
| 135 |
+
return env.get_distribution(name)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def print_results(
|
| 139 |
+
hits: list[TransformedHit],
|
| 140 |
+
name_column_width: int | None = None,
|
| 141 |
+
terminal_width: int | None = None,
|
| 142 |
+
) -> None:
|
| 143 |
+
if not hits:
|
| 144 |
+
return
|
| 145 |
+
if name_column_width is None:
|
| 146 |
+
name_column_width = (
|
| 147 |
+
max(
|
| 148 |
+
[
|
| 149 |
+
len(hit["name"]) + len(highest_version(hit.get("versions", ["-"])))
|
| 150 |
+
for hit in hits
|
| 151 |
+
]
|
| 152 |
+
)
|
| 153 |
+
+ 4
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
for hit in hits:
|
| 157 |
+
name = hit["name"]
|
| 158 |
+
summary = hit["summary"] or ""
|
| 159 |
+
latest = highest_version(hit.get("versions", ["-"]))
|
| 160 |
+
if terminal_width is not None:
|
| 161 |
+
target_width = terminal_width - name_column_width - 5
|
| 162 |
+
if target_width > 10:
|
| 163 |
+
# wrap and indent summary to fit terminal
|
| 164 |
+
summary_lines = textwrap.wrap(summary, target_width)
|
| 165 |
+
summary = ("\n" + " " * (name_column_width + 3)).join(summary_lines)
|
| 166 |
+
|
| 167 |
+
name_latest = f"{name} ({latest})"
|
| 168 |
+
line = f"{name_latest:{name_column_width}} - {summary}"
|
| 169 |
+
try:
|
| 170 |
+
write_output(line)
|
| 171 |
+
dist = get_installed_distribution(name)
|
| 172 |
+
print_dist_installation_info(latest, dist)
|
| 173 |
+
except UnicodeEncodeError:
|
| 174 |
+
pass
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def highest_version(versions: list[str]) -> str:
|
| 178 |
+
return max(versions, key=parse_version)
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/show.py
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import string
|
| 5 |
+
from collections.abc import Generator, Iterable, Iterator
|
| 6 |
+
from optparse import Values
|
| 7 |
+
from typing import NamedTuple
|
| 8 |
+
|
| 9 |
+
from pip._vendor.packaging.requirements import InvalidRequirement
|
| 10 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 11 |
+
|
| 12 |
+
from pip._internal.cli.base_command import Command
|
| 13 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 14 |
+
from pip._internal.metadata import BaseDistribution, get_default_environment
|
| 15 |
+
from pip._internal.utils.misc import write_output
|
| 16 |
+
|
| 17 |
+
logger = logging.getLogger(__name__)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def normalize_project_url_label(label: str) -> str:
|
| 21 |
+
# This logic is from PEP 753 (Well-known Project URLs in Metadata).
|
| 22 |
+
chars_to_remove = string.punctuation + string.whitespace
|
| 23 |
+
removal_map = str.maketrans("", "", chars_to_remove)
|
| 24 |
+
return label.translate(removal_map).lower()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class ShowCommand(Command):
|
| 28 |
+
"""
|
| 29 |
+
Show information about one or more installed packages.
|
| 30 |
+
|
| 31 |
+
The output is in RFC-compliant mail header format.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
usage = """
|
| 35 |
+
%prog [options] <package> ..."""
|
| 36 |
+
ignore_require_venv = True
|
| 37 |
+
|
| 38 |
+
def add_options(self) -> None:
|
| 39 |
+
self.cmd_opts.add_option(
|
| 40 |
+
"-f",
|
| 41 |
+
"--files",
|
| 42 |
+
dest="files",
|
| 43 |
+
action="store_true",
|
| 44 |
+
default=False,
|
| 45 |
+
help="Show the full list of installed files for each package.",
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 49 |
+
|
| 50 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 51 |
+
if not args:
|
| 52 |
+
logger.warning("ERROR: Please provide a package name or names.")
|
| 53 |
+
return ERROR
|
| 54 |
+
query = args
|
| 55 |
+
|
| 56 |
+
results = search_packages_info(query)
|
| 57 |
+
if not print_results(
|
| 58 |
+
results, list_files=options.files, verbose=options.verbose
|
| 59 |
+
):
|
| 60 |
+
return ERROR
|
| 61 |
+
return SUCCESS
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class _PackageInfo(NamedTuple):
|
| 65 |
+
name: str
|
| 66 |
+
version: str
|
| 67 |
+
location: str
|
| 68 |
+
editable_project_location: str | None
|
| 69 |
+
requires: list[str]
|
| 70 |
+
required_by: list[str]
|
| 71 |
+
installer: str
|
| 72 |
+
metadata_version: str
|
| 73 |
+
classifiers: list[str]
|
| 74 |
+
summary: str
|
| 75 |
+
homepage: str
|
| 76 |
+
project_urls: list[str]
|
| 77 |
+
author: str
|
| 78 |
+
author_email: str
|
| 79 |
+
license: str
|
| 80 |
+
license_expression: str
|
| 81 |
+
entry_points: list[str]
|
| 82 |
+
files: list[str] | None
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def search_packages_info(query: list[str]) -> Generator[_PackageInfo, None, None]:
|
| 86 |
+
"""
|
| 87 |
+
Gather details from installed distributions. Print distribution name,
|
| 88 |
+
version, location, and installed files. Installed files requires a
|
| 89 |
+
pip generated 'installed-files.txt' in the distributions '.egg-info'
|
| 90 |
+
directory.
|
| 91 |
+
"""
|
| 92 |
+
env = get_default_environment()
|
| 93 |
+
|
| 94 |
+
installed = {dist.canonical_name: dist for dist in env.iter_all_distributions()}
|
| 95 |
+
query_names = [canonicalize_name(name) for name in query]
|
| 96 |
+
missing = sorted(
|
| 97 |
+
[name for name, pkg in zip(query, query_names) if pkg not in installed]
|
| 98 |
+
)
|
| 99 |
+
if missing:
|
| 100 |
+
logger.warning("Package(s) not found: %s", ", ".join(missing))
|
| 101 |
+
|
| 102 |
+
def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]:
|
| 103 |
+
return (
|
| 104 |
+
dist.metadata["Name"] or "UNKNOWN"
|
| 105 |
+
for dist in installed.values()
|
| 106 |
+
if current_dist.canonical_name
|
| 107 |
+
in {canonicalize_name(d.name) for d in dist.iter_dependencies()}
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
for query_name in query_names:
|
| 111 |
+
try:
|
| 112 |
+
dist = installed[query_name]
|
| 113 |
+
except KeyError:
|
| 114 |
+
continue
|
| 115 |
+
|
| 116 |
+
try:
|
| 117 |
+
requires = sorted(
|
| 118 |
+
# Avoid duplicates in requirements (e.g. due to environment markers).
|
| 119 |
+
{req.name for req in dist.iter_dependencies()},
|
| 120 |
+
key=str.lower,
|
| 121 |
+
)
|
| 122 |
+
except InvalidRequirement:
|
| 123 |
+
requires = sorted(dist.iter_raw_dependencies(), key=str.lower)
|
| 124 |
+
|
| 125 |
+
try:
|
| 126 |
+
required_by = sorted(_get_requiring_packages(dist), key=str.lower)
|
| 127 |
+
except InvalidRequirement:
|
| 128 |
+
required_by = ["#N/A"]
|
| 129 |
+
|
| 130 |
+
try:
|
| 131 |
+
entry_points_text = dist.read_text("entry_points.txt")
|
| 132 |
+
entry_points = entry_points_text.splitlines(keepends=False)
|
| 133 |
+
except FileNotFoundError:
|
| 134 |
+
entry_points = []
|
| 135 |
+
|
| 136 |
+
files_iter = dist.iter_declared_entries()
|
| 137 |
+
if files_iter is None:
|
| 138 |
+
files: list[str] | None = None
|
| 139 |
+
else:
|
| 140 |
+
files = sorted(files_iter)
|
| 141 |
+
|
| 142 |
+
metadata = dist.metadata
|
| 143 |
+
|
| 144 |
+
project_urls = metadata.get_all("Project-URL", [])
|
| 145 |
+
homepage = metadata.get("Home-page", "")
|
| 146 |
+
if not homepage:
|
| 147 |
+
# It's common that there is a "homepage" Project-URL, but Home-page
|
| 148 |
+
# remains unset (especially as PEP 621 doesn't surface the field).
|
| 149 |
+
for url in project_urls:
|
| 150 |
+
url_label, url = url.split(",", maxsplit=1)
|
| 151 |
+
normalized_label = normalize_project_url_label(url_label)
|
| 152 |
+
if normalized_label == "homepage":
|
| 153 |
+
homepage = url.strip()
|
| 154 |
+
break
|
| 155 |
+
|
| 156 |
+
yield _PackageInfo(
|
| 157 |
+
name=dist.raw_name,
|
| 158 |
+
version=dist.raw_version,
|
| 159 |
+
location=dist.location or "",
|
| 160 |
+
editable_project_location=dist.editable_project_location,
|
| 161 |
+
requires=requires,
|
| 162 |
+
required_by=required_by,
|
| 163 |
+
installer=dist.installer,
|
| 164 |
+
metadata_version=dist.metadata_version or "",
|
| 165 |
+
classifiers=metadata.get_all("Classifier", []),
|
| 166 |
+
summary=metadata.get("Summary", ""),
|
| 167 |
+
homepage=homepage,
|
| 168 |
+
project_urls=project_urls,
|
| 169 |
+
author=metadata.get("Author", ""),
|
| 170 |
+
author_email=metadata.get("Author-email", ""),
|
| 171 |
+
license=metadata.get("License", ""),
|
| 172 |
+
license_expression=metadata.get("License-Expression", ""),
|
| 173 |
+
entry_points=entry_points,
|
| 174 |
+
files=files,
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def print_results(
|
| 179 |
+
distributions: Iterable[_PackageInfo],
|
| 180 |
+
list_files: bool,
|
| 181 |
+
verbose: bool,
|
| 182 |
+
) -> bool:
|
| 183 |
+
"""
|
| 184 |
+
Print the information from installed distributions found.
|
| 185 |
+
"""
|
| 186 |
+
results_printed = False
|
| 187 |
+
for i, dist in enumerate(distributions):
|
| 188 |
+
results_printed = True
|
| 189 |
+
if i > 0:
|
| 190 |
+
write_output("---")
|
| 191 |
+
|
| 192 |
+
metadata_version_tuple = tuple(map(int, dist.metadata_version.split(".")))
|
| 193 |
+
|
| 194 |
+
write_output("Name: %s", dist.name)
|
| 195 |
+
write_output("Version: %s", dist.version)
|
| 196 |
+
write_output("Summary: %s", dist.summary)
|
| 197 |
+
write_output("Home-page: %s", dist.homepage)
|
| 198 |
+
write_output("Author: %s", dist.author)
|
| 199 |
+
write_output("Author-email: %s", dist.author_email)
|
| 200 |
+
if metadata_version_tuple >= (2, 4) and dist.license_expression:
|
| 201 |
+
write_output("License-Expression: %s", dist.license_expression)
|
| 202 |
+
else:
|
| 203 |
+
write_output("License: %s", dist.license)
|
| 204 |
+
write_output("Location: %s", dist.location)
|
| 205 |
+
if dist.editable_project_location is not None:
|
| 206 |
+
write_output(
|
| 207 |
+
"Editable project location: %s", dist.editable_project_location
|
| 208 |
+
)
|
| 209 |
+
write_output("Requires: %s", ", ".join(dist.requires))
|
| 210 |
+
write_output("Required-by: %s", ", ".join(dist.required_by))
|
| 211 |
+
|
| 212 |
+
if verbose:
|
| 213 |
+
write_output("Metadata-Version: %s", dist.metadata_version)
|
| 214 |
+
write_output("Installer: %s", dist.installer)
|
| 215 |
+
write_output("Classifiers:")
|
| 216 |
+
for classifier in dist.classifiers:
|
| 217 |
+
write_output(" %s", classifier)
|
| 218 |
+
write_output("Entry-points:")
|
| 219 |
+
for entry in dist.entry_points:
|
| 220 |
+
write_output(" %s", entry.strip())
|
| 221 |
+
write_output("Project-URLs:")
|
| 222 |
+
for project_url in dist.project_urls:
|
| 223 |
+
write_output(" %s", project_url)
|
| 224 |
+
if list_files:
|
| 225 |
+
write_output("Files:")
|
| 226 |
+
if dist.files is None:
|
| 227 |
+
write_output("Cannot locate RECORD or installed-files.txt")
|
| 228 |
+
else:
|
| 229 |
+
for line in dist.files:
|
| 230 |
+
write_output(" %s", line.strip())
|
| 231 |
+
return results_printed
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/uninstall.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from optparse import Values
|
| 3 |
+
|
| 4 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 5 |
+
|
| 6 |
+
from pip._internal.cli import cmdoptions
|
| 7 |
+
from pip._internal.cli.base_command import Command
|
| 8 |
+
from pip._internal.cli.index_command import SessionCommandMixin
|
| 9 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 10 |
+
from pip._internal.exceptions import InstallationError
|
| 11 |
+
from pip._internal.req import parse_requirements
|
| 12 |
+
from pip._internal.req.constructors import (
|
| 13 |
+
install_req_from_line,
|
| 14 |
+
install_req_from_parsed_requirement,
|
| 15 |
+
)
|
| 16 |
+
from pip._internal.utils.misc import (
|
| 17 |
+
check_externally_managed,
|
| 18 |
+
protect_pip_from_modification_on_windows,
|
| 19 |
+
warn_if_run_as_root,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
logger = logging.getLogger(__name__)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class UninstallCommand(Command, SessionCommandMixin):
|
| 26 |
+
"""
|
| 27 |
+
Uninstall packages.
|
| 28 |
+
|
| 29 |
+
pip is able to uninstall most installed packages. Known exceptions are:
|
| 30 |
+
|
| 31 |
+
- Pure distutils packages installed with ``python setup.py install``, which
|
| 32 |
+
leave behind no metadata to determine what files were installed.
|
| 33 |
+
- Script wrappers installed by ``python setup.py develop``.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
usage = """
|
| 37 |
+
%prog [options] <package> ...
|
| 38 |
+
%prog [options] -r <requirements file> ..."""
|
| 39 |
+
|
| 40 |
+
def add_options(self) -> None:
|
| 41 |
+
self.cmd_opts.add_option(
|
| 42 |
+
"-r",
|
| 43 |
+
"--requirement",
|
| 44 |
+
dest="requirements",
|
| 45 |
+
action="append",
|
| 46 |
+
default=[],
|
| 47 |
+
metavar="file",
|
| 48 |
+
help=(
|
| 49 |
+
"Uninstall all the packages listed in the given requirements "
|
| 50 |
+
"file. This option can be used multiple times."
|
| 51 |
+
),
|
| 52 |
+
)
|
| 53 |
+
self.cmd_opts.add_option(
|
| 54 |
+
"-y",
|
| 55 |
+
"--yes",
|
| 56 |
+
dest="yes",
|
| 57 |
+
action="store_true",
|
| 58 |
+
help="Don't ask for confirmation of uninstall deletions.",
|
| 59 |
+
)
|
| 60 |
+
self.cmd_opts.add_option(cmdoptions.root_user_action())
|
| 61 |
+
self.cmd_opts.add_option(cmdoptions.override_externally_managed())
|
| 62 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 63 |
+
|
| 64 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 65 |
+
session = self.get_default_session(options)
|
| 66 |
+
|
| 67 |
+
reqs_to_uninstall = {}
|
| 68 |
+
for name in args:
|
| 69 |
+
req = install_req_from_line(
|
| 70 |
+
name,
|
| 71 |
+
isolated=options.isolated_mode,
|
| 72 |
+
)
|
| 73 |
+
if req.name:
|
| 74 |
+
reqs_to_uninstall[canonicalize_name(req.name)] = req
|
| 75 |
+
else:
|
| 76 |
+
logger.warning(
|
| 77 |
+
"Invalid requirement: %r ignored -"
|
| 78 |
+
" the uninstall command expects named"
|
| 79 |
+
" requirements.",
|
| 80 |
+
name,
|
| 81 |
+
)
|
| 82 |
+
for filename in options.requirements:
|
| 83 |
+
for parsed_req in parse_requirements(
|
| 84 |
+
filename, options=options, session=session
|
| 85 |
+
):
|
| 86 |
+
req = install_req_from_parsed_requirement(
|
| 87 |
+
parsed_req, isolated=options.isolated_mode
|
| 88 |
+
)
|
| 89 |
+
if req.name:
|
| 90 |
+
reqs_to_uninstall[canonicalize_name(req.name)] = req
|
| 91 |
+
if not reqs_to_uninstall:
|
| 92 |
+
raise InstallationError(
|
| 93 |
+
f"You must give at least one requirement to {self.name} (see "
|
| 94 |
+
f'"pip help {self.name}")'
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
if not options.override_externally_managed:
|
| 98 |
+
check_externally_managed()
|
| 99 |
+
|
| 100 |
+
protect_pip_from_modification_on_windows(
|
| 101 |
+
modifying_pip="pip" in reqs_to_uninstall
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
for req in reqs_to_uninstall.values():
|
| 105 |
+
uninstall_pathset = req.uninstall(
|
| 106 |
+
auto_confirm=options.yes,
|
| 107 |
+
verbose=self.verbosity > 0,
|
| 108 |
+
)
|
| 109 |
+
if uninstall_pathset:
|
| 110 |
+
uninstall_pathset.commit()
|
| 111 |
+
if options.root_user_action == "warn":
|
| 112 |
+
warn_if_run_as_root()
|
| 113 |
+
return SUCCESS
|
.venv/lib/python3.12/site-packages/pip/_internal/commands/wheel.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
from optparse import Values
|
| 5 |
+
|
| 6 |
+
from pip._internal.cache import WheelCache
|
| 7 |
+
from pip._internal.cli import cmdoptions
|
| 8 |
+
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
|
| 9 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 10 |
+
from pip._internal.exceptions import CommandError
|
| 11 |
+
from pip._internal.operations.build.build_tracker import get_build_tracker
|
| 12 |
+
from pip._internal.req.req_install import (
|
| 13 |
+
InstallRequirement,
|
| 14 |
+
)
|
| 15 |
+
from pip._internal.utils.misc import ensure_dir, normalize_path
|
| 16 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 17 |
+
from pip._internal.wheel_builder import build
|
| 18 |
+
|
| 19 |
+
logger = logging.getLogger(__name__)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class WheelCommand(RequirementCommand):
|
| 23 |
+
"""
|
| 24 |
+
Build Wheel archives for your requirements and dependencies.
|
| 25 |
+
|
| 26 |
+
Wheel is a built-package format, and offers the advantage of not
|
| 27 |
+
recompiling your software during every install. For more details, see the
|
| 28 |
+
wheel docs: https://wheel.readthedocs.io/en/latest/
|
| 29 |
+
|
| 30 |
+
'pip wheel' uses the build system interface as described here:
|
| 31 |
+
https://pip.pypa.io/en/stable/reference/build-system/
|
| 32 |
+
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
usage = """
|
| 36 |
+
%prog [options] <requirement specifier> ...
|
| 37 |
+
%prog [options] -r <requirements file> ...
|
| 38 |
+
%prog [options] [-e] <vcs project url> ...
|
| 39 |
+
%prog [options] [-e] <local project path> ...
|
| 40 |
+
%prog [options] <archive url/path> ..."""
|
| 41 |
+
|
| 42 |
+
def add_options(self) -> None:
|
| 43 |
+
self.cmd_opts.add_option(
|
| 44 |
+
"-w",
|
| 45 |
+
"--wheel-dir",
|
| 46 |
+
dest="wheel_dir",
|
| 47 |
+
metavar="dir",
|
| 48 |
+
default=os.curdir,
|
| 49 |
+
help=(
|
| 50 |
+
"Build wheels into <dir>, where the default is the "
|
| 51 |
+
"current working directory."
|
| 52 |
+
),
|
| 53 |
+
)
|
| 54 |
+
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
|
| 55 |
+
self.cmd_opts.add_option(cmdoptions.use_pep517())
|
| 56 |
+
self.cmd_opts.add_option(cmdoptions.check_build_deps())
|
| 57 |
+
self.cmd_opts.add_option(cmdoptions.constraints())
|
| 58 |
+
self.cmd_opts.add_option(cmdoptions.build_constraints())
|
| 59 |
+
self.cmd_opts.add_option(cmdoptions.editable())
|
| 60 |
+
self.cmd_opts.add_option(cmdoptions.requirements())
|
| 61 |
+
self.cmd_opts.add_option(cmdoptions.requirements_from_scripts())
|
| 62 |
+
self.cmd_opts.add_option(cmdoptions.src())
|
| 63 |
+
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
| 64 |
+
self.cmd_opts.add_option(cmdoptions.no_deps())
|
| 65 |
+
self.cmd_opts.add_option(cmdoptions.progress_bar())
|
| 66 |
+
|
| 67 |
+
self.cmd_opts.add_option(
|
| 68 |
+
"--no-verify",
|
| 69 |
+
dest="no_verify",
|
| 70 |
+
action="store_true",
|
| 71 |
+
default=False,
|
| 72 |
+
help="Don't verify if built wheel is valid.",
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
self.cmd_opts.add_option(cmdoptions.config_settings())
|
| 76 |
+
|
| 77 |
+
self.cmd_opts.add_option(cmdoptions.require_hashes())
|
| 78 |
+
|
| 79 |
+
index_opts = cmdoptions.make_option_group(
|
| 80 |
+
cmdoptions.index_group,
|
| 81 |
+
self.parser,
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
selection_opts = cmdoptions.make_option_group(
|
| 85 |
+
cmdoptions.package_selection_group,
|
| 86 |
+
self.parser,
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
self.parser.insert_option_group(0, index_opts)
|
| 90 |
+
self.parser.insert_option_group(0, selection_opts)
|
| 91 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 92 |
+
|
| 93 |
+
@with_cleanup
|
| 94 |
+
def run(self, options: Values, args: list[str]) -> int:
|
| 95 |
+
cmdoptions.check_build_constraints(options)
|
| 96 |
+
cmdoptions.check_release_control_exclusive(options)
|
| 97 |
+
|
| 98 |
+
session = self.get_default_session(options)
|
| 99 |
+
|
| 100 |
+
finder = self._build_package_finder(options, session)
|
| 101 |
+
|
| 102 |
+
options.wheel_dir = normalize_path(options.wheel_dir)
|
| 103 |
+
ensure_dir(options.wheel_dir)
|
| 104 |
+
|
| 105 |
+
build_tracker = self.enter_context(get_build_tracker())
|
| 106 |
+
|
| 107 |
+
directory = TempDirectory(
|
| 108 |
+
delete=not options.no_clean,
|
| 109 |
+
kind="wheel",
|
| 110 |
+
globally_managed=True,
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
reqs = self.get_requirements(args, options, finder, session)
|
| 114 |
+
|
| 115 |
+
wheel_cache = WheelCache(options.cache_dir)
|
| 116 |
+
|
| 117 |
+
preparer = self.make_requirement_preparer(
|
| 118 |
+
temp_build_dir=directory,
|
| 119 |
+
options=options,
|
| 120 |
+
build_tracker=build_tracker,
|
| 121 |
+
session=session,
|
| 122 |
+
finder=finder,
|
| 123 |
+
download_dir=options.wheel_dir,
|
| 124 |
+
use_user_site=False,
|
| 125 |
+
verbosity=self.verbosity,
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
resolver = self.make_resolver(
|
| 129 |
+
preparer=preparer,
|
| 130 |
+
finder=finder,
|
| 131 |
+
options=options,
|
| 132 |
+
wheel_cache=wheel_cache,
|
| 133 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
self.trace_basic_info(finder)
|
| 137 |
+
|
| 138 |
+
requirement_set = resolver.resolve(reqs, check_supported_wheels=True)
|
| 139 |
+
|
| 140 |
+
preparer.prepare_linked_requirements_more(requirement_set.requirements.values())
|
| 141 |
+
|
| 142 |
+
reqs_to_build: list[InstallRequirement] = []
|
| 143 |
+
for req in requirement_set.requirements.values():
|
| 144 |
+
if req.is_wheel:
|
| 145 |
+
preparer.save_linked_requirement(req)
|
| 146 |
+
else:
|
| 147 |
+
reqs_to_build.append(req)
|
| 148 |
+
|
| 149 |
+
# build wheels
|
| 150 |
+
build_successes, build_failures = build(
|
| 151 |
+
reqs_to_build,
|
| 152 |
+
wheel_cache=wheel_cache,
|
| 153 |
+
verify=(not options.no_verify),
|
| 154 |
+
)
|
| 155 |
+
for req in build_successes:
|
| 156 |
+
assert req.link and req.link.is_wheel
|
| 157 |
+
assert req.local_file_path
|
| 158 |
+
# copy from cache to target directory
|
| 159 |
+
try:
|
| 160 |
+
shutil.copy(req.local_file_path, options.wheel_dir)
|
| 161 |
+
except OSError as e:
|
| 162 |
+
logger.warning(
|
| 163 |
+
"Building wheel for %s failed: %s",
|
| 164 |
+
req.name,
|
| 165 |
+
e,
|
| 166 |
+
)
|
| 167 |
+
build_failures.append(req)
|
| 168 |
+
if len(build_failures) != 0:
|
| 169 |
+
raise CommandError("Failed to build one or more wheels")
|
| 170 |
+
|
| 171 |
+
return SUCCESS
|
.venv/lib/python3.12/site-packages/pip/_internal/configuration.py
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Configuration management setup
|
| 2 |
+
|
| 3 |
+
Some terminology:
|
| 4 |
+
- name
|
| 5 |
+
As written in config files.
|
| 6 |
+
- value
|
| 7 |
+
Value associated with a name
|
| 8 |
+
- key
|
| 9 |
+
Name combined with it's section (section.name)
|
| 10 |
+
- variant
|
| 11 |
+
A single word describing where the configuration key-value pair came from
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import configparser
|
| 17 |
+
import locale
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
from collections.abc import Iterable
|
| 21 |
+
from typing import Any, NewType
|
| 22 |
+
|
| 23 |
+
from pip._internal.exceptions import (
|
| 24 |
+
ConfigurationError,
|
| 25 |
+
ConfigurationFileCouldNotBeLoaded,
|
| 26 |
+
)
|
| 27 |
+
from pip._internal.utils import appdirs
|
| 28 |
+
from pip._internal.utils.compat import WINDOWS
|
| 29 |
+
from pip._internal.utils.logging import getLogger
|
| 30 |
+
from pip._internal.utils.misc import ensure_dir, enum
|
| 31 |
+
|
| 32 |
+
RawConfigParser = configparser.RawConfigParser # Shorthand
|
| 33 |
+
Kind = NewType("Kind", str)
|
| 34 |
+
|
| 35 |
+
CONFIG_BASENAME = "pip.ini" if WINDOWS else "pip.conf"
|
| 36 |
+
ENV_NAMES_IGNORED = "version", "help"
|
| 37 |
+
|
| 38 |
+
# The kinds of configurations there are.
|
| 39 |
+
kinds = enum(
|
| 40 |
+
USER="user", # User Specific
|
| 41 |
+
GLOBAL="global", # System Wide
|
| 42 |
+
SITE="site", # [Virtual] Environment Specific
|
| 43 |
+
ENV="env", # from PIP_CONFIG_FILE
|
| 44 |
+
ENV_VAR="env-var", # from Environment Variables
|
| 45 |
+
)
|
| 46 |
+
OVERRIDE_ORDER = kinds.GLOBAL, kinds.USER, kinds.SITE, kinds.ENV, kinds.ENV_VAR
|
| 47 |
+
VALID_LOAD_ONLY = kinds.USER, kinds.GLOBAL, kinds.SITE
|
| 48 |
+
|
| 49 |
+
logger = getLogger(__name__)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# NOTE: Maybe use the optionx attribute to normalize keynames.
|
| 53 |
+
def _normalize_name(name: str) -> str:
|
| 54 |
+
"""Make a name consistent regardless of source (environment or file)"""
|
| 55 |
+
name = name.lower().replace("_", "-")
|
| 56 |
+
name = name.removeprefix("--") # only prefer long opts
|
| 57 |
+
return name
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _disassemble_key(name: str) -> list[str]:
|
| 61 |
+
if "." not in name:
|
| 62 |
+
error_message = (
|
| 63 |
+
"Key does not contain dot separated section and key. "
|
| 64 |
+
f"Perhaps you wanted to use 'global.{name}' instead?"
|
| 65 |
+
)
|
| 66 |
+
raise ConfigurationError(error_message)
|
| 67 |
+
return name.split(".", 1)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def get_configuration_files() -> dict[Kind, list[str]]:
|
| 71 |
+
global_config_files = [
|
| 72 |
+
os.path.join(path, CONFIG_BASENAME) for path in appdirs.site_config_dirs("pip")
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
|
| 76 |
+
legacy_config_file = os.path.join(
|
| 77 |
+
os.path.expanduser("~"),
|
| 78 |
+
"pip" if WINDOWS else ".pip",
|
| 79 |
+
CONFIG_BASENAME,
|
| 80 |
+
)
|
| 81 |
+
new_config_file = os.path.join(appdirs.user_config_dir("pip"), CONFIG_BASENAME)
|
| 82 |
+
return {
|
| 83 |
+
kinds.GLOBAL: global_config_files,
|
| 84 |
+
kinds.SITE: [site_config_file],
|
| 85 |
+
kinds.USER: [legacy_config_file, new_config_file],
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class Configuration:
|
| 90 |
+
"""Handles management of configuration.
|
| 91 |
+
|
| 92 |
+
Provides an interface to accessing and managing configuration files.
|
| 93 |
+
|
| 94 |
+
This class converts provides an API that takes "section.key-name" style
|
| 95 |
+
keys and stores the value associated with it as "key-name" under the
|
| 96 |
+
section "section".
|
| 97 |
+
|
| 98 |
+
This allows for a clean interface wherein the both the section and the
|
| 99 |
+
key-name are preserved in an easy to manage form in the configuration files
|
| 100 |
+
and the data stored is also nice.
|
| 101 |
+
"""
|
| 102 |
+
|
| 103 |
+
def __init__(self, isolated: bool, load_only: Kind | None = None) -> None:
|
| 104 |
+
super().__init__()
|
| 105 |
+
|
| 106 |
+
if load_only is not None and load_only not in VALID_LOAD_ONLY:
|
| 107 |
+
raise ConfigurationError(
|
| 108 |
+
"Got invalid value for load_only - should be one of {}".format(
|
| 109 |
+
", ".join(map(repr, VALID_LOAD_ONLY))
|
| 110 |
+
)
|
| 111 |
+
)
|
| 112 |
+
self.isolated = isolated
|
| 113 |
+
self.load_only = load_only
|
| 114 |
+
|
| 115 |
+
# Because we keep track of where we got the data from
|
| 116 |
+
self._parsers: dict[Kind, list[tuple[str, RawConfigParser]]] = {
|
| 117 |
+
variant: [] for variant in OVERRIDE_ORDER
|
| 118 |
+
}
|
| 119 |
+
self._config: dict[Kind, dict[str, dict[str, Any]]] = {
|
| 120 |
+
variant: {} for variant in OVERRIDE_ORDER
|
| 121 |
+
}
|
| 122 |
+
self._modified_parsers: list[tuple[str, RawConfigParser]] = []
|
| 123 |
+
|
| 124 |
+
def load(self) -> None:
|
| 125 |
+
"""Loads configuration from configuration files and environment"""
|
| 126 |
+
self._load_config_files()
|
| 127 |
+
if not self.isolated:
|
| 128 |
+
self._load_environment_vars()
|
| 129 |
+
|
| 130 |
+
def get_file_to_edit(self) -> str | None:
|
| 131 |
+
"""Returns the file with highest priority in configuration"""
|
| 132 |
+
assert self.load_only is not None, "Need to be specified a file to be editing"
|
| 133 |
+
|
| 134 |
+
try:
|
| 135 |
+
return self._get_parser_to_modify()[0]
|
| 136 |
+
except IndexError:
|
| 137 |
+
return None
|
| 138 |
+
|
| 139 |
+
def items(self) -> Iterable[tuple[str, Any]]:
|
| 140 |
+
"""Returns key-value pairs like dict.items() representing the loaded
|
| 141 |
+
configuration
|
| 142 |
+
"""
|
| 143 |
+
return self._dictionary.items()
|
| 144 |
+
|
| 145 |
+
def get_value(self, key: str) -> Any:
|
| 146 |
+
"""Get a value from the configuration."""
|
| 147 |
+
orig_key = key
|
| 148 |
+
key = _normalize_name(key)
|
| 149 |
+
try:
|
| 150 |
+
clean_config: dict[str, Any] = {}
|
| 151 |
+
for file_values in self._dictionary.values():
|
| 152 |
+
clean_config.update(file_values)
|
| 153 |
+
return clean_config[key]
|
| 154 |
+
except KeyError:
|
| 155 |
+
# disassembling triggers a more useful error message than simply
|
| 156 |
+
# "No such key" in the case that the key isn't in the form command.option
|
| 157 |
+
_disassemble_key(key)
|
| 158 |
+
raise ConfigurationError(f"No such key - {orig_key}")
|
| 159 |
+
|
| 160 |
+
def set_value(self, key: str, value: Any) -> None:
|
| 161 |
+
"""Modify a value in the configuration."""
|
| 162 |
+
key = _normalize_name(key)
|
| 163 |
+
self._ensure_have_load_only()
|
| 164 |
+
|
| 165 |
+
assert self.load_only
|
| 166 |
+
fname, parser = self._get_parser_to_modify()
|
| 167 |
+
|
| 168 |
+
if parser is not None:
|
| 169 |
+
section, name = _disassemble_key(key)
|
| 170 |
+
|
| 171 |
+
# Modify the parser and the configuration
|
| 172 |
+
if not parser.has_section(section):
|
| 173 |
+
parser.add_section(section)
|
| 174 |
+
parser.set(section, name, value)
|
| 175 |
+
|
| 176 |
+
self._config[self.load_only].setdefault(fname, {})
|
| 177 |
+
self._config[self.load_only][fname][key] = value
|
| 178 |
+
self._mark_as_modified(fname, parser)
|
| 179 |
+
|
| 180 |
+
def unset_value(self, key: str) -> None:
|
| 181 |
+
"""Unset a value in the configuration."""
|
| 182 |
+
orig_key = key
|
| 183 |
+
key = _normalize_name(key)
|
| 184 |
+
self._ensure_have_load_only()
|
| 185 |
+
|
| 186 |
+
assert self.load_only
|
| 187 |
+
fname, parser = self._get_parser_to_modify()
|
| 188 |
+
|
| 189 |
+
if (
|
| 190 |
+
key not in self._config[self.load_only][fname]
|
| 191 |
+
and key not in self._config[self.load_only]
|
| 192 |
+
):
|
| 193 |
+
raise ConfigurationError(f"No such key - {orig_key}")
|
| 194 |
+
|
| 195 |
+
if parser is not None:
|
| 196 |
+
section, name = _disassemble_key(key)
|
| 197 |
+
if not (
|
| 198 |
+
parser.has_section(section) and parser.remove_option(section, name)
|
| 199 |
+
):
|
| 200 |
+
# The option was not removed.
|
| 201 |
+
raise ConfigurationError(
|
| 202 |
+
"Fatal Internal error [id=1]. Please report as a bug."
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
# The section may be empty after the option was removed.
|
| 206 |
+
if not parser.items(section):
|
| 207 |
+
parser.remove_section(section)
|
| 208 |
+
self._mark_as_modified(fname, parser)
|
| 209 |
+
try:
|
| 210 |
+
del self._config[self.load_only][fname][key]
|
| 211 |
+
except KeyError:
|
| 212 |
+
del self._config[self.load_only][key]
|
| 213 |
+
|
| 214 |
+
def save(self) -> None:
|
| 215 |
+
"""Save the current in-memory state."""
|
| 216 |
+
self._ensure_have_load_only()
|
| 217 |
+
|
| 218 |
+
for fname, parser in self._modified_parsers:
|
| 219 |
+
logger.info("Writing to %s", fname)
|
| 220 |
+
|
| 221 |
+
# Ensure directory exists.
|
| 222 |
+
ensure_dir(os.path.dirname(fname))
|
| 223 |
+
|
| 224 |
+
# Ensure directory's permission(need to be writeable)
|
| 225 |
+
try:
|
| 226 |
+
with open(fname, "w") as f:
|
| 227 |
+
parser.write(f)
|
| 228 |
+
except OSError as error:
|
| 229 |
+
raise ConfigurationError(
|
| 230 |
+
f"An error occurred while writing to the configuration file "
|
| 231 |
+
f"{fname}: {error}"
|
| 232 |
+
)
|
| 233 |
+
|
| 234 |
+
#
|
| 235 |
+
# Private routines
|
| 236 |
+
#
|
| 237 |
+
|
| 238 |
+
def _ensure_have_load_only(self) -> None:
|
| 239 |
+
if self.load_only is None:
|
| 240 |
+
raise ConfigurationError("Needed a specific file to be modifying.")
|
| 241 |
+
logger.debug("Will be working with %s variant only", self.load_only)
|
| 242 |
+
|
| 243 |
+
@property
|
| 244 |
+
def _dictionary(self) -> dict[str, dict[str, Any]]:
|
| 245 |
+
"""A dictionary representing the loaded configuration."""
|
| 246 |
+
# NOTE: Dictionaries are not populated if not loaded. So, conditionals
|
| 247 |
+
# are not needed here.
|
| 248 |
+
retval = {}
|
| 249 |
+
|
| 250 |
+
for variant in OVERRIDE_ORDER:
|
| 251 |
+
retval.update(self._config[variant])
|
| 252 |
+
|
| 253 |
+
return retval
|
| 254 |
+
|
| 255 |
+
def _load_config_files(self) -> None:
|
| 256 |
+
"""Loads configuration from configuration files"""
|
| 257 |
+
config_files = dict(self.iter_config_files())
|
| 258 |
+
if config_files[kinds.ENV][0:1] == [os.devnull]:
|
| 259 |
+
logger.debug(
|
| 260 |
+
"Skipping loading configuration files due to "
|
| 261 |
+
"environment's PIP_CONFIG_FILE being os.devnull"
|
| 262 |
+
)
|
| 263 |
+
return
|
| 264 |
+
|
| 265 |
+
for variant, files in config_files.items():
|
| 266 |
+
for fname in files:
|
| 267 |
+
# If there's specific variant set in `load_only`, load only
|
| 268 |
+
# that variant, not the others.
|
| 269 |
+
if self.load_only is not None and variant != self.load_only:
|
| 270 |
+
logger.debug("Skipping file '%s' (variant: %s)", fname, variant)
|
| 271 |
+
continue
|
| 272 |
+
|
| 273 |
+
parser = self._load_file(variant, fname)
|
| 274 |
+
|
| 275 |
+
# Keeping track of the parsers used
|
| 276 |
+
self._parsers[variant].append((fname, parser))
|
| 277 |
+
|
| 278 |
+
def _load_file(self, variant: Kind, fname: str) -> RawConfigParser:
|
| 279 |
+
logger.verbose("For variant '%s', will try loading '%s'", variant, fname)
|
| 280 |
+
parser = self._construct_parser(fname)
|
| 281 |
+
|
| 282 |
+
for section in parser.sections():
|
| 283 |
+
items = parser.items(section)
|
| 284 |
+
self._config[variant].setdefault(fname, {})
|
| 285 |
+
self._config[variant][fname].update(self._normalized_keys(section, items))
|
| 286 |
+
|
| 287 |
+
return parser
|
| 288 |
+
|
| 289 |
+
def _construct_parser(self, fname: str) -> RawConfigParser:
|
| 290 |
+
parser = configparser.RawConfigParser()
|
| 291 |
+
# If there is no such file, don't bother reading it but create the
|
| 292 |
+
# parser anyway, to hold the data.
|
| 293 |
+
# Doing this is useful when modifying and saving files, where we don't
|
| 294 |
+
# need to construct a parser.
|
| 295 |
+
if os.path.exists(fname):
|
| 296 |
+
locale_encoding = locale.getpreferredencoding(False)
|
| 297 |
+
try:
|
| 298 |
+
parser.read(fname, encoding=locale_encoding)
|
| 299 |
+
except UnicodeDecodeError:
|
| 300 |
+
# See https://github.com/pypa/pip/issues/4963
|
| 301 |
+
raise ConfigurationFileCouldNotBeLoaded(
|
| 302 |
+
reason=f"contains invalid {locale_encoding} characters",
|
| 303 |
+
fname=fname,
|
| 304 |
+
)
|
| 305 |
+
except configparser.Error as error:
|
| 306 |
+
# See https://github.com/pypa/pip/issues/4893
|
| 307 |
+
raise ConfigurationFileCouldNotBeLoaded(error=error)
|
| 308 |
+
return parser
|
| 309 |
+
|
| 310 |
+
def _load_environment_vars(self) -> None:
|
| 311 |
+
"""Loads configuration from environment variables"""
|
| 312 |
+
self._config[kinds.ENV_VAR].setdefault(":env:", {})
|
| 313 |
+
self._config[kinds.ENV_VAR][":env:"].update(
|
| 314 |
+
self._normalized_keys(":env:", self.get_environ_vars())
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
def _normalized_keys(
|
| 318 |
+
self, section: str, items: Iterable[tuple[str, Any]]
|
| 319 |
+
) -> dict[str, Any]:
|
| 320 |
+
"""Normalizes items to construct a dictionary with normalized keys.
|
| 321 |
+
|
| 322 |
+
This routine is where the names become keys and are made the same
|
| 323 |
+
regardless of source - configuration files or environment.
|
| 324 |
+
"""
|
| 325 |
+
normalized = {}
|
| 326 |
+
for name, val in items:
|
| 327 |
+
key = section + "." + _normalize_name(name)
|
| 328 |
+
normalized[key] = val
|
| 329 |
+
return normalized
|
| 330 |
+
|
| 331 |
+
def get_environ_vars(self) -> Iterable[tuple[str, str]]:
|
| 332 |
+
"""Returns a generator with all environmental vars with prefix PIP_"""
|
| 333 |
+
for key, val in os.environ.items():
|
| 334 |
+
if key.startswith("PIP_"):
|
| 335 |
+
name = key[4:].lower()
|
| 336 |
+
if name not in ENV_NAMES_IGNORED:
|
| 337 |
+
yield name, val
|
| 338 |
+
|
| 339 |
+
# XXX: This is patched in the tests.
|
| 340 |
+
def iter_config_files(self) -> Iterable[tuple[Kind, list[str]]]:
|
| 341 |
+
"""Yields variant and configuration files associated with it.
|
| 342 |
+
|
| 343 |
+
This should be treated like items of a dictionary. The order
|
| 344 |
+
here doesn't affect what gets overridden. That is controlled
|
| 345 |
+
by OVERRIDE_ORDER. However this does control the order they are
|
| 346 |
+
displayed to the user. It's probably most ergonomic to display
|
| 347 |
+
things in the same order as OVERRIDE_ORDER
|
| 348 |
+
"""
|
| 349 |
+
# SMELL: Move the conditions out of this function
|
| 350 |
+
|
| 351 |
+
env_config_file = os.environ.get("PIP_CONFIG_FILE", None)
|
| 352 |
+
config_files = get_configuration_files()
|
| 353 |
+
|
| 354 |
+
yield kinds.GLOBAL, config_files[kinds.GLOBAL]
|
| 355 |
+
|
| 356 |
+
# per-user config is not loaded when env_config_file exists
|
| 357 |
+
should_load_user_config = not self.isolated and not (
|
| 358 |
+
env_config_file and os.path.exists(env_config_file)
|
| 359 |
+
)
|
| 360 |
+
if should_load_user_config:
|
| 361 |
+
# The legacy config file is overridden by the new config file
|
| 362 |
+
yield kinds.USER, config_files[kinds.USER]
|
| 363 |
+
|
| 364 |
+
# virtualenv config
|
| 365 |
+
yield kinds.SITE, config_files[kinds.SITE]
|
| 366 |
+
|
| 367 |
+
if env_config_file is not None:
|
| 368 |
+
yield kinds.ENV, [env_config_file]
|
| 369 |
+
else:
|
| 370 |
+
yield kinds.ENV, []
|
| 371 |
+
|
| 372 |
+
def get_values_in_config(self, variant: Kind) -> dict[str, Any]:
|
| 373 |
+
"""Get values present in a config file"""
|
| 374 |
+
return self._config[variant]
|
| 375 |
+
|
| 376 |
+
def _get_parser_to_modify(self) -> tuple[str, RawConfigParser]:
|
| 377 |
+
# Determine which parser to modify
|
| 378 |
+
assert self.load_only
|
| 379 |
+
parsers = self._parsers[self.load_only]
|
| 380 |
+
if not parsers:
|
| 381 |
+
# This should not happen if everything works correctly.
|
| 382 |
+
raise ConfigurationError(
|
| 383 |
+
"Fatal Internal error [id=2]. Please report as a bug."
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
# Use the highest priority parser.
|
| 387 |
+
return parsers[-1]
|
| 388 |
+
|
| 389 |
+
# XXX: This is patched in the tests.
|
| 390 |
+
def _mark_as_modified(self, fname: str, parser: RawConfigParser) -> None:
|
| 391 |
+
file_parser_tuple = (fname, parser)
|
| 392 |
+
if file_parser_tuple not in self._modified_parsers:
|
| 393 |
+
self._modified_parsers.append(file_parser_tuple)
|
| 394 |
+
|
| 395 |
+
def __repr__(self) -> str:
|
| 396 |
+
return f"{self.__class__.__name__}({self._dictionary!r})"
|
.venv/lib/python3.12/site-packages/pip/_internal/distributions/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pip._internal.distributions.base import AbstractDistribution
|
| 2 |
+
from pip._internal.distributions.sdist import SourceDistribution
|
| 3 |
+
from pip._internal.distributions.wheel import WheelDistribution
|
| 4 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def make_distribution_for_install_requirement(
|
| 8 |
+
install_req: InstallRequirement,
|
| 9 |
+
) -> AbstractDistribution:
|
| 10 |
+
"""Returns a Distribution for the given InstallRequirement"""
|
| 11 |
+
# Editable requirements will always be source distributions. They use the
|
| 12 |
+
# legacy logic until we create a modern standard for them.
|
| 13 |
+
if install_req.editable:
|
| 14 |
+
return SourceDistribution(install_req)
|
| 15 |
+
|
| 16 |
+
# If it's a wheel, it's a WheelDistribution
|
| 17 |
+
if install_req.is_wheel:
|
| 18 |
+
return WheelDistribution(install_req)
|
| 19 |
+
|
| 20 |
+
# Otherwise, a SourceDistribution
|
| 21 |
+
return SourceDistribution(install_req)
|
.venv/lib/python3.12/site-packages/pip/_internal/distributions/base.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import abc
|
| 4 |
+
from typing import TYPE_CHECKING
|
| 5 |
+
|
| 6 |
+
from pip._internal.metadata.base import BaseDistribution
|
| 7 |
+
from pip._internal.req import InstallRequirement
|
| 8 |
+
|
| 9 |
+
if TYPE_CHECKING:
|
| 10 |
+
from pip._internal.build_env import BuildEnvironmentInstaller
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class AbstractDistribution(metaclass=abc.ABCMeta):
|
| 14 |
+
"""A base class for handling installable artifacts.
|
| 15 |
+
|
| 16 |
+
The requirements for anything installable are as follows:
|
| 17 |
+
|
| 18 |
+
- we must be able to determine the requirement name
|
| 19 |
+
(or we can't correctly handle the non-upgrade case).
|
| 20 |
+
|
| 21 |
+
- for packages with setup requirements, we must also be able
|
| 22 |
+
to determine their requirements without installing additional
|
| 23 |
+
packages (for the same reason as run-time dependencies)
|
| 24 |
+
|
| 25 |
+
- we must be able to create a Distribution object exposing the
|
| 26 |
+
above metadata.
|
| 27 |
+
|
| 28 |
+
- if we need to do work in the build tracker, we must be able to generate a unique
|
| 29 |
+
string to identify the requirement in the build tracker.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def __init__(self, req: InstallRequirement) -> None:
|
| 33 |
+
super().__init__()
|
| 34 |
+
self.req = req
|
| 35 |
+
|
| 36 |
+
@abc.abstractproperty
|
| 37 |
+
def build_tracker_id(self) -> str | None:
|
| 38 |
+
"""A string that uniquely identifies this requirement to the build tracker.
|
| 39 |
+
|
| 40 |
+
If None, then this dist has no work to do in the build tracker, and
|
| 41 |
+
``.prepare_distribution_metadata()`` will not be called."""
|
| 42 |
+
raise NotImplementedError()
|
| 43 |
+
|
| 44 |
+
@abc.abstractmethod
|
| 45 |
+
def get_metadata_distribution(self) -> BaseDistribution:
|
| 46 |
+
raise NotImplementedError()
|
| 47 |
+
|
| 48 |
+
@abc.abstractmethod
|
| 49 |
+
def prepare_distribution_metadata(
|
| 50 |
+
self,
|
| 51 |
+
build_env_installer: BuildEnvironmentInstaller,
|
| 52 |
+
build_isolation: bool,
|
| 53 |
+
check_build_deps: bool,
|
| 54 |
+
) -> None:
|
| 55 |
+
raise NotImplementedError()
|
.venv/lib/python3.12/site-packages/pip/_internal/distributions/installed.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING
|
| 4 |
+
|
| 5 |
+
from pip._internal.distributions.base import AbstractDistribution
|
| 6 |
+
from pip._internal.metadata import BaseDistribution
|
| 7 |
+
|
| 8 |
+
if TYPE_CHECKING:
|
| 9 |
+
from pip._internal.build_env import BuildEnvironmentInstaller
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class InstalledDistribution(AbstractDistribution):
|
| 13 |
+
"""Represents an installed package.
|
| 14 |
+
|
| 15 |
+
This does not need any preparation as the required information has already
|
| 16 |
+
been computed.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
@property
|
| 20 |
+
def build_tracker_id(self) -> str | None:
|
| 21 |
+
return None
|
| 22 |
+
|
| 23 |
+
def get_metadata_distribution(self) -> BaseDistribution:
|
| 24 |
+
assert self.req.satisfied_by is not None, "not actually installed"
|
| 25 |
+
return self.req.satisfied_by
|
| 26 |
+
|
| 27 |
+
def prepare_distribution_metadata(
|
| 28 |
+
self,
|
| 29 |
+
build_env_installer: BuildEnvironmentInstaller,
|
| 30 |
+
build_isolation: bool,
|
| 31 |
+
check_build_deps: bool,
|
| 32 |
+
) -> None:
|
| 33 |
+
pass
|
.venv/lib/python3.12/site-packages/pip/_internal/distributions/sdist.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
from collections.abc import Iterable
|
| 5 |
+
from typing import TYPE_CHECKING
|
| 6 |
+
|
| 7 |
+
from pip._internal.build_env import BuildEnvironment
|
| 8 |
+
from pip._internal.distributions.base import AbstractDistribution
|
| 9 |
+
from pip._internal.exceptions import InstallationError
|
| 10 |
+
from pip._internal.metadata import BaseDistribution
|
| 11 |
+
from pip._internal.utils.subprocess import runner_with_spinner_message
|
| 12 |
+
|
| 13 |
+
if TYPE_CHECKING:
|
| 14 |
+
from pip._internal.build_env import BuildEnvironmentInstaller
|
| 15 |
+
|
| 16 |
+
logger = logging.getLogger(__name__)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class SourceDistribution(AbstractDistribution):
|
| 20 |
+
"""Represents a source distribution.
|
| 21 |
+
|
| 22 |
+
The preparation step for these needs metadata for the packages to be
|
| 23 |
+
generated.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
@property
|
| 27 |
+
def build_tracker_id(self) -> str | None:
|
| 28 |
+
"""Identify this requirement uniquely by its link."""
|
| 29 |
+
assert self.req.link
|
| 30 |
+
return self.req.link.url_without_fragment
|
| 31 |
+
|
| 32 |
+
def get_metadata_distribution(self) -> BaseDistribution:
|
| 33 |
+
return self.req.get_dist()
|
| 34 |
+
|
| 35 |
+
def prepare_distribution_metadata(
|
| 36 |
+
self,
|
| 37 |
+
build_env_installer: BuildEnvironmentInstaller,
|
| 38 |
+
build_isolation: bool,
|
| 39 |
+
check_build_deps: bool,
|
| 40 |
+
) -> None:
|
| 41 |
+
# Load pyproject.toml
|
| 42 |
+
self.req.load_pyproject_toml()
|
| 43 |
+
|
| 44 |
+
# Set up the build isolation, if this requirement should be isolated
|
| 45 |
+
if build_isolation:
|
| 46 |
+
# Setup an isolated environment and install the build backend static
|
| 47 |
+
# requirements in it.
|
| 48 |
+
self._prepare_build_backend(build_env_installer)
|
| 49 |
+
# Check that the build backend supports PEP 660. This cannot be done
|
| 50 |
+
# earlier because we need to setup the build backend to verify it
|
| 51 |
+
# supports build_editable, nor can it be done later, because we want
|
| 52 |
+
# to avoid installing build requirements needlessly.
|
| 53 |
+
self.req.editable_sanity_check()
|
| 54 |
+
# Install the dynamic build requirements.
|
| 55 |
+
self._install_build_reqs(build_env_installer)
|
| 56 |
+
else:
|
| 57 |
+
# When not using build isolation, we still need to check that
|
| 58 |
+
# the build backend supports PEP 660.
|
| 59 |
+
self.req.editable_sanity_check()
|
| 60 |
+
# Check if the current environment provides build dependencies
|
| 61 |
+
if check_build_deps:
|
| 62 |
+
pyproject_requires = self.req.pyproject_requires
|
| 63 |
+
assert pyproject_requires is not None
|
| 64 |
+
conflicting, missing = self.req.build_env.check_requirements(
|
| 65 |
+
pyproject_requires
|
| 66 |
+
)
|
| 67 |
+
if conflicting:
|
| 68 |
+
self._raise_conflicts("the backend dependencies", conflicting)
|
| 69 |
+
if missing:
|
| 70 |
+
self._raise_missing_reqs(missing)
|
| 71 |
+
self.req.prepare_metadata()
|
| 72 |
+
|
| 73 |
+
def _prepare_build_backend(
|
| 74 |
+
self, build_env_installer: BuildEnvironmentInstaller
|
| 75 |
+
) -> None:
|
| 76 |
+
# Isolate in a BuildEnvironment and install the build-time
|
| 77 |
+
# requirements.
|
| 78 |
+
pyproject_requires = self.req.pyproject_requires
|
| 79 |
+
assert pyproject_requires is not None
|
| 80 |
+
|
| 81 |
+
self.req.build_env = BuildEnvironment(build_env_installer)
|
| 82 |
+
self.req.build_env.install_requirements(
|
| 83 |
+
pyproject_requires, "overlay", kind="build dependencies", for_req=self.req
|
| 84 |
+
)
|
| 85 |
+
conflicting, missing = self.req.build_env.check_requirements(
|
| 86 |
+
self.req.requirements_to_check
|
| 87 |
+
)
|
| 88 |
+
if conflicting:
|
| 89 |
+
self._raise_conflicts("PEP 517/518 supported requirements", conflicting)
|
| 90 |
+
if missing:
|
| 91 |
+
logger.warning(
|
| 92 |
+
"Missing build requirements in pyproject.toml for %s.",
|
| 93 |
+
self.req,
|
| 94 |
+
)
|
| 95 |
+
logger.warning(
|
| 96 |
+
"The project does not specify a build backend, and "
|
| 97 |
+
"pip cannot fall back to setuptools without %s.",
|
| 98 |
+
" and ".join(map(repr, sorted(missing))),
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
def _get_build_requires_wheel(self) -> Iterable[str]:
|
| 102 |
+
with self.req.build_env:
|
| 103 |
+
runner = runner_with_spinner_message("Getting requirements to build wheel")
|
| 104 |
+
backend = self.req.pep517_backend
|
| 105 |
+
assert backend is not None
|
| 106 |
+
with backend.subprocess_runner(runner):
|
| 107 |
+
return backend.get_requires_for_build_wheel()
|
| 108 |
+
|
| 109 |
+
def _get_build_requires_editable(self) -> Iterable[str]:
|
| 110 |
+
with self.req.build_env:
|
| 111 |
+
runner = runner_with_spinner_message(
|
| 112 |
+
"Getting requirements to build editable"
|
| 113 |
+
)
|
| 114 |
+
backend = self.req.pep517_backend
|
| 115 |
+
assert backend is not None
|
| 116 |
+
with backend.subprocess_runner(runner):
|
| 117 |
+
return backend.get_requires_for_build_editable()
|
| 118 |
+
|
| 119 |
+
def _install_build_reqs(
|
| 120 |
+
self, build_env_installer: BuildEnvironmentInstaller
|
| 121 |
+
) -> None:
|
| 122 |
+
# Install any extra build dependencies that the backend requests.
|
| 123 |
+
# This must be done in a second pass, as the pyproject.toml
|
| 124 |
+
# dependencies must be installed before we can call the backend.
|
| 125 |
+
if (
|
| 126 |
+
self.req.editable
|
| 127 |
+
and self.req.permit_editable_wheels
|
| 128 |
+
and self.req.supports_pyproject_editable
|
| 129 |
+
):
|
| 130 |
+
build_reqs = self._get_build_requires_editable()
|
| 131 |
+
else:
|
| 132 |
+
build_reqs = self._get_build_requires_wheel()
|
| 133 |
+
conflicting, missing = self.req.build_env.check_requirements(build_reqs)
|
| 134 |
+
if conflicting:
|
| 135 |
+
self._raise_conflicts("the backend dependencies", conflicting)
|
| 136 |
+
self.req.build_env.install_requirements(
|
| 137 |
+
missing, "normal", kind="backend dependencies", for_req=self.req
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
def _raise_conflicts(
|
| 141 |
+
self, conflicting_with: str, conflicting_reqs: set[tuple[str, str]]
|
| 142 |
+
) -> None:
|
| 143 |
+
format_string = (
|
| 144 |
+
"Some build dependencies for {requirement} "
|
| 145 |
+
"conflict with {conflicting_with}: {description}."
|
| 146 |
+
)
|
| 147 |
+
error_message = format_string.format(
|
| 148 |
+
requirement=self.req,
|
| 149 |
+
conflicting_with=conflicting_with,
|
| 150 |
+
description=", ".join(
|
| 151 |
+
f"{installed} is incompatible with {wanted}"
|
| 152 |
+
for installed, wanted in sorted(conflicting_reqs)
|
| 153 |
+
),
|
| 154 |
+
)
|
| 155 |
+
raise InstallationError(error_message)
|
| 156 |
+
|
| 157 |
+
def _raise_missing_reqs(self, missing: set[str]) -> None:
|
| 158 |
+
format_string = (
|
| 159 |
+
"Some build dependencies for {requirement} are missing: {missing}."
|
| 160 |
+
)
|
| 161 |
+
error_message = format_string.format(
|
| 162 |
+
requirement=self.req, missing=", ".join(map(repr, sorted(missing)))
|
| 163 |
+
)
|
| 164 |
+
raise InstallationError(error_message)
|
.venv/lib/python3.12/site-packages/pip/_internal/distributions/wheel.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING
|
| 4 |
+
|
| 5 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 6 |
+
|
| 7 |
+
from pip._internal.distributions.base import AbstractDistribution
|
| 8 |
+
from pip._internal.metadata import (
|
| 9 |
+
BaseDistribution,
|
| 10 |
+
FilesystemWheel,
|
| 11 |
+
get_wheel_distribution,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from pip._internal.build_env import BuildEnvironmentInstaller
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class WheelDistribution(AbstractDistribution):
|
| 19 |
+
"""Represents a wheel distribution.
|
| 20 |
+
|
| 21 |
+
This does not need any preparation as wheels can be directly unpacked.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
@property
|
| 25 |
+
def build_tracker_id(self) -> str | None:
|
| 26 |
+
return None
|
| 27 |
+
|
| 28 |
+
def get_metadata_distribution(self) -> BaseDistribution:
|
| 29 |
+
"""Loads the metadata from the wheel file into memory and returns a
|
| 30 |
+
Distribution that uses it, not relying on the wheel file or
|
| 31 |
+
requirement.
|
| 32 |
+
"""
|
| 33 |
+
assert self.req.local_file_path, "Set as part of preparation during download"
|
| 34 |
+
assert self.req.name, "Wheels are never unnamed"
|
| 35 |
+
wheel = FilesystemWheel(self.req.local_file_path)
|
| 36 |
+
return get_wheel_distribution(wheel, canonicalize_name(self.req.name))
|
| 37 |
+
|
| 38 |
+
def prepare_distribution_metadata(
|
| 39 |
+
self,
|
| 40 |
+
build_env_installer: BuildEnvironmentInstaller,
|
| 41 |
+
build_isolation: bool,
|
| 42 |
+
check_build_deps: bool,
|
| 43 |
+
) -> None:
|
| 44 |
+
pass
|
.venv/lib/python3.12/site-packages/pip/_internal/ex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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Exceptions used throughout package.
|
| 2 |
+
|
| 3 |
+
This module MUST NOT try to import from anything within `pip._internal` to
|
| 4 |
+
operate. This is expected to be importable from any/all files within the
|
| 5 |
+
subpackage and, thus, should not depend on them.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import configparser
|
| 11 |
+
import contextlib
|
| 12 |
+
import locale
|
| 13 |
+
import logging
|
| 14 |
+
import pathlib
|
| 15 |
+
import re
|
| 16 |
+
import sys
|
| 17 |
+
import traceback
|
| 18 |
+
from collections.abc import Iterable, Iterator
|
| 19 |
+
from itertools import chain, groupby, repeat
|
| 20 |
+
from typing import TYPE_CHECKING, Literal
|
| 21 |
+
|
| 22 |
+
from pip._vendor.packaging.requirements import InvalidRequirement
|
| 23 |
+
from pip._vendor.packaging.version import InvalidVersion
|
| 24 |
+
from pip._vendor.rich.console import Console, ConsoleOptions, RenderResult
|
| 25 |
+
from pip._vendor.rich.markup import escape
|
| 26 |
+
from pip._vendor.rich.text import Text
|
| 27 |
+
|
| 28 |
+
if TYPE_CHECKING:
|
| 29 |
+
from hashlib import _Hash
|
| 30 |
+
|
| 31 |
+
from pip._vendor.requests.models import PreparedRequest, Request, Response
|
| 32 |
+
|
| 33 |
+
from pip._internal.metadata import BaseDistribution
|
| 34 |
+
from pip._internal.models.link import Link
|
| 35 |
+
from pip._internal.network.download import _FileDownload
|
| 36 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 37 |
+
|
| 38 |
+
logger = logging.getLogger(__name__)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
#
|
| 42 |
+
# Scaffolding
|
| 43 |
+
#
|
| 44 |
+
def _is_kebab_case(s: str) -> bool:
|
| 45 |
+
return re.match(r"^[a-z]+(-[a-z]+)*$", s) is not None
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _prefix_with_indent(
|
| 49 |
+
s: Text | str,
|
| 50 |
+
console: Console,
|
| 51 |
+
*,
|
| 52 |
+
prefix: str,
|
| 53 |
+
indent: str,
|
| 54 |
+
) -> Text:
|
| 55 |
+
if isinstance(s, Text):
|
| 56 |
+
text = s
|
| 57 |
+
else:
|
| 58 |
+
text = console.render_str(s)
|
| 59 |
+
|
| 60 |
+
return console.render_str(prefix, overflow="ignore") + console.render_str(
|
| 61 |
+
f"\n{indent}", overflow="ignore"
|
| 62 |
+
).join(text.split(allow_blank=True))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class PipError(Exception):
|
| 66 |
+
"""The base pip error."""
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class DiagnosticPipError(PipError):
|
| 70 |
+
"""An error, that presents diagnostic information to the user.
|
| 71 |
+
|
| 72 |
+
This contains a bunch of logic, to enable pretty presentation of our error
|
| 73 |
+
messages. Each error gets a unique reference. Each error can also include
|
| 74 |
+
additional context, a hint and/or a note -- which are presented with the
|
| 75 |
+
main error message in a consistent style.
|
| 76 |
+
|
| 77 |
+
This is adapted from the error output styling in `sphinx-theme-builder`.
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
reference: str
|
| 81 |
+
|
| 82 |
+
def __init__(
|
| 83 |
+
self,
|
| 84 |
+
*,
|
| 85 |
+
kind: Literal["error", "warning"] = "error",
|
| 86 |
+
reference: str | None = None,
|
| 87 |
+
message: str | Text,
|
| 88 |
+
context: str | Text | None,
|
| 89 |
+
hint_stmt: str | Text | None,
|
| 90 |
+
note_stmt: str | Text | None = None,
|
| 91 |
+
link: str | None = None,
|
| 92 |
+
) -> None:
|
| 93 |
+
# Ensure a proper reference is provided.
|
| 94 |
+
if reference is None:
|
| 95 |
+
assert hasattr(self, "reference"), "error reference not provided!"
|
| 96 |
+
reference = self.reference
|
| 97 |
+
assert _is_kebab_case(reference), "error reference must be kebab-case!"
|
| 98 |
+
|
| 99 |
+
self.kind = kind
|
| 100 |
+
self.reference = reference
|
| 101 |
+
|
| 102 |
+
self.message = message
|
| 103 |
+
self.context = context
|
| 104 |
+
|
| 105 |
+
self.note_stmt = note_stmt
|
| 106 |
+
self.hint_stmt = hint_stmt
|
| 107 |
+
|
| 108 |
+
self.link = link
|
| 109 |
+
|
| 110 |
+
super().__init__(f"<{self.__class__.__name__}: {self.reference}>")
|
| 111 |
+
|
| 112 |
+
def __repr__(self) -> str:
|
| 113 |
+
return (
|
| 114 |
+
f"<{self.__class__.__name__}("
|
| 115 |
+
f"reference={self.reference!r}, "
|
| 116 |
+
f"message={self.message!r}, "
|
| 117 |
+
f"context={self.context!r}, "
|
| 118 |
+
f"note_stmt={self.note_stmt!r}, "
|
| 119 |
+
f"hint_stmt={self.hint_stmt!r}"
|
| 120 |
+
")>"
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
def __rich_console__(
|
| 124 |
+
self,
|
| 125 |
+
console: Console,
|
| 126 |
+
options: ConsoleOptions,
|
| 127 |
+
) -> RenderResult:
|
| 128 |
+
colour = "red" if self.kind == "error" else "yellow"
|
| 129 |
+
|
| 130 |
+
yield f"[{colour} bold]{self.kind}[/]: [bold]{self.reference}[/]"
|
| 131 |
+
yield ""
|
| 132 |
+
|
| 133 |
+
if not options.ascii_only:
|
| 134 |
+
# Present the main message, with relevant context indented.
|
| 135 |
+
if self.context is not None:
|
| 136 |
+
yield _prefix_with_indent(
|
| 137 |
+
self.message,
|
| 138 |
+
console,
|
| 139 |
+
prefix=f"[{colour}]×[/] ",
|
| 140 |
+
indent=f"[{colour}]│[/] ",
|
| 141 |
+
)
|
| 142 |
+
yield _prefix_with_indent(
|
| 143 |
+
self.context,
|
| 144 |
+
console,
|
| 145 |
+
prefix=f"[{colour}]╰─>[/] ",
|
| 146 |
+
indent=f"[{colour}] [/] ",
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
yield _prefix_with_indent(
|
| 150 |
+
self.message,
|
| 151 |
+
console,
|
| 152 |
+
prefix="[red]×[/] ",
|
| 153 |
+
indent=" ",
|
| 154 |
+
)
|
| 155 |
+
else:
|
| 156 |
+
yield self.message
|
| 157 |
+
if self.context is not None:
|
| 158 |
+
yield ""
|
| 159 |
+
yield self.context
|
| 160 |
+
|
| 161 |
+
if self.note_stmt is not None or self.hint_stmt is not None:
|
| 162 |
+
yield ""
|
| 163 |
+
|
| 164 |
+
if self.note_stmt is not None:
|
| 165 |
+
yield _prefix_with_indent(
|
| 166 |
+
self.note_stmt,
|
| 167 |
+
console,
|
| 168 |
+
prefix="[magenta bold]note[/]: ",
|
| 169 |
+
indent=" ",
|
| 170 |
+
)
|
| 171 |
+
if self.hint_stmt is not None:
|
| 172 |
+
yield _prefix_with_indent(
|
| 173 |
+
self.hint_stmt,
|
| 174 |
+
console,
|
| 175 |
+
prefix="[cyan bold]hint[/]: ",
|
| 176 |
+
indent=" ",
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
if self.link is not None:
|
| 180 |
+
yield ""
|
| 181 |
+
yield f"Link: {self.link}"
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
#
|
| 185 |
+
# Actual Errors
|
| 186 |
+
#
|
| 187 |
+
class ConfigurationError(PipError):
|
| 188 |
+
"""General exception in configuration"""
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
class InstallationError(PipError):
|
| 192 |
+
"""General exception during installation"""
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
class FailedToPrepareCandidate(InstallationError):
|
| 196 |
+
"""Raised when we fail to prepare a candidate (i.e. fetch and generate metadata).
|
| 197 |
+
|
| 198 |
+
This is intentionally not a diagnostic error, since the output will be presented
|
| 199 |
+
above this error, when this occurs. This should instead present information to the
|
| 200 |
+
user.
|
| 201 |
+
"""
|
| 202 |
+
|
| 203 |
+
def __init__(
|
| 204 |
+
self, *, package_name: str, requirement_chain: str, failed_step: str
|
| 205 |
+
) -> None:
|
| 206 |
+
super().__init__(f"Failed to build '{package_name}' when {failed_step.lower()}")
|
| 207 |
+
self.package_name = package_name
|
| 208 |
+
self.requirement_chain = requirement_chain
|
| 209 |
+
self.failed_step = failed_step
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class MissingPyProjectBuildRequires(DiagnosticPipError):
|
| 213 |
+
"""Raised when pyproject.toml has `build-system`, but no `build-system.requires`."""
|
| 214 |
+
|
| 215 |
+
reference = "missing-pyproject-build-system-requires"
|
| 216 |
+
|
| 217 |
+
def __init__(self, *, package: str) -> None:
|
| 218 |
+
super().__init__(
|
| 219 |
+
message=f"Can not process {escape(package)}",
|
| 220 |
+
context=Text(
|
| 221 |
+
"This package has an invalid pyproject.toml file.\n"
|
| 222 |
+
"The [build-system] table is missing the mandatory `requires` key."
|
| 223 |
+
),
|
| 224 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
| 225 |
+
hint_stmt=Text("See PEP 518 for the detailed specification."),
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
class InvalidPyProjectBuildRequires(DiagnosticPipError):
|
| 230 |
+
"""Raised when pyproject.toml an invalid `build-system.requires`."""
|
| 231 |
+
|
| 232 |
+
reference = "invalid-pyproject-build-system-requires"
|
| 233 |
+
|
| 234 |
+
def __init__(self, *, package: str, reason: str) -> None:
|
| 235 |
+
super().__init__(
|
| 236 |
+
message=f"Can not process {escape(package)}",
|
| 237 |
+
context=Text(
|
| 238 |
+
"This package has an invalid `build-system.requires` key in "
|
| 239 |
+
f"pyproject.toml.\n{reason}"
|
| 240 |
+
),
|
| 241 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
| 242 |
+
hint_stmt=Text("See PEP 518 for the detailed specification."),
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
class NoneMetadataError(PipError):
|
| 247 |
+
"""Raised when accessing a Distribution's "METADATA" or "PKG-INFO".
|
| 248 |
+
|
| 249 |
+
This signifies an inconsistency, when the Distribution claims to have
|
| 250 |
+
the metadata file (if not, raise ``FileNotFoundError`` instead), but is
|
| 251 |
+
not actually able to produce its content. This may be due to permission
|
| 252 |
+
errors.
|
| 253 |
+
"""
|
| 254 |
+
|
| 255 |
+
def __init__(
|
| 256 |
+
self,
|
| 257 |
+
dist: BaseDistribution,
|
| 258 |
+
metadata_name: str,
|
| 259 |
+
) -> None:
|
| 260 |
+
"""
|
| 261 |
+
:param dist: A Distribution object.
|
| 262 |
+
:param metadata_name: The name of the metadata being accessed
|
| 263 |
+
(can be "METADATA" or "PKG-INFO").
|
| 264 |
+
"""
|
| 265 |
+
self.dist = dist
|
| 266 |
+
self.metadata_name = metadata_name
|
| 267 |
+
|
| 268 |
+
def __str__(self) -> str:
|
| 269 |
+
# Use `dist` in the error message because its stringification
|
| 270 |
+
# includes more information, like the version and location.
|
| 271 |
+
return f"None {self.metadata_name} metadata found for distribution: {self.dist}"
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
class UserInstallationInvalid(InstallationError):
|
| 275 |
+
"""A --user install is requested on an environment without user site."""
|
| 276 |
+
|
| 277 |
+
def __str__(self) -> str:
|
| 278 |
+
return "User base directory is not specified"
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
class InvalidSchemeCombination(InstallationError):
|
| 282 |
+
def __str__(self) -> str:
|
| 283 |
+
before = ", ".join(str(a) for a in self.args[:-1])
|
| 284 |
+
return f"Cannot set {before} and {self.args[-1]} together"
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
class DistributionNotFound(InstallationError):
|
| 288 |
+
"""Raised when a distribution cannot be found to satisfy a requirement"""
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
class RequirementsFileParseError(InstallationError):
|
| 292 |
+
"""Raised when a general error occurs parsing a requirements file line."""
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
class BestVersionAlreadyInstalled(PipError):
|
| 296 |
+
"""Raised when the most up-to-date version of a package is already
|
| 297 |
+
installed."""
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
class BadCommand(PipError):
|
| 301 |
+
"""Raised when virtualenv or a command is not found"""
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
class CommandError(PipError):
|
| 305 |
+
"""Raised when there is an error in command-line arguments"""
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
class PreviousBuildDirError(PipError):
|
| 309 |
+
"""Raised when there's a previous conflicting build directory"""
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
class NetworkConnectionError(PipError):
|
| 313 |
+
"""HTTP connection error"""
|
| 314 |
+
|
| 315 |
+
def __init__(
|
| 316 |
+
self,
|
| 317 |
+
error_msg: str,
|
| 318 |
+
response: Response | None = None,
|
| 319 |
+
request: Request | PreparedRequest | None = None,
|
| 320 |
+
) -> None:
|
| 321 |
+
"""
|
| 322 |
+
Initialize NetworkConnectionError with `request` and `response`
|
| 323 |
+
objects.
|
| 324 |
+
"""
|
| 325 |
+
self.response = response
|
| 326 |
+
self.request = request
|
| 327 |
+
self.error_msg = error_msg
|
| 328 |
+
if (
|
| 329 |
+
self.response is not None
|
| 330 |
+
and not self.request
|
| 331 |
+
and hasattr(response, "request")
|
| 332 |
+
):
|
| 333 |
+
self.request = self.response.request
|
| 334 |
+
super().__init__(error_msg, response, request)
|
| 335 |
+
|
| 336 |
+
def __str__(self) -> str:
|
| 337 |
+
return str(self.error_msg)
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
class InvalidWheelFilename(InstallationError):
|
| 341 |
+
"""Invalid wheel filename."""
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
class UnsupportedWheel(InstallationError):
|
| 345 |
+
"""Unsupported wheel."""
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
class InvalidWheel(InstallationError):
|
| 349 |
+
"""Invalid (e.g. corrupt) wheel."""
|
| 350 |
+
|
| 351 |
+
def __init__(self, location: str, name: str):
|
| 352 |
+
self.location = location
|
| 353 |
+
self.name = name
|
| 354 |
+
|
| 355 |
+
def __str__(self) -> str:
|
| 356 |
+
return f"Wheel '{self.name}' located at {self.location} is invalid."
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
class MetadataInconsistent(InstallationError):
|
| 360 |
+
"""Built metadata contains inconsistent information.
|
| 361 |
+
|
| 362 |
+
This is raised when the metadata contains values (e.g. name and version)
|
| 363 |
+
that do not match the information previously obtained from sdist filename,
|
| 364 |
+
user-supplied ``#egg=`` value, or an install requirement name.
|
| 365 |
+
"""
|
| 366 |
+
|
| 367 |
+
def __init__(
|
| 368 |
+
self, ireq: InstallRequirement, field: str, f_val: str, m_val: str
|
| 369 |
+
) -> None:
|
| 370 |
+
self.ireq = ireq
|
| 371 |
+
self.field = field
|
| 372 |
+
self.f_val = f_val
|
| 373 |
+
self.m_val = m_val
|
| 374 |
+
|
| 375 |
+
def __str__(self) -> str:
|
| 376 |
+
return (
|
| 377 |
+
f"Requested {self.ireq} has inconsistent {self.field}: "
|
| 378 |
+
f"expected {self.f_val!r}, but metadata has {self.m_val!r}"
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
class MetadataInvalid(InstallationError):
|
| 383 |
+
"""Metadata is invalid."""
|
| 384 |
+
|
| 385 |
+
def __init__(self, ireq: InstallRequirement, error: str) -> None:
|
| 386 |
+
self.ireq = ireq
|
| 387 |
+
self.error = error
|
| 388 |
+
|
| 389 |
+
def __str__(self) -> str:
|
| 390 |
+
return f"Requested {self.ireq} has invalid metadata: {self.error}"
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
class InstallationSubprocessError(DiagnosticPipError, InstallationError):
|
| 394 |
+
"""A subprocess call failed."""
|
| 395 |
+
|
| 396 |
+
reference = "subprocess-exited-with-error"
|
| 397 |
+
|
| 398 |
+
def __init__(
|
| 399 |
+
self,
|
| 400 |
+
*,
|
| 401 |
+
command_description: str,
|
| 402 |
+
exit_code: int,
|
| 403 |
+
output_lines: list[str] | None,
|
| 404 |
+
) -> None:
|
| 405 |
+
if output_lines is None:
|
| 406 |
+
output_prompt = Text("No available output.")
|
| 407 |
+
else:
|
| 408 |
+
output_prompt = (
|
| 409 |
+
Text.from_markup(f"[red][{len(output_lines)} lines of output][/]\n")
|
| 410 |
+
+ Text("".join(output_lines))
|
| 411 |
+
+ Text.from_markup(R"[red]\[end of output][/]")
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
super().__init__(
|
| 415 |
+
message=(
|
| 416 |
+
f"[green]{escape(command_description)}[/] did not run successfully.\n"
|
| 417 |
+
f"exit code: {exit_code}"
|
| 418 |
+
),
|
| 419 |
+
context=output_prompt,
|
| 420 |
+
hint_stmt=None,
|
| 421 |
+
note_stmt=(
|
| 422 |
+
"This error originates from a subprocess, and is likely not a "
|
| 423 |
+
"problem with pip."
|
| 424 |
+
),
|
| 425 |
+
)
|
| 426 |
+
|
| 427 |
+
self.command_description = command_description
|
| 428 |
+
self.exit_code = exit_code
|
| 429 |
+
|
| 430 |
+
def __str__(self) -> str:
|
| 431 |
+
return f"{self.command_description} exited with {self.exit_code}"
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
class MetadataGenerationFailed(DiagnosticPipError, InstallationError):
|
| 435 |
+
reference = "metadata-generation-failed"
|
| 436 |
+
|
| 437 |
+
def __init__(
|
| 438 |
+
self,
|
| 439 |
+
*,
|
| 440 |
+
package_details: str,
|
| 441 |
+
) -> None:
|
| 442 |
+
super().__init__(
|
| 443 |
+
message="Encountered error while generating package metadata.",
|
| 444 |
+
context=escape(package_details),
|
| 445 |
+
hint_stmt="See above for details.",
|
| 446 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
def __str__(self) -> str:
|
| 450 |
+
return "metadata generation failed"
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
class HashErrors(InstallationError):
|
| 454 |
+
"""Multiple HashError instances rolled into one for reporting"""
|
| 455 |
+
|
| 456 |
+
def __init__(self) -> None:
|
| 457 |
+
self.errors: list[HashError] = []
|
| 458 |
+
|
| 459 |
+
def append(self, error: HashError) -> None:
|
| 460 |
+
self.errors.append(error)
|
| 461 |
+
|
| 462 |
+
def __str__(self) -> str:
|
| 463 |
+
lines = []
|
| 464 |
+
self.errors.sort(key=lambda e: e.order)
|
| 465 |
+
for cls, errors_of_cls in groupby(self.errors, lambda e: e.__class__):
|
| 466 |
+
lines.append(cls.head)
|
| 467 |
+
lines.extend(e.body() for e in errors_of_cls)
|
| 468 |
+
if lines:
|
| 469 |
+
return "\n".join(lines)
|
| 470 |
+
return ""
|
| 471 |
+
|
| 472 |
+
def __bool__(self) -> bool:
|
| 473 |
+
return bool(self.errors)
|
| 474 |
+
|
| 475 |
+
|
| 476 |
+
class HashError(InstallationError):
|
| 477 |
+
"""
|
| 478 |
+
A failure to verify a package against known-good hashes
|
| 479 |
+
|
| 480 |
+
:cvar order: An int sorting hash exception classes by difficulty of
|
| 481 |
+
recovery (lower being harder), so the user doesn't bother fretting
|
| 482 |
+
about unpinned packages when he has deeper issues, like VCS
|
| 483 |
+
dependencies, to deal with. Also keeps error reports in a
|
| 484 |
+
deterministic order.
|
| 485 |
+
:cvar head: A section heading for display above potentially many
|
| 486 |
+
exceptions of this kind
|
| 487 |
+
:ivar req: The InstallRequirement that triggered this error. This is
|
| 488 |
+
pasted on after the exception is instantiated, because it's not
|
| 489 |
+
typically available earlier.
|
| 490 |
+
|
| 491 |
+
"""
|
| 492 |
+
|
| 493 |
+
req: InstallRequirement | None = None
|
| 494 |
+
head = ""
|
| 495 |
+
order: int = -1
|
| 496 |
+
|
| 497 |
+
def body(self) -> str:
|
| 498 |
+
"""Return a summary of me for display under the heading.
|
| 499 |
+
|
| 500 |
+
This default implementation simply prints a description of the
|
| 501 |
+
triggering requirement.
|
| 502 |
+
|
| 503 |
+
:param req: The InstallRequirement that provoked this error, with
|
| 504 |
+
its link already populated by the resolver's _populate_link().
|
| 505 |
+
|
| 506 |
+
"""
|
| 507 |
+
return f" {self._requirement_name()}"
|
| 508 |
+
|
| 509 |
+
def __str__(self) -> str:
|
| 510 |
+
return f"{self.head}\n{self.body()}"
|
| 511 |
+
|
| 512 |
+
def _requirement_name(self) -> str:
|
| 513 |
+
"""Return a description of the requirement that triggered me.
|
| 514 |
+
|
| 515 |
+
This default implementation returns long description of the req, with
|
| 516 |
+
line numbers
|
| 517 |
+
|
| 518 |
+
"""
|
| 519 |
+
return str(self.req) if self.req else "unknown package"
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
class VcsHashUnsupported(HashError):
|
| 523 |
+
"""A hash was provided for a version-control-system-based requirement, but
|
| 524 |
+
we don't have a method for hashing those."""
|
| 525 |
+
|
| 526 |
+
order = 0
|
| 527 |
+
head = (
|
| 528 |
+
"Can't verify hashes for these requirements because we don't "
|
| 529 |
+
"have a way to hash version control repositories:"
|
| 530 |
+
)
|
| 531 |
+
|
| 532 |
+
|
| 533 |
+
class DirectoryUrlHashUnsupported(HashError):
|
| 534 |
+
"""A hash was provided for a version-control-system-based requirement, but
|
| 535 |
+
we don't have a method for hashing those."""
|
| 536 |
+
|
| 537 |
+
order = 1
|
| 538 |
+
head = (
|
| 539 |
+
"Can't verify hashes for these file:// requirements because they "
|
| 540 |
+
"point to directories:"
|
| 541 |
+
)
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
class HashMissing(HashError):
|
| 545 |
+
"""A hash was needed for a requirement but is absent."""
|
| 546 |
+
|
| 547 |
+
order = 2
|
| 548 |
+
head = (
|
| 549 |
+
"Hashes are required in --require-hashes mode, but they are "
|
| 550 |
+
"missing from some requirements. Here is a list of those "
|
| 551 |
+
"requirements along with the hashes their downloaded archives "
|
| 552 |
+
"actually had. Add lines like these to your requirements files to "
|
| 553 |
+
"prevent tampering. (If you did not enable --require-hashes "
|
| 554 |
+
"manually, note that it turns on automatically when any package "
|
| 555 |
+
"has a hash.)"
|
| 556 |
+
)
|
| 557 |
+
|
| 558 |
+
def __init__(self, gotten_hash: str) -> None:
|
| 559 |
+
"""
|
| 560 |
+
:param gotten_hash: The hash of the (possibly malicious) archive we
|
| 561 |
+
just downloaded
|
| 562 |
+
"""
|
| 563 |
+
self.gotten_hash = gotten_hash
|
| 564 |
+
|
| 565 |
+
def body(self) -> str:
|
| 566 |
+
# Dodge circular import.
|
| 567 |
+
from pip._internal.utils.hashes import FAVORITE_HASH
|
| 568 |
+
|
| 569 |
+
package = None
|
| 570 |
+
if self.req:
|
| 571 |
+
# In the case of URL-based requirements, display the original URL
|
| 572 |
+
# seen in the requirements file rather than the package name,
|
| 573 |
+
# so the output can be directly copied into the requirements file.
|
| 574 |
+
package = (
|
| 575 |
+
self.req.original_link
|
| 576 |
+
if self.req.is_direct
|
| 577 |
+
# In case someone feeds something downright stupid
|
| 578 |
+
# to InstallRequirement's constructor.
|
| 579 |
+
else getattr(self.req, "req", None)
|
| 580 |
+
)
|
| 581 |
+
return " {} --hash={}:{}".format(
|
| 582 |
+
package or "unknown package", FAVORITE_HASH, self.gotten_hash
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
class HashUnpinned(HashError):
|
| 587 |
+
"""A requirement had a hash specified but was not pinned to a specific
|
| 588 |
+
version."""
|
| 589 |
+
|
| 590 |
+
order = 3
|
| 591 |
+
head = (
|
| 592 |
+
"In --require-hashes mode, all requirements must have their "
|
| 593 |
+
"versions pinned with ==. These do not:"
|
| 594 |
+
)
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
class HashMismatch(HashError):
|
| 598 |
+
"""
|
| 599 |
+
Distribution file hash values don't match.
|
| 600 |
+
|
| 601 |
+
:ivar package_name: The name of the package that triggered the hash
|
| 602 |
+
mismatch. Feel free to write to this after the exception is raise to
|
| 603 |
+
improve its error message.
|
| 604 |
+
|
| 605 |
+
"""
|
| 606 |
+
|
| 607 |
+
order = 4
|
| 608 |
+
head = (
|
| 609 |
+
"THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS "
|
| 610 |
+
"FILE. If you have updated the package versions, please update "
|
| 611 |
+
"the hashes. Otherwise, examine the package contents carefully; "
|
| 612 |
+
"someone may have tampered with them."
|
| 613 |
+
)
|
| 614 |
+
|
| 615 |
+
def __init__(self, allowed: dict[str, list[str]], gots: dict[str, _Hash]) -> None:
|
| 616 |
+
"""
|
| 617 |
+
:param allowed: A dict of algorithm names pointing to lists of allowed
|
| 618 |
+
hex digests
|
| 619 |
+
:param gots: A dict of algorithm names pointing to hashes we
|
| 620 |
+
actually got from the files under suspicion
|
| 621 |
+
"""
|
| 622 |
+
self.allowed = allowed
|
| 623 |
+
self.gots = gots
|
| 624 |
+
|
| 625 |
+
def body(self) -> str:
|
| 626 |
+
return f" {self._requirement_name()}:\n{self._hash_comparison()}"
|
| 627 |
+
|
| 628 |
+
def _hash_comparison(self) -> str:
|
| 629 |
+
"""
|
| 630 |
+
Return a comparison of actual and expected hash values.
|
| 631 |
+
|
| 632 |
+
Example::
|
| 633 |
+
|
| 634 |
+
Expected sha256 abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde
|
| 635 |
+
or 123451234512345123451234512345123451234512345
|
| 636 |
+
Got bcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdef
|
| 637 |
+
|
| 638 |
+
"""
|
| 639 |
+
|
| 640 |
+
def hash_then_or(hash_name: str) -> chain[str]:
|
| 641 |
+
# For now, all the decent hashes have 6-char names, so we can get
|
| 642 |
+
# away with hard-coding space literals.
|
| 643 |
+
return chain([hash_name], repeat(" or"))
|
| 644 |
+
|
| 645 |
+
lines: list[str] = []
|
| 646 |
+
for hash_name, expecteds in self.allowed.items():
|
| 647 |
+
prefix = hash_then_or(hash_name)
|
| 648 |
+
lines.extend((f" Expected {next(prefix)} {e}") for e in expecteds)
|
| 649 |
+
lines.append(
|
| 650 |
+
f" Got {self.gots[hash_name].hexdigest()}\n"
|
| 651 |
+
)
|
| 652 |
+
return "\n".join(lines)
|
| 653 |
+
|
| 654 |
+
|
| 655 |
+
class UnsupportedPythonVersion(InstallationError):
|
| 656 |
+
"""Unsupported python version according to Requires-Python package
|
| 657 |
+
metadata."""
|
| 658 |
+
|
| 659 |
+
|
| 660 |
+
class ConfigurationFileCouldNotBeLoaded(ConfigurationError):
|
| 661 |
+
"""When there are errors while loading a configuration file"""
|
| 662 |
+
|
| 663 |
+
def __init__(
|
| 664 |
+
self,
|
| 665 |
+
reason: str = "could not be loaded",
|
| 666 |
+
fname: str | None = None,
|
| 667 |
+
error: configparser.Error | None = None,
|
| 668 |
+
) -> None:
|
| 669 |
+
super().__init__(error)
|
| 670 |
+
self.reason = reason
|
| 671 |
+
self.fname = fname
|
| 672 |
+
self.error = error
|
| 673 |
+
|
| 674 |
+
def __str__(self) -> str:
|
| 675 |
+
if self.fname is not None:
|
| 676 |
+
message_part = f" in {self.fname}."
|
| 677 |
+
else:
|
| 678 |
+
assert self.error is not None
|
| 679 |
+
message_part = f".\n{self.error}\n"
|
| 680 |
+
return f"Configuration file {self.reason}{message_part}"
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
_DEFAULT_EXTERNALLY_MANAGED_ERROR = f"""\
|
| 684 |
+
The Python environment under {sys.prefix} is managed externally, and may not be
|
| 685 |
+
manipulated by the user. Please use specific tooling from the distributor of
|
| 686 |
+
the Python installation to interact with this environment instead.
|
| 687 |
+
"""
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
class ExternallyManagedEnvironment(DiagnosticPipError):
|
| 691 |
+
"""The current environment is externally managed.
|
| 692 |
+
|
| 693 |
+
This is raised when the current environment is externally managed, as
|
| 694 |
+
defined by `PEP 668`_. The ``EXTERNALLY-MANAGED`` configuration is checked
|
| 695 |
+
and displayed when the error is bubbled up to the user.
|
| 696 |
+
|
| 697 |
+
:param error: The error message read from ``EXTERNALLY-MANAGED``.
|
| 698 |
+
"""
|
| 699 |
+
|
| 700 |
+
reference = "externally-managed-environment"
|
| 701 |
+
|
| 702 |
+
def __init__(self, error: str | None) -> None:
|
| 703 |
+
if error is None:
|
| 704 |
+
context = Text(_DEFAULT_EXTERNALLY_MANAGED_ERROR)
|
| 705 |
+
else:
|
| 706 |
+
context = Text(error)
|
| 707 |
+
super().__init__(
|
| 708 |
+
message="This environment is externally managed",
|
| 709 |
+
context=context,
|
| 710 |
+
note_stmt=(
|
| 711 |
+
"If you believe this is a mistake, please contact your "
|
| 712 |
+
"Python installation or OS distribution provider. "
|
| 713 |
+
"You can override this, at the risk of breaking your Python "
|
| 714 |
+
"installation or OS, by passing --break-system-packages."
|
| 715 |
+
),
|
| 716 |
+
hint_stmt=Text("See PEP 668 for the detailed specification."),
|
| 717 |
+
)
|
| 718 |
+
|
| 719 |
+
@staticmethod
|
| 720 |
+
def _iter_externally_managed_error_keys() -> Iterator[str]:
|
| 721 |
+
# LC_MESSAGES is in POSIX, but not the C standard. The most common
|
| 722 |
+
# platform that does not implement this category is Windows, where
|
| 723 |
+
# using other categories for console message localization is equally
|
| 724 |
+
# unreliable, so we fall back to the locale-less vendor message. This
|
| 725 |
+
# can always be re-evaluated when a vendor proposes a new alternative.
|
| 726 |
+
try:
|
| 727 |
+
category = locale.LC_MESSAGES
|
| 728 |
+
except AttributeError:
|
| 729 |
+
lang: str | None = None
|
| 730 |
+
else:
|
| 731 |
+
lang, _ = locale.getlocale(category)
|
| 732 |
+
if lang is not None:
|
| 733 |
+
yield f"Error-{lang}"
|
| 734 |
+
for sep in ("-", "_"):
|
| 735 |
+
before, found, _ = lang.partition(sep)
|
| 736 |
+
if not found:
|
| 737 |
+
continue
|
| 738 |
+
yield f"Error-{before}"
|
| 739 |
+
yield "Error"
|
| 740 |
+
|
| 741 |
+
@classmethod
|
| 742 |
+
def from_config(
|
| 743 |
+
cls,
|
| 744 |
+
config: pathlib.Path | str,
|
| 745 |
+
) -> ExternallyManagedEnvironment:
|
| 746 |
+
parser = configparser.ConfigParser(interpolation=None)
|
| 747 |
+
try:
|
| 748 |
+
parser.read(config, encoding="utf-8")
|
| 749 |
+
section = parser["externally-managed"]
|
| 750 |
+
for key in cls._iter_externally_managed_error_keys():
|
| 751 |
+
with contextlib.suppress(KeyError):
|
| 752 |
+
return cls(section[key])
|
| 753 |
+
except KeyError:
|
| 754 |
+
pass
|
| 755 |
+
except (OSError, UnicodeDecodeError, configparser.ParsingError):
|
| 756 |
+
from pip._internal.utils._log import VERBOSE
|
| 757 |
+
|
| 758 |
+
exc_info = logger.isEnabledFor(VERBOSE)
|
| 759 |
+
logger.warning("Failed to read %s", config, exc_info=exc_info)
|
| 760 |
+
return cls(None)
|
| 761 |
+
|
| 762 |
+
|
| 763 |
+
class UninstallMissingRecord(DiagnosticPipError):
|
| 764 |
+
reference = "uninstall-no-record-file"
|
| 765 |
+
|
| 766 |
+
def __init__(self, *, distribution: BaseDistribution) -> None:
|
| 767 |
+
installer = distribution.installer
|
| 768 |
+
if not installer or installer == "pip":
|
| 769 |
+
dep = f"{distribution.raw_name}=={distribution.version}"
|
| 770 |
+
hint = Text.assemble(
|
| 771 |
+
"You might be able to recover from this via: ",
|
| 772 |
+
(f"pip install --force-reinstall --no-deps {dep}", "green"),
|
| 773 |
+
)
|
| 774 |
+
else:
|
| 775 |
+
hint = Text(
|
| 776 |
+
f"The package was installed by {installer}. "
|
| 777 |
+
"You should check if it can uninstall the package."
|
| 778 |
+
)
|
| 779 |
+
|
| 780 |
+
super().__init__(
|
| 781 |
+
message=Text(f"Cannot uninstall {distribution}"),
|
| 782 |
+
context=(
|
| 783 |
+
"The package's contents are unknown: "
|
| 784 |
+
f"no RECORD file was found for {distribution.raw_name}."
|
| 785 |
+
),
|
| 786 |
+
hint_stmt=hint,
|
| 787 |
+
)
|
| 788 |
+
|
| 789 |
+
|
| 790 |
+
class LegacyDistutilsInstall(DiagnosticPipError):
|
| 791 |
+
reference = "uninstall-distutils-installed-package"
|
| 792 |
+
|
| 793 |
+
def __init__(self, *, distribution: BaseDistribution) -> None:
|
| 794 |
+
super().__init__(
|
| 795 |
+
message=Text(f"Cannot uninstall {distribution}"),
|
| 796 |
+
context=(
|
| 797 |
+
"It is a distutils installed project and thus we cannot accurately "
|
| 798 |
+
"determine which files belong to it which would lead to only a partial "
|
| 799 |
+
"uninstall."
|
| 800 |
+
),
|
| 801 |
+
hint_stmt=None,
|
| 802 |
+
)
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
class InvalidInstalledPackage(DiagnosticPipError):
|
| 806 |
+
reference = "invalid-installed-package"
|
| 807 |
+
|
| 808 |
+
def __init__(
|
| 809 |
+
self,
|
| 810 |
+
*,
|
| 811 |
+
dist: BaseDistribution,
|
| 812 |
+
invalid_exc: InvalidRequirement | InvalidVersion,
|
| 813 |
+
) -> None:
|
| 814 |
+
installed_location = dist.installed_location
|
| 815 |
+
|
| 816 |
+
if isinstance(invalid_exc, InvalidRequirement):
|
| 817 |
+
invalid_type = "requirement"
|
| 818 |
+
else:
|
| 819 |
+
invalid_type = "version"
|
| 820 |
+
|
| 821 |
+
super().__init__(
|
| 822 |
+
message=Text(
|
| 823 |
+
f"Cannot process installed package {dist} "
|
| 824 |
+
+ (f"in {installed_location!r} " if installed_location else "")
|
| 825 |
+
+ f"because it has an invalid {invalid_type}:\n{invalid_exc.args[0]}"
|
| 826 |
+
),
|
| 827 |
+
context=(
|
| 828 |
+
"Starting with pip 24.1, packages with invalid "
|
| 829 |
+
f"{invalid_type}s can not be processed."
|
| 830 |
+
),
|
| 831 |
+
hint_stmt="To proceed this package must be uninstalled.",
|
| 832 |
+
)
|
| 833 |
+
|
| 834 |
+
|
| 835 |
+
class IncompleteDownloadError(DiagnosticPipError):
|
| 836 |
+
"""Raised when the downloader receives fewer bytes than advertised
|
| 837 |
+
in the Content-Length header."""
|
| 838 |
+
|
| 839 |
+
reference = "incomplete-download"
|
| 840 |
+
|
| 841 |
+
def __init__(self, download: _FileDownload) -> None:
|
| 842 |
+
# Dodge circular import.
|
| 843 |
+
from pip._internal.utils.misc import format_size
|
| 844 |
+
|
| 845 |
+
assert download.size is not None
|
| 846 |
+
download_status = (
|
| 847 |
+
f"{format_size(download.bytes_received)}/{format_size(download.size)}"
|
| 848 |
+
)
|
| 849 |
+
if download.reattempts:
|
| 850 |
+
retry_status = f"after {download.reattempts + 1} attempts "
|
| 851 |
+
hint = "Use --resume-retries to configure resume attempt limit."
|
| 852 |
+
else:
|
| 853 |
+
# Download retrying is not enabled.
|
| 854 |
+
retry_status = ""
|
| 855 |
+
hint = "Consider using --resume-retries to enable download resumption."
|
| 856 |
+
message = Text(
|
| 857 |
+
f"Download failed {retry_status}because not enough bytes "
|
| 858 |
+
f"were received ({download_status})"
|
| 859 |
+
)
|
| 860 |
+
|
| 861 |
+
super().__init__(
|
| 862 |
+
message=message,
|
| 863 |
+
context=f"URL: {download.link.redacted_url}",
|
| 864 |
+
hint_stmt=hint,
|
| 865 |
+
note_stmt="This is an issue with network connectivity, not pip.",
|
| 866 |
+
)
|
| 867 |
+
|
| 868 |
+
|
| 869 |
+
class ResolutionTooDeepError(DiagnosticPipError):
|
| 870 |
+
"""Raised when the dependency resolver exceeds the maximum recursion depth."""
|
| 871 |
+
|
| 872 |
+
reference = "resolution-too-deep"
|
| 873 |
+
|
| 874 |
+
def __init__(self) -> None:
|
| 875 |
+
super().__init__(
|
| 876 |
+
message="Dependency resolution exceeded maximum depth",
|
| 877 |
+
context=(
|
| 878 |
+
"Pip cannot resolve the current dependencies as the dependency graph "
|
| 879 |
+
"is too complex for pip to solve efficiently."
|
| 880 |
+
),
|
| 881 |
+
hint_stmt=(
|
| 882 |
+
"Try adding lower bounds to constrain your dependencies, "
|
| 883 |
+
"for example: 'package>=2.0.0' instead of just 'package'. "
|
| 884 |
+
),
|
| 885 |
+
link="https://pip.pypa.io/en/stable/topics/dependency-resolution/#handling-resolution-too-deep-errors",
|
| 886 |
+
)
|
| 887 |
+
|
| 888 |
+
|
| 889 |
+
class InstallWheelBuildError(DiagnosticPipError):
|
| 890 |
+
reference = "failed-wheel-build-for-install"
|
| 891 |
+
|
| 892 |
+
def __init__(self, failed: list[InstallRequirement]) -> None:
|
| 893 |
+
super().__init__(
|
| 894 |
+
message=(
|
| 895 |
+
"Failed to build installable wheels for some "
|
| 896 |
+
"pyproject.toml based projects"
|
| 897 |
+
),
|
| 898 |
+
context=", ".join(r.name for r in failed), # type: ignore
|
| 899 |
+
hint_stmt=None,
|
| 900 |
+
)
|
| 901 |
+
|
| 902 |
+
|
| 903 |
+
class InvalidEggFragment(DiagnosticPipError):
|
| 904 |
+
reference = "invalid-egg-fragment"
|
| 905 |
+
|
| 906 |
+
def __init__(self, link: Link, fragment: str) -> None:
|
| 907 |
+
hint = ""
|
| 908 |
+
if ">" in fragment or "=" in fragment or "<" in fragment:
|
| 909 |
+
hint = (
|
| 910 |
+
"Version specifiers are silently ignored for URL references. "
|
| 911 |
+
"Remove them. "
|
| 912 |
+
)
|
| 913 |
+
if "[" in fragment and "]" in fragment:
|
| 914 |
+
hint += "Try using the Direct URL requirement syntax: 'name[extra] @ URL'"
|
| 915 |
+
|
| 916 |
+
if not hint:
|
| 917 |
+
hint = "Egg fragments can only be a valid project name."
|
| 918 |
+
|
| 919 |
+
super().__init__(
|
| 920 |
+
message=f"The '{escape(fragment)}' egg fragment is invalid",
|
| 921 |
+
context=f"from '{escape(str(link))}'",
|
| 922 |
+
hint_stmt=escape(hint),
|
| 923 |
+
)
|
| 924 |
+
|
| 925 |
+
|
| 926 |
+
class BuildDependencyInstallError(DiagnosticPipError):
|
| 927 |
+
"""Raised when build dependencies cannot be installed."""
|
| 928 |
+
|
| 929 |
+
reference = "failed-build-dependency-install"
|
| 930 |
+
|
| 931 |
+
def __init__(
|
| 932 |
+
self,
|
| 933 |
+
req: InstallRequirement | None,
|
| 934 |
+
build_reqs: Iterable[str],
|
| 935 |
+
*,
|
| 936 |
+
cause: Exception,
|
| 937 |
+
log_lines: list[str] | None,
|
| 938 |
+
) -> None:
|
| 939 |
+
if isinstance(cause, PipError):
|
| 940 |
+
note = "This is likely not a problem with pip."
|
| 941 |
+
else:
|
| 942 |
+
note = (
|
| 943 |
+
"pip crashed unexpectedly. Please file an issue on pip's issue "
|
| 944 |
+
"tracker: https://github.com/pypa/pip/issues/new"
|
| 945 |
+
)
|
| 946 |
+
|
| 947 |
+
if log_lines is None:
|
| 948 |
+
# No logs are available, they must have been printed earlier.
|
| 949 |
+
context = Text("See above for more details.")
|
| 950 |
+
else:
|
| 951 |
+
if isinstance(cause, PipError):
|
| 952 |
+
log_lines.append(f"ERROR: {cause}")
|
| 953 |
+
else:
|
| 954 |
+
# Split rendered error into real lines without trailing newlines.
|
| 955 |
+
log_lines.extend(
|
| 956 |
+
"".join(traceback.format_exception(cause)).splitlines()
|
| 957 |
+
)
|
| 958 |
+
|
| 959 |
+
context = Text.assemble(
|
| 960 |
+
f"Installing {' '.join(build_reqs)}\n",
|
| 961 |
+
(f"[{len(log_lines)} lines of output]\n", "red"),
|
| 962 |
+
"\n".join(log_lines),
|
| 963 |
+
("\n[end of output]", "red"),
|
| 964 |
+
)
|
| 965 |
+
|
| 966 |
+
message = Text("Cannot install build dependencies", "green")
|
| 967 |
+
if req:
|
| 968 |
+
message += Text(f" for {req}")
|
| 969 |
+
super().__init__(
|
| 970 |
+
message=message, context=context, hint_stmt=None, note_stmt=note
|
| 971 |
+
)
|
.venv/lib/python3.12/site-packages/pip/_internal/index/collector.py
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
The main purpose of this module is to expose LinkCollector.collect_sources().
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import collections
|
| 8 |
+
import email.message
|
| 9 |
+
import functools
|
| 10 |
+
import itertools
|
| 11 |
+
import json
|
| 12 |
+
import logging
|
| 13 |
+
import os
|
| 14 |
+
import urllib.parse
|
| 15 |
+
from collections.abc import Iterable, MutableMapping, Sequence
|
| 16 |
+
from dataclasses import dataclass
|
| 17 |
+
from html.parser import HTMLParser
|
| 18 |
+
from optparse import Values
|
| 19 |
+
from typing import (
|
| 20 |
+
Callable,
|
| 21 |
+
NamedTuple,
|
| 22 |
+
Protocol,
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
from pip._vendor import requests
|
| 26 |
+
from pip._vendor.requests import Response
|
| 27 |
+
from pip._vendor.requests.exceptions import RetryError, SSLError
|
| 28 |
+
|
| 29 |
+
from pip._internal.exceptions import NetworkConnectionError
|
| 30 |
+
from pip._internal.models.link import Link
|
| 31 |
+
from pip._internal.models.search_scope import SearchScope
|
| 32 |
+
from pip._internal.network.session import PipSession
|
| 33 |
+
from pip._internal.network.utils import raise_for_status
|
| 34 |
+
from pip._internal.utils.filetypes import is_archive_file
|
| 35 |
+
from pip._internal.utils.misc import redact_auth_from_url
|
| 36 |
+
from pip._internal.utils.urls import url_to_path
|
| 37 |
+
from pip._internal.vcs import vcs
|
| 38 |
+
|
| 39 |
+
from .sources import CandidatesFromPage, LinkSource, build_source
|
| 40 |
+
|
| 41 |
+
logger = logging.getLogger(__name__)
|
| 42 |
+
|
| 43 |
+
ResponseHeaders = MutableMapping[str, str]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _match_vcs_scheme(url: str) -> str | None:
|
| 47 |
+
"""Look for VCS schemes in the URL.
|
| 48 |
+
|
| 49 |
+
Returns the matched VCS scheme, or None if there's no match.
|
| 50 |
+
"""
|
| 51 |
+
for scheme in vcs.schemes:
|
| 52 |
+
if url.lower().startswith(scheme) and url[len(scheme)] in "+:":
|
| 53 |
+
return scheme
|
| 54 |
+
return None
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class _NotAPIContent(Exception):
|
| 58 |
+
def __init__(self, content_type: str, request_desc: str) -> None:
|
| 59 |
+
super().__init__(content_type, request_desc)
|
| 60 |
+
self.content_type = content_type
|
| 61 |
+
self.request_desc = request_desc
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _ensure_api_header(response: Response) -> None:
|
| 65 |
+
"""
|
| 66 |
+
Check the Content-Type header to ensure the response contains a Simple
|
| 67 |
+
API Response.
|
| 68 |
+
|
| 69 |
+
Raises `_NotAPIContent` if the content type is not a valid content-type.
|
| 70 |
+
"""
|
| 71 |
+
content_type = response.headers.get("Content-Type", "Unknown")
|
| 72 |
+
|
| 73 |
+
content_type_l = content_type.lower()
|
| 74 |
+
if content_type_l.startswith(
|
| 75 |
+
(
|
| 76 |
+
"text/html",
|
| 77 |
+
"application/vnd.pypi.simple.v1+html",
|
| 78 |
+
"application/vnd.pypi.simple.v1+json",
|
| 79 |
+
)
|
| 80 |
+
):
|
| 81 |
+
return
|
| 82 |
+
|
| 83 |
+
raise _NotAPIContent(content_type, response.request.method)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
class _NotHTTP(Exception):
|
| 87 |
+
pass
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _ensure_api_response(url: str, session: PipSession) -> None:
|
| 91 |
+
"""
|
| 92 |
+
Send a HEAD request to the URL, and ensure the response contains a simple
|
| 93 |
+
API Response.
|
| 94 |
+
|
| 95 |
+
Raises `_NotHTTP` if the URL is not available for a HEAD request, or
|
| 96 |
+
`_NotAPIContent` if the content type is not a valid content type.
|
| 97 |
+
"""
|
| 98 |
+
scheme, netloc, path, query, fragment = urllib.parse.urlsplit(url)
|
| 99 |
+
if scheme not in {"http", "https"}:
|
| 100 |
+
raise _NotHTTP()
|
| 101 |
+
|
| 102 |
+
resp = session.head(url, allow_redirects=True)
|
| 103 |
+
raise_for_status(resp)
|
| 104 |
+
|
| 105 |
+
_ensure_api_header(resp)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def _get_simple_response(url: str, session: PipSession) -> Response:
|
| 109 |
+
"""Access an Simple API response with GET, and return the response.
|
| 110 |
+
|
| 111 |
+
This consists of three parts:
|
| 112 |
+
|
| 113 |
+
1. If the URL looks suspiciously like an archive, send a HEAD first to
|
| 114 |
+
check the Content-Type is HTML or Simple API, to avoid downloading a
|
| 115 |
+
large file. Raise `_NotHTTP` if the content type cannot be determined, or
|
| 116 |
+
`_NotAPIContent` if it is not HTML or a Simple API.
|
| 117 |
+
2. Actually perform the request. Raise HTTP exceptions on network failures.
|
| 118 |
+
3. Check the Content-Type header to make sure we got a Simple API response,
|
| 119 |
+
and raise `_NotAPIContent` otherwise.
|
| 120 |
+
"""
|
| 121 |
+
if is_archive_file(Link(url).filename):
|
| 122 |
+
_ensure_api_response(url, session=session)
|
| 123 |
+
|
| 124 |
+
logger.debug("Getting page %s", redact_auth_from_url(url))
|
| 125 |
+
|
| 126 |
+
resp = session.get(
|
| 127 |
+
url,
|
| 128 |
+
headers={
|
| 129 |
+
"Accept": ", ".join(
|
| 130 |
+
[
|
| 131 |
+
"application/vnd.pypi.simple.v1+json",
|
| 132 |
+
"application/vnd.pypi.simple.v1+html; q=0.1",
|
| 133 |
+
"text/html; q=0.01",
|
| 134 |
+
]
|
| 135 |
+
),
|
| 136 |
+
# We don't want to blindly returned cached data for
|
| 137 |
+
# /simple/, because authors generally expecting that
|
| 138 |
+
# twine upload && pip install will function, but if
|
| 139 |
+
# they've done a pip install in the last ~10 minutes
|
| 140 |
+
# it won't. Thus by setting this to zero we will not
|
| 141 |
+
# blindly use any cached data, however the benefit of
|
| 142 |
+
# using max-age=0 instead of no-cache, is that we will
|
| 143 |
+
# still support conditional requests, so we will still
|
| 144 |
+
# minimize traffic sent in cases where the page hasn't
|
| 145 |
+
# changed at all, we will just always incur the round
|
| 146 |
+
# trip for the conditional GET now instead of only
|
| 147 |
+
# once per 10 minutes.
|
| 148 |
+
# For more information, please see pypa/pip#5670.
|
| 149 |
+
"Cache-Control": "max-age=0",
|
| 150 |
+
},
|
| 151 |
+
)
|
| 152 |
+
raise_for_status(resp)
|
| 153 |
+
|
| 154 |
+
# The check for archives above only works if the url ends with
|
| 155 |
+
# something that looks like an archive. However that is not a
|
| 156 |
+
# requirement of an url. Unless we issue a HEAD request on every
|
| 157 |
+
# url we cannot know ahead of time for sure if something is a
|
| 158 |
+
# Simple API response or not. However we can check after we've
|
| 159 |
+
# downloaded it.
|
| 160 |
+
_ensure_api_header(resp)
|
| 161 |
+
|
| 162 |
+
logger.debug(
|
| 163 |
+
"Fetched page %s as %s",
|
| 164 |
+
redact_auth_from_url(url),
|
| 165 |
+
resp.headers.get("Content-Type", "Unknown"),
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
return resp
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def _get_encoding_from_headers(headers: ResponseHeaders) -> str | None:
|
| 172 |
+
"""Determine if we have any encoding information in our headers."""
|
| 173 |
+
if headers and "Content-Type" in headers:
|
| 174 |
+
m = email.message.Message()
|
| 175 |
+
m["content-type"] = headers["Content-Type"]
|
| 176 |
+
charset = m.get_param("charset")
|
| 177 |
+
if charset:
|
| 178 |
+
return str(charset)
|
| 179 |
+
return None
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
class CacheablePageContent:
|
| 183 |
+
def __init__(self, page: IndexContent) -> None:
|
| 184 |
+
assert page.cache_link_parsing
|
| 185 |
+
self.page = page
|
| 186 |
+
|
| 187 |
+
def __eq__(self, other: object) -> bool:
|
| 188 |
+
return isinstance(other, type(self)) and self.page.url == other.page.url
|
| 189 |
+
|
| 190 |
+
def __hash__(self) -> int:
|
| 191 |
+
return hash(self.page.url)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
class ParseLinks(Protocol):
|
| 195 |
+
def __call__(self, page: IndexContent) -> Iterable[Link]: ...
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def with_cached_index_content(fn: ParseLinks) -> ParseLinks:
|
| 199 |
+
"""
|
| 200 |
+
Given a function that parses an Iterable[Link] from an IndexContent, cache the
|
| 201 |
+
function's result (keyed by CacheablePageContent), unless the IndexContent
|
| 202 |
+
`page` has `page.cache_link_parsing == False`.
|
| 203 |
+
"""
|
| 204 |
+
|
| 205 |
+
@functools.cache
|
| 206 |
+
def wrapper(cacheable_page: CacheablePageContent) -> list[Link]:
|
| 207 |
+
return list(fn(cacheable_page.page))
|
| 208 |
+
|
| 209 |
+
@functools.wraps(fn)
|
| 210 |
+
def wrapper_wrapper(page: IndexContent) -> list[Link]:
|
| 211 |
+
if page.cache_link_parsing:
|
| 212 |
+
return wrapper(CacheablePageContent(page))
|
| 213 |
+
return list(fn(page))
|
| 214 |
+
|
| 215 |
+
return wrapper_wrapper
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
@with_cached_index_content
|
| 219 |
+
def parse_links(page: IndexContent) -> Iterable[Link]:
|
| 220 |
+
"""
|
| 221 |
+
Parse a Simple API's Index Content, and yield its anchor elements as Link objects.
|
| 222 |
+
"""
|
| 223 |
+
|
| 224 |
+
content_type_l = page.content_type.lower()
|
| 225 |
+
if content_type_l.startswith("application/vnd.pypi.simple.v1+json"):
|
| 226 |
+
data = json.loads(page.content)
|
| 227 |
+
for file in data.get("files", []):
|
| 228 |
+
link = Link.from_json(file, page.url)
|
| 229 |
+
if link is None:
|
| 230 |
+
continue
|
| 231 |
+
yield link
|
| 232 |
+
return
|
| 233 |
+
|
| 234 |
+
parser = HTMLLinkParser(page.url)
|
| 235 |
+
encoding = page.encoding or "utf-8"
|
| 236 |
+
parser.feed(page.content.decode(encoding))
|
| 237 |
+
|
| 238 |
+
url = page.url
|
| 239 |
+
base_url = parser.base_url or url
|
| 240 |
+
for anchor in parser.anchors:
|
| 241 |
+
link = Link.from_element(anchor, page_url=url, base_url=base_url)
|
| 242 |
+
if link is None:
|
| 243 |
+
continue
|
| 244 |
+
yield link
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
@dataclass(frozen=True)
|
| 248 |
+
class IndexContent:
|
| 249 |
+
"""Represents one response (or page), along with its URL.
|
| 250 |
+
|
| 251 |
+
:param encoding: the encoding to decode the given content.
|
| 252 |
+
:param url: the URL from which the HTML was downloaded.
|
| 253 |
+
:param cache_link_parsing: whether links parsed from this page's url
|
| 254 |
+
should be cached. PyPI index urls should
|
| 255 |
+
have this set to False, for example.
|
| 256 |
+
"""
|
| 257 |
+
|
| 258 |
+
content: bytes
|
| 259 |
+
content_type: str
|
| 260 |
+
encoding: str | None
|
| 261 |
+
url: str
|
| 262 |
+
cache_link_parsing: bool = True
|
| 263 |
+
|
| 264 |
+
def __str__(self) -> str:
|
| 265 |
+
return redact_auth_from_url(self.url)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
class HTMLLinkParser(HTMLParser):
|
| 269 |
+
"""
|
| 270 |
+
HTMLParser that keeps the first base HREF and a list of all anchor
|
| 271 |
+
elements' attributes.
|
| 272 |
+
"""
|
| 273 |
+
|
| 274 |
+
def __init__(self, url: str) -> None:
|
| 275 |
+
super().__init__(convert_charrefs=True)
|
| 276 |
+
|
| 277 |
+
self.url: str = url
|
| 278 |
+
self.base_url: str | None = None
|
| 279 |
+
self.anchors: list[dict[str, str | None]] = []
|
| 280 |
+
|
| 281 |
+
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
|
| 282 |
+
if tag == "base" and self.base_url is None:
|
| 283 |
+
href = self.get_href(attrs)
|
| 284 |
+
if href is not None:
|
| 285 |
+
self.base_url = href
|
| 286 |
+
elif tag == "a":
|
| 287 |
+
self.anchors.append(dict(attrs))
|
| 288 |
+
|
| 289 |
+
def get_href(self, attrs: list[tuple[str, str | None]]) -> str | None:
|
| 290 |
+
for name, value in attrs:
|
| 291 |
+
if name == "href":
|
| 292 |
+
return value
|
| 293 |
+
return None
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def _handle_get_simple_fail(
|
| 297 |
+
link: Link,
|
| 298 |
+
reason: str | Exception,
|
| 299 |
+
meth: Callable[..., None] | None = None,
|
| 300 |
+
) -> None:
|
| 301 |
+
if meth is None:
|
| 302 |
+
meth = logger.debug
|
| 303 |
+
meth("Could not fetch URL %s: %s - skipping", link, reason)
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
def _make_index_content(
|
| 307 |
+
response: Response, cache_link_parsing: bool = True
|
| 308 |
+
) -> IndexContent:
|
| 309 |
+
encoding = _get_encoding_from_headers(response.headers)
|
| 310 |
+
return IndexContent(
|
| 311 |
+
response.content,
|
| 312 |
+
response.headers["Content-Type"],
|
| 313 |
+
encoding=encoding,
|
| 314 |
+
url=response.url,
|
| 315 |
+
cache_link_parsing=cache_link_parsing,
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def _get_index_content(link: Link, *, session: PipSession) -> IndexContent | None:
|
| 320 |
+
url = link.url.split("#", 1)[0]
|
| 321 |
+
|
| 322 |
+
# Check for VCS schemes that do not support lookup as web pages.
|
| 323 |
+
vcs_scheme = _match_vcs_scheme(url)
|
| 324 |
+
if vcs_scheme:
|
| 325 |
+
logger.warning(
|
| 326 |
+
"Cannot look at %s URL %s because it does not support lookup as web pages.",
|
| 327 |
+
vcs_scheme,
|
| 328 |
+
link,
|
| 329 |
+
)
|
| 330 |
+
return None
|
| 331 |
+
|
| 332 |
+
# Tack index.html onto file:// URLs that point to directories
|
| 333 |
+
if url.startswith("file:") and os.path.isdir(url_to_path(url)):
|
| 334 |
+
# add trailing slash if not present so urljoin doesn't trim
|
| 335 |
+
# final segment
|
| 336 |
+
if not url.endswith("/"):
|
| 337 |
+
url += "/"
|
| 338 |
+
# TODO: In the future, it would be nice if pip supported PEP 691
|
| 339 |
+
# style responses in the file:// URLs, however there's no
|
| 340 |
+
# standard file extension for application/vnd.pypi.simple.v1+json
|
| 341 |
+
# so we'll need to come up with something on our own.
|
| 342 |
+
url = urllib.parse.urljoin(url, "index.html")
|
| 343 |
+
logger.debug(" file: URL is directory, getting %s", url)
|
| 344 |
+
|
| 345 |
+
try:
|
| 346 |
+
resp = _get_simple_response(url, session=session)
|
| 347 |
+
except _NotHTTP:
|
| 348 |
+
logger.warning(
|
| 349 |
+
"Skipping page %s because it looks like an archive, and cannot "
|
| 350 |
+
"be checked by a HTTP HEAD request.",
|
| 351 |
+
link,
|
| 352 |
+
)
|
| 353 |
+
except _NotAPIContent as exc:
|
| 354 |
+
logger.warning(
|
| 355 |
+
"Skipping page %s because the %s request got Content-Type: %s. "
|
| 356 |
+
"The only supported Content-Types are application/vnd.pypi.simple.v1+json, "
|
| 357 |
+
"application/vnd.pypi.simple.v1+html, and text/html",
|
| 358 |
+
link,
|
| 359 |
+
exc.request_desc,
|
| 360 |
+
exc.content_type,
|
| 361 |
+
)
|
| 362 |
+
except NetworkConnectionError as exc:
|
| 363 |
+
_handle_get_simple_fail(link, exc)
|
| 364 |
+
except RetryError as exc:
|
| 365 |
+
_handle_get_simple_fail(link, exc)
|
| 366 |
+
except SSLError as exc:
|
| 367 |
+
reason = "There was a problem confirming the ssl certificate: "
|
| 368 |
+
reason += str(exc)
|
| 369 |
+
_handle_get_simple_fail(link, reason, meth=logger.info)
|
| 370 |
+
except requests.ConnectionError as exc:
|
| 371 |
+
_handle_get_simple_fail(link, f"connection error: {exc}")
|
| 372 |
+
except requests.Timeout:
|
| 373 |
+
_handle_get_simple_fail(link, "timed out")
|
| 374 |
+
else:
|
| 375 |
+
return _make_index_content(resp, cache_link_parsing=link.cache_link_parsing)
|
| 376 |
+
return None
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
class CollectedSources(NamedTuple):
|
| 380 |
+
find_links: Sequence[LinkSource | None]
|
| 381 |
+
index_urls: Sequence[LinkSource | None]
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
class LinkCollector:
|
| 385 |
+
"""
|
| 386 |
+
Responsible for collecting Link objects from all configured locations,
|
| 387 |
+
making network requests as needed.
|
| 388 |
+
|
| 389 |
+
The class's main method is its collect_sources() method.
|
| 390 |
+
"""
|
| 391 |
+
|
| 392 |
+
def __init__(
|
| 393 |
+
self,
|
| 394 |
+
session: PipSession,
|
| 395 |
+
search_scope: SearchScope,
|
| 396 |
+
) -> None:
|
| 397 |
+
self.search_scope = search_scope
|
| 398 |
+
self.session = session
|
| 399 |
+
|
| 400 |
+
@classmethod
|
| 401 |
+
def create(
|
| 402 |
+
cls,
|
| 403 |
+
session: PipSession,
|
| 404 |
+
options: Values,
|
| 405 |
+
suppress_no_index: bool = False,
|
| 406 |
+
) -> LinkCollector:
|
| 407 |
+
"""
|
| 408 |
+
:param session: The Session to use to make requests.
|
| 409 |
+
:param suppress_no_index: Whether to ignore the --no-index option
|
| 410 |
+
when constructing the SearchScope object.
|
| 411 |
+
"""
|
| 412 |
+
index_urls = [options.index_url] + options.extra_index_urls
|
| 413 |
+
if options.no_index and not suppress_no_index:
|
| 414 |
+
logger.debug(
|
| 415 |
+
"Ignoring indexes: %s",
|
| 416 |
+
",".join(redact_auth_from_url(url) for url in index_urls),
|
| 417 |
+
)
|
| 418 |
+
index_urls = []
|
| 419 |
+
|
| 420 |
+
# Make sure find_links is a list before passing to create().
|
| 421 |
+
find_links = options.find_links or []
|
| 422 |
+
|
| 423 |
+
search_scope = SearchScope.create(
|
| 424 |
+
find_links=find_links,
|
| 425 |
+
index_urls=index_urls,
|
| 426 |
+
no_index=options.no_index,
|
| 427 |
+
)
|
| 428 |
+
link_collector = LinkCollector(
|
| 429 |
+
session=session,
|
| 430 |
+
search_scope=search_scope,
|
| 431 |
+
)
|
| 432 |
+
return link_collector
|
| 433 |
+
|
| 434 |
+
@property
|
| 435 |
+
def find_links(self) -> list[str]:
|
| 436 |
+
return self.search_scope.find_links
|
| 437 |
+
|
| 438 |
+
def fetch_response(self, location: Link) -> IndexContent | None:
|
| 439 |
+
"""
|
| 440 |
+
Fetch an HTML page containing package links.
|
| 441 |
+
"""
|
| 442 |
+
return _get_index_content(location, session=self.session)
|
| 443 |
+
|
| 444 |
+
def collect_sources(
|
| 445 |
+
self,
|
| 446 |
+
project_name: str,
|
| 447 |
+
candidates_from_page: CandidatesFromPage,
|
| 448 |
+
) -> CollectedSources:
|
| 449 |
+
# The OrderedDict calls deduplicate sources by URL.
|
| 450 |
+
index_url_sources = collections.OrderedDict(
|
| 451 |
+
build_source(
|
| 452 |
+
loc,
|
| 453 |
+
candidates_from_page=candidates_from_page,
|
| 454 |
+
page_validator=self.session.is_secure_origin,
|
| 455 |
+
expand_dir=False,
|
| 456 |
+
cache_link_parsing=False,
|
| 457 |
+
project_name=project_name,
|
| 458 |
+
)
|
| 459 |
+
for loc in self.search_scope.get_index_urls_locations(project_name)
|
| 460 |
+
).values()
|
| 461 |
+
find_links_sources = collections.OrderedDict(
|
| 462 |
+
build_source(
|
| 463 |
+
loc,
|
| 464 |
+
candidates_from_page=candidates_from_page,
|
| 465 |
+
page_validator=self.session.is_secure_origin,
|
| 466 |
+
expand_dir=True,
|
| 467 |
+
cache_link_parsing=True,
|
| 468 |
+
project_name=project_name,
|
| 469 |
+
)
|
| 470 |
+
for loc in self.find_links
|
| 471 |
+
).values()
|
| 472 |
+
|
| 473 |
+
if logger.isEnabledFor(logging.DEBUG):
|
| 474 |
+
lines = [
|
| 475 |
+
f"* {s.link}"
|
| 476 |
+
for s in itertools.chain(find_links_sources, index_url_sources)
|
| 477 |
+
if s is not None and s.link is not None
|
| 478 |
+
]
|
| 479 |
+
lines = [
|
| 480 |
+
f"{len(lines)} location(s) to search "
|
| 481 |
+
f"for versions of {project_name}:"
|
| 482 |
+
] + lines
|
| 483 |
+
logger.debug("\n".join(lines))
|
| 484 |
+
|
| 485 |
+
return CollectedSources(
|
| 486 |
+
find_links=list(find_links_sources),
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Routines related to PyPI, indexes"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import datetime
|
| 6 |
+
import enum
|
| 7 |
+
import functools
|
| 8 |
+
import itertools
|
| 9 |
+
import logging
|
| 10 |
+
import re
|
| 11 |
+
from collections.abc import Iterable
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
from typing import (
|
| 14 |
+
TYPE_CHECKING,
|
| 15 |
+
Optional,
|
| 16 |
+
Union,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
from pip._vendor.packaging import specifiers
|
| 20 |
+
from pip._vendor.packaging.tags import Tag
|
| 21 |
+
from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
|
| 22 |
+
from pip._vendor.packaging.version import InvalidVersion, Version, _BaseVersion
|
| 23 |
+
from pip._vendor.packaging.version import parse as parse_version
|
| 24 |
+
|
| 25 |
+
from pip._internal.exceptions import (
|
| 26 |
+
BestVersionAlreadyInstalled,
|
| 27 |
+
DistributionNotFound,
|
| 28 |
+
InstallationError,
|
| 29 |
+
InvalidWheelFilename,
|
| 30 |
+
UnsupportedWheel,
|
| 31 |
+
)
|
| 32 |
+
from pip._internal.index.collector import LinkCollector, parse_links
|
| 33 |
+
from pip._internal.metadata import select_backend
|
| 34 |
+
from pip._internal.models.candidate import InstallationCandidate
|
| 35 |
+
from pip._internal.models.format_control import FormatControl
|
| 36 |
+
from pip._internal.models.link import Link
|
| 37 |
+
from pip._internal.models.release_control import ReleaseControl
|
| 38 |
+
from pip._internal.models.search_scope import SearchScope
|
| 39 |
+
from pip._internal.models.selection_prefs import SelectionPreferences
|
| 40 |
+
from pip._internal.models.target_python import TargetPython
|
| 41 |
+
from pip._internal.models.wheel import Wheel
|
| 42 |
+
from pip._internal.req import InstallRequirement
|
| 43 |
+
from pip._internal.utils._log import getLogger
|
| 44 |
+
from pip._internal.utils.filetypes import WHEEL_EXTENSION
|
| 45 |
+
from pip._internal.utils.hashes import Hashes
|
| 46 |
+
from pip._internal.utils.logging import indent_log
|
| 47 |
+
from pip._internal.utils.misc import build_netloc
|
| 48 |
+
from pip._internal.utils.packaging import check_requires_python
|
| 49 |
+
from pip._internal.utils.unpacking import SUPPORTED_EXTENSIONS
|
| 50 |
+
|
| 51 |
+
if TYPE_CHECKING:
|
| 52 |
+
from typing_extensions import TypeGuard
|
| 53 |
+
|
| 54 |
+
__all__ = ["FormatControl", "BestCandidateResult", "PackageFinder"]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
logger = getLogger(__name__)
|
| 58 |
+
|
| 59 |
+
BuildTag = Union[tuple[()], tuple[int, str]]
|
| 60 |
+
CandidateSortingKey = tuple[int, int, int, _BaseVersion, Optional[int], BuildTag]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def _check_link_requires_python(
|
| 64 |
+
link: Link,
|
| 65 |
+
version_info: tuple[int, int, int],
|
| 66 |
+
ignore_requires_python: bool = False,
|
| 67 |
+
) -> bool:
|
| 68 |
+
"""
|
| 69 |
+
Return whether the given Python version is compatible with a link's
|
| 70 |
+
"Requires-Python" value.
|
| 71 |
+
|
| 72 |
+
:param version_info: A 3-tuple of ints representing the Python
|
| 73 |
+
major-minor-micro version to check.
|
| 74 |
+
:param ignore_requires_python: Whether to ignore the "Requires-Python"
|
| 75 |
+
value if the given Python version isn't compatible.
|
| 76 |
+
"""
|
| 77 |
+
try:
|
| 78 |
+
is_compatible = check_requires_python(
|
| 79 |
+
link.requires_python,
|
| 80 |
+
version_info=version_info,
|
| 81 |
+
)
|
| 82 |
+
except specifiers.InvalidSpecifier:
|
| 83 |
+
logger.debug(
|
| 84 |
+
"Ignoring invalid Requires-Python (%r) for link: %s",
|
| 85 |
+
link.requires_python,
|
| 86 |
+
link,
|
| 87 |
+
)
|
| 88 |
+
else:
|
| 89 |
+
if not is_compatible:
|
| 90 |
+
version = ".".join(map(str, version_info))
|
| 91 |
+
if not ignore_requires_python:
|
| 92 |
+
logger.verbose(
|
| 93 |
+
"Link requires a different Python (%s not in: %r): %s",
|
| 94 |
+
version,
|
| 95 |
+
link.requires_python,
|
| 96 |
+
link,
|
| 97 |
+
)
|
| 98 |
+
return False
|
| 99 |
+
|
| 100 |
+
logger.debug(
|
| 101 |
+
"Ignoring failed Requires-Python check (%s not in: %r) for link: %s",
|
| 102 |
+
version,
|
| 103 |
+
link.requires_python,
|
| 104 |
+
link,
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
return True
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
class LinkType(enum.Enum):
|
| 111 |
+
candidate = enum.auto()
|
| 112 |
+
different_project = enum.auto()
|
| 113 |
+
yanked = enum.auto()
|
| 114 |
+
format_unsupported = enum.auto()
|
| 115 |
+
format_invalid = enum.auto()
|
| 116 |
+
platform_mismatch = enum.auto()
|
| 117 |
+
requires_python_mismatch = enum.auto()
|
| 118 |
+
upload_too_late = enum.auto()
|
| 119 |
+
upload_time_missing = enum.auto()
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
class LinkEvaluator:
|
| 123 |
+
"""
|
| 124 |
+
Responsible for evaluating links for a particular project.
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
_py_version_re = re.compile(r"-py([123]\.?[0-9]?)$")
|
| 128 |
+
|
| 129 |
+
# Don't include an allow_yanked default value to make sure each call
|
| 130 |
+
# site considers whether yanked releases are allowed. This also causes
|
| 131 |
+
# that decision to be made explicit in the calling code, which helps
|
| 132 |
+
# people when reading the code.
|
| 133 |
+
def __init__(
|
| 134 |
+
self,
|
| 135 |
+
project_name: str,
|
| 136 |
+
canonical_name: NormalizedName,
|
| 137 |
+
formats: frozenset[str],
|
| 138 |
+
target_python: TargetPython,
|
| 139 |
+
allow_yanked: bool,
|
| 140 |
+
ignore_requires_python: bool | None = None,
|
| 141 |
+
uploaded_prior_to: datetime.datetime | None = None,
|
| 142 |
+
) -> None:
|
| 143 |
+
"""
|
| 144 |
+
:param project_name: The user supplied package name.
|
| 145 |
+
:param canonical_name: The canonical package name.
|
| 146 |
+
:param formats: The formats allowed for this package. Should be a set
|
| 147 |
+
with 'binary' or 'source' or both in it.
|
| 148 |
+
:param target_python: The target Python interpreter to use when
|
| 149 |
+
evaluating link compatibility. This is used, for example, to
|
| 150 |
+
check wheel compatibility, as well as when checking the Python
|
| 151 |
+
version, e.g. the Python version embedded in a link filename
|
| 152 |
+
(or egg fragment) and against an HTML link's optional PEP 503
|
| 153 |
+
"data-requires-python" attribute.
|
| 154 |
+
:param allow_yanked: Whether files marked as yanked (in the sense
|
| 155 |
+
of PEP 592) are permitted to be candidates for install.
|
| 156 |
+
:param ignore_requires_python: Whether to ignore incompatible
|
| 157 |
+
PEP 503 "data-requires-python" values in HTML links. Defaults
|
| 158 |
+
to False.
|
| 159 |
+
:param uploaded_prior_to: If set, only allow links uploaded prior to
|
| 160 |
+
the given datetime.
|
| 161 |
+
"""
|
| 162 |
+
if ignore_requires_python is None:
|
| 163 |
+
ignore_requires_python = False
|
| 164 |
+
|
| 165 |
+
self._allow_yanked = allow_yanked
|
| 166 |
+
self._canonical_name = canonical_name
|
| 167 |
+
self._ignore_requires_python = ignore_requires_python
|
| 168 |
+
self._formats = formats
|
| 169 |
+
self._target_python = target_python
|
| 170 |
+
self._uploaded_prior_to = uploaded_prior_to
|
| 171 |
+
|
| 172 |
+
self.project_name = project_name
|
| 173 |
+
|
| 174 |
+
def evaluate_link(self, link: Link) -> tuple[LinkType, str]:
|
| 175 |
+
"""
|
| 176 |
+
Determine whether a link is a candidate for installation.
|
| 177 |
+
|
| 178 |
+
:return: A tuple (result, detail), where *result* is an enum
|
| 179 |
+
representing whether the evaluation found a candidate, or the reason
|
| 180 |
+
why one is not found. If a candidate is found, *detail* will be the
|
| 181 |
+
candidate's version string; if one is not found, it contains the
|
| 182 |
+
reason the link fails to qualify.
|
| 183 |
+
"""
|
| 184 |
+
version = None
|
| 185 |
+
if link.is_yanked and not self._allow_yanked:
|
| 186 |
+
reason = link.yanked_reason or "<none given>"
|
| 187 |
+
return (LinkType.yanked, f"yanked for reason: {reason}")
|
| 188 |
+
|
| 189 |
+
if link.egg_fragment:
|
| 190 |
+
egg_info = link.egg_fragment
|
| 191 |
+
ext = link.ext
|
| 192 |
+
else:
|
| 193 |
+
egg_info, ext = link.splitext()
|
| 194 |
+
if not ext:
|
| 195 |
+
return (LinkType.format_unsupported, "not a file")
|
| 196 |
+
if ext not in SUPPORTED_EXTENSIONS:
|
| 197 |
+
return (
|
| 198 |
+
LinkType.format_unsupported,
|
| 199 |
+
f"unsupported archive format: {ext}",
|
| 200 |
+
)
|
| 201 |
+
if "binary" not in self._formats and ext == WHEEL_EXTENSION:
|
| 202 |
+
reason = f"No binaries permitted for {self.project_name}"
|
| 203 |
+
return (LinkType.format_unsupported, reason)
|
| 204 |
+
if "macosx10" in link.path and ext == ".zip":
|
| 205 |
+
return (LinkType.format_unsupported, "macosx10 one")
|
| 206 |
+
if ext == WHEEL_EXTENSION:
|
| 207 |
+
try:
|
| 208 |
+
wheel = Wheel(link.filename)
|
| 209 |
+
except InvalidWheelFilename:
|
| 210 |
+
return (
|
| 211 |
+
LinkType.format_invalid,
|
| 212 |
+
"invalid wheel filename",
|
| 213 |
+
)
|
| 214 |
+
if wheel.name != self._canonical_name:
|
| 215 |
+
reason = f"wrong project name (not {self.project_name})"
|
| 216 |
+
return (LinkType.different_project, reason)
|
| 217 |
+
|
| 218 |
+
supported_tags = self._target_python.get_unsorted_tags()
|
| 219 |
+
if not wheel.supported(supported_tags):
|
| 220 |
+
# Include the wheel's tags in the reason string to
|
| 221 |
+
# simplify troubleshooting compatibility issues.
|
| 222 |
+
file_tags = ", ".join(wheel.get_formatted_file_tags())
|
| 223 |
+
reason = (
|
| 224 |
+
f"none of the wheel's tags ({file_tags}) are compatible "
|
| 225 |
+
f"(run pip debug --verbose to show compatible tags)"
|
| 226 |
+
)
|
| 227 |
+
return (LinkType.platform_mismatch, reason)
|
| 228 |
+
|
| 229 |
+
version = wheel.version
|
| 230 |
+
|
| 231 |
+
# Check upload-time filter after verifying the link is a package file.
|
| 232 |
+
# Skip this check for local files, as --uploaded-prior-to only applies
|
| 233 |
+
# to packages from indexes.
|
| 234 |
+
if self._uploaded_prior_to is not None and not link.is_file:
|
| 235 |
+
if link.upload_time is None:
|
| 236 |
+
if link.comes_from:
|
| 237 |
+
index_info = f"Index {link.comes_from}"
|
| 238 |
+
else:
|
| 239 |
+
index_info = "Index"
|
| 240 |
+
|
| 241 |
+
return (
|
| 242 |
+
LinkType.upload_time_missing,
|
| 243 |
+
f"{index_info} does not provide upload-time metadata.",
|
| 244 |
+
)
|
| 245 |
+
elif link.upload_time >= self._uploaded_prior_to:
|
| 246 |
+
return (
|
| 247 |
+
LinkType.upload_too_late,
|
| 248 |
+
f"Upload time {link.upload_time} not "
|
| 249 |
+
f"prior to {self._uploaded_prior_to}",
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
# This should be up by the self.ok_binary check, but see issue 2700.
|
| 253 |
+
if "source" not in self._formats and ext != WHEEL_EXTENSION:
|
| 254 |
+
reason = f"No sources permitted for {self.project_name}"
|
| 255 |
+
return (LinkType.format_unsupported, reason)
|
| 256 |
+
|
| 257 |
+
if not version:
|
| 258 |
+
version = _extract_version_from_fragment(
|
| 259 |
+
egg_info,
|
| 260 |
+
self._canonical_name,
|
| 261 |
+
)
|
| 262 |
+
if not version:
|
| 263 |
+
reason = f"Missing project version for {self.project_name}"
|
| 264 |
+
return (LinkType.format_invalid, reason)
|
| 265 |
+
|
| 266 |
+
match = self._py_version_re.search(version)
|
| 267 |
+
if match:
|
| 268 |
+
version = version[: match.start()]
|
| 269 |
+
py_version = match.group(1)
|
| 270 |
+
if py_version != self._target_python.py_version:
|
| 271 |
+
return (
|
| 272 |
+
LinkType.platform_mismatch,
|
| 273 |
+
"Python version is incorrect",
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
supports_python = _check_link_requires_python(
|
| 277 |
+
link,
|
| 278 |
+
version_info=self._target_python.py_version_info,
|
| 279 |
+
ignore_requires_python=self._ignore_requires_python,
|
| 280 |
+
)
|
| 281 |
+
if not supports_python:
|
| 282 |
+
requires_python = link.requires_python
|
| 283 |
+
if requires_python:
|
| 284 |
+
|
| 285 |
+
def get_version_sort_key(v: str) -> tuple[int, ...]:
|
| 286 |
+
return tuple(int(s) for s in v.split(".") if s.isdigit())
|
| 287 |
+
|
| 288 |
+
requires_python = ",".join(
|
| 289 |
+
sorted(
|
| 290 |
+
(str(s) for s in specifiers.SpecifierSet(requires_python)),
|
| 291 |
+
key=get_version_sort_key,
|
| 292 |
+
)
|
| 293 |
+
)
|
| 294 |
+
reason = f"{version} Requires-Python {requires_python}"
|
| 295 |
+
return (LinkType.requires_python_mismatch, reason)
|
| 296 |
+
|
| 297 |
+
logger.debug("Found link %s, version: %s", link, version)
|
| 298 |
+
|
| 299 |
+
return (LinkType.candidate, version)
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def filter_unallowed_hashes(
|
| 303 |
+
candidates: list[InstallationCandidate],
|
| 304 |
+
hashes: Hashes | None,
|
| 305 |
+
project_name: str,
|
| 306 |
+
) -> list[InstallationCandidate]:
|
| 307 |
+
"""
|
| 308 |
+
Filter out candidates whose hashes aren't allowed, and return a new
|
| 309 |
+
list of candidates.
|
| 310 |
+
|
| 311 |
+
If at least one candidate has an allowed hash, then all candidates with
|
| 312 |
+
either an allowed hash or no hash specified are returned. Otherwise,
|
| 313 |
+
the given candidates are returned.
|
| 314 |
+
|
| 315 |
+
Including the candidates with no hash specified when there is a match
|
| 316 |
+
allows a warning to be logged if there is a more preferred candidate
|
| 317 |
+
with no hash specified. Returning all candidates in the case of no
|
| 318 |
+
matches lets pip report the hash of the candidate that would otherwise
|
| 319 |
+
have been installed (e.g. permitting the user to more easily update
|
| 320 |
+
their requirements file with the desired hash).
|
| 321 |
+
"""
|
| 322 |
+
if not hashes:
|
| 323 |
+
logger.debug(
|
| 324 |
+
"Given no hashes to check %s links for project %r: "
|
| 325 |
+
"discarding no candidates",
|
| 326 |
+
len(candidates),
|
| 327 |
+
project_name,
|
| 328 |
+
)
|
| 329 |
+
# Make sure we're not returning back the given value.
|
| 330 |
+
return list(candidates)
|
| 331 |
+
|
| 332 |
+
matches_or_no_digest = []
|
| 333 |
+
# Collect the non-matches for logging purposes.
|
| 334 |
+
non_matches = []
|
| 335 |
+
match_count = 0
|
| 336 |
+
for candidate in candidates:
|
| 337 |
+
link = candidate.link
|
| 338 |
+
if not link.has_hash:
|
| 339 |
+
pass
|
| 340 |
+
elif link.is_hash_allowed(hashes=hashes):
|
| 341 |
+
match_count += 1
|
| 342 |
+
else:
|
| 343 |
+
non_matches.append(candidate)
|
| 344 |
+
continue
|
| 345 |
+
|
| 346 |
+
matches_or_no_digest.append(candidate)
|
| 347 |
+
|
| 348 |
+
if match_count:
|
| 349 |
+
filtered = matches_or_no_digest
|
| 350 |
+
else:
|
| 351 |
+
# Make sure we're not returning back the given value.
|
| 352 |
+
filtered = list(candidates)
|
| 353 |
+
|
| 354 |
+
if len(filtered) == len(candidates):
|
| 355 |
+
discard_message = "discarding no candidates"
|
| 356 |
+
else:
|
| 357 |
+
discard_message = "discarding {} non-matches:\n {}".format(
|
| 358 |
+
len(non_matches),
|
| 359 |
+
"\n ".join(str(candidate.link) for candidate in non_matches),
|
| 360 |
+
)
|
| 361 |
+
|
| 362 |
+
logger.debug(
|
| 363 |
+
"Checked %s links for project %r against %s hashes "
|
| 364 |
+
"(%s matches, %s no digest): %s",
|
| 365 |
+
len(candidates),
|
| 366 |
+
project_name,
|
| 367 |
+
hashes.digest_count,
|
| 368 |
+
match_count,
|
| 369 |
+
len(matches_or_no_digest) - match_count,
|
| 370 |
+
discard_message,
|
| 371 |
+
)
|
| 372 |
+
|
| 373 |
+
return filtered
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
@dataclass
|
| 377 |
+
class CandidatePreferences:
|
| 378 |
+
"""
|
| 379 |
+
Encapsulates some of the preferences for filtering and sorting
|
| 380 |
+
InstallationCandidate objects.
|
| 381 |
+
"""
|
| 382 |
+
|
| 383 |
+
prefer_binary: bool = False
|
| 384 |
+
release_control: ReleaseControl | None = None
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
@dataclass(frozen=True)
|
| 388 |
+
class BestCandidateResult:
|
| 389 |
+
"""A collection of candidates, returned by `PackageFinder.find_best_candidate`.
|
| 390 |
+
|
| 391 |
+
This class is only intended to be instantiated by CandidateEvaluator's
|
| 392 |
+
`compute_best_candidate()` method.
|
| 393 |
+
|
| 394 |
+
:param all_candidates: A sequence of all available candidates found.
|
| 395 |
+
:param applicable_candidates: The applicable candidates.
|
| 396 |
+
:param best_candidate: The most preferred candidate found, or None
|
| 397 |
+
if no applicable candidates were found.
|
| 398 |
+
"""
|
| 399 |
+
|
| 400 |
+
all_candidates: list[InstallationCandidate]
|
| 401 |
+
applicable_candidates: list[InstallationCandidate]
|
| 402 |
+
best_candidate: InstallationCandidate | None
|
| 403 |
+
|
| 404 |
+
def __post_init__(self) -> None:
|
| 405 |
+
assert set(self.applicable_candidates) <= set(self.all_candidates)
|
| 406 |
+
|
| 407 |
+
if self.best_candidate is None:
|
| 408 |
+
assert not self.applicable_candidates
|
| 409 |
+
else:
|
| 410 |
+
assert self.best_candidate in self.applicable_candidates
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
class CandidateEvaluator:
|
| 414 |
+
"""
|
| 415 |
+
Responsible for filtering and sorting candidates for installation based
|
| 416 |
+
on what tags are valid.
|
| 417 |
+
"""
|
| 418 |
+
|
| 419 |
+
@classmethod
|
| 420 |
+
def create(
|
| 421 |
+
cls,
|
| 422 |
+
project_name: str,
|
| 423 |
+
target_python: TargetPython | None = None,
|
| 424 |
+
prefer_binary: bool = False,
|
| 425 |
+
release_control: ReleaseControl | None = None,
|
| 426 |
+
specifier: specifiers.BaseSpecifier | None = None,
|
| 427 |
+
hashes: Hashes | None = None,
|
| 428 |
+
) -> CandidateEvaluator:
|
| 429 |
+
"""Create a CandidateEvaluator object.
|
| 430 |
+
|
| 431 |
+
:param target_python: The target Python interpreter to use when
|
| 432 |
+
checking compatibility. If None (the default), a TargetPython
|
| 433 |
+
object will be constructed from the running Python.
|
| 434 |
+
:param specifier: An optional object implementing `filter`
|
| 435 |
+
(e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
|
| 436 |
+
versions.
|
| 437 |
+
:param hashes: An optional collection of allowed hashes.
|
| 438 |
+
"""
|
| 439 |
+
if target_python is None:
|
| 440 |
+
target_python = TargetPython()
|
| 441 |
+
if specifier is None:
|
| 442 |
+
specifier = specifiers.SpecifierSet()
|
| 443 |
+
|
| 444 |
+
supported_tags = target_python.get_sorted_tags()
|
| 445 |
+
|
| 446 |
+
return cls(
|
| 447 |
+
project_name=project_name,
|
| 448 |
+
supported_tags=supported_tags,
|
| 449 |
+
specifier=specifier,
|
| 450 |
+
prefer_binary=prefer_binary,
|
| 451 |
+
release_control=release_control,
|
| 452 |
+
hashes=hashes,
|
| 453 |
+
)
|
| 454 |
+
|
| 455 |
+
def __init__(
|
| 456 |
+
self,
|
| 457 |
+
project_name: str,
|
| 458 |
+
supported_tags: list[Tag],
|
| 459 |
+
specifier: specifiers.BaseSpecifier,
|
| 460 |
+
prefer_binary: bool = False,
|
| 461 |
+
release_control: ReleaseControl | None = None,
|
| 462 |
+
hashes: Hashes | None = None,
|
| 463 |
+
) -> None:
|
| 464 |
+
"""
|
| 465 |
+
:param supported_tags: The PEP 425 tags supported by the target
|
| 466 |
+
Python in order of preference (most preferred first).
|
| 467 |
+
"""
|
| 468 |
+
self._release_control = release_control
|
| 469 |
+
self._hashes = hashes
|
| 470 |
+
self._prefer_binary = prefer_binary
|
| 471 |
+
self._project_name = project_name
|
| 472 |
+
self._specifier = specifier
|
| 473 |
+
self._supported_tags = supported_tags
|
| 474 |
+
# Since the index of the tag in the _supported_tags list is used
|
| 475 |
+
# as a priority, precompute a map from tag to index/priority to be
|
| 476 |
+
# used in wheel.find_most_preferred_tag.
|
| 477 |
+
self._wheel_tag_preferences = {
|
| 478 |
+
tag: idx for idx, tag in enumerate(supported_tags)
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
def get_applicable_candidates(
|
| 482 |
+
self,
|
| 483 |
+
candidates: list[InstallationCandidate],
|
| 484 |
+
) -> list[InstallationCandidate]:
|
| 485 |
+
"""
|
| 486 |
+
Return the applicable candidates from a list of candidates.
|
| 487 |
+
"""
|
| 488 |
+
# Using None infers from the specifier instead.
|
| 489 |
+
if self._release_control is not None:
|
| 490 |
+
allow_prereleases = self._release_control.allows_prereleases(
|
| 491 |
+
canonicalize_name(self._project_name)
|
| 492 |
+
)
|
| 493 |
+
else:
|
| 494 |
+
allow_prereleases = None
|
| 495 |
+
specifier = self._specifier
|
| 496 |
+
|
| 497 |
+
# When using the pkg_resources backend we turn the version object into
|
| 498 |
+
# a str here because otherwise when we're debundled but setuptools isn't,
|
| 499 |
+
# Python will see packaging.version.Version and
|
| 500 |
+
# pkg_resources._vendor.packaging.version.Version as different
|
| 501 |
+
# types. This way we'll use a str as a common data interchange
|
| 502 |
+
# format. If we stop using the pkg_resources provided specifier
|
| 503 |
+
# and start using our own, we can drop the cast to str().
|
| 504 |
+
if select_backend().NAME == "pkg_resources":
|
| 505 |
+
candidates_and_versions: list[
|
| 506 |
+
tuple[InstallationCandidate, str | Version]
|
| 507 |
+
] = [(c, str(c.version)) for c in candidates]
|
| 508 |
+
else:
|
| 509 |
+
candidates_and_versions = [(c, c.version) for c in candidates]
|
| 510 |
+
versions = set(
|
| 511 |
+
specifier.filter(
|
| 512 |
+
(v for _, v in candidates_and_versions),
|
| 513 |
+
prereleases=allow_prereleases,
|
| 514 |
+
)
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
+
applicable_candidates = [c for c, v in candidates_and_versions if v in versions]
|
| 518 |
+
filtered_applicable_candidates = filter_unallowed_hashes(
|
| 519 |
+
candidates=applicable_candidates,
|
| 520 |
+
hashes=self._hashes,
|
| 521 |
+
project_name=self._project_name,
|
| 522 |
+
)
|
| 523 |
+
|
| 524 |
+
return sorted(filtered_applicable_candidates, key=self._sort_key)
|
| 525 |
+
|
| 526 |
+
def _sort_key(self, candidate: InstallationCandidate) -> CandidateSortingKey:
|
| 527 |
+
"""
|
| 528 |
+
Function to pass as the `key` argument to a call to sorted() to sort
|
| 529 |
+
InstallationCandidates by preference.
|
| 530 |
+
|
| 531 |
+
Returns a tuple such that tuples sorting as greater using Python's
|
| 532 |
+
default comparison operator are more preferred.
|
| 533 |
+
|
| 534 |
+
The preference is as follows:
|
| 535 |
+
|
| 536 |
+
First and foremost, candidates with allowed (matching) hashes are
|
| 537 |
+
always preferred over candidates without matching hashes. This is
|
| 538 |
+
because e.g. if the only candidate with an allowed hash is yanked,
|
| 539 |
+
we still want to use that candidate.
|
| 540 |
+
|
| 541 |
+
Second, excepting hash considerations, candidates that have been
|
| 542 |
+
yanked (in the sense of PEP 592) are always less preferred than
|
| 543 |
+
candidates that haven't been yanked. Then:
|
| 544 |
+
|
| 545 |
+
If not finding wheels, they are sorted by version only.
|
| 546 |
+
If finding wheels, then the sort order is by version, then:
|
| 547 |
+
1. existing installs
|
| 548 |
+
2. wheels ordered via Wheel.support_index_min(self._supported_tags)
|
| 549 |
+
3. source archives
|
| 550 |
+
If prefer_binary was set, then all wheels are sorted above sources.
|
| 551 |
+
|
| 552 |
+
Note: it was considered to embed this logic into the Link
|
| 553 |
+
comparison operators, but then different sdist links
|
| 554 |
+
with the same version, would have to be considered equal
|
| 555 |
+
"""
|
| 556 |
+
valid_tags = self._supported_tags
|
| 557 |
+
support_num = len(valid_tags)
|
| 558 |
+
build_tag: BuildTag = ()
|
| 559 |
+
binary_preference = 0
|
| 560 |
+
link = candidate.link
|
| 561 |
+
if link.is_wheel:
|
| 562 |
+
# can raise InvalidWheelFilename
|
| 563 |
+
wheel = Wheel(link.filename)
|
| 564 |
+
try:
|
| 565 |
+
pri = -(
|
| 566 |
+
wheel.find_most_preferred_tag(
|
| 567 |
+
valid_tags, self._wheel_tag_preferences
|
| 568 |
+
)
|
| 569 |
+
)
|
| 570 |
+
except ValueError:
|
| 571 |
+
raise UnsupportedWheel(
|
| 572 |
+
f"{wheel.filename} is not a supported wheel for this platform. It "
|
| 573 |
+
"can't be sorted."
|
| 574 |
+
)
|
| 575 |
+
if self._prefer_binary:
|
| 576 |
+
binary_preference = 1
|
| 577 |
+
build_tag = wheel.build_tag
|
| 578 |
+
else: # sdist
|
| 579 |
+
pri = -(support_num)
|
| 580 |
+
has_allowed_hash = int(link.is_hash_allowed(self._hashes))
|
| 581 |
+
yank_value = -1 * int(link.is_yanked) # -1 for yanked.
|
| 582 |
+
return (
|
| 583 |
+
has_allowed_hash,
|
| 584 |
+
yank_value,
|
| 585 |
+
binary_preference,
|
| 586 |
+
candidate.version,
|
| 587 |
+
pri,
|
| 588 |
+
build_tag,
|
| 589 |
+
)
|
| 590 |
+
|
| 591 |
+
def sort_best_candidate(
|
| 592 |
+
self,
|
| 593 |
+
candidates: list[InstallationCandidate],
|
| 594 |
+
) -> InstallationCandidate | None:
|
| 595 |
+
"""
|
| 596 |
+
Return the best candidate per the instance's sort order, or None if
|
| 597 |
+
no candidate is acceptable.
|
| 598 |
+
"""
|
| 599 |
+
if not candidates:
|
| 600 |
+
return None
|
| 601 |
+
best_candidate = max(candidates, key=self._sort_key)
|
| 602 |
+
return best_candidate
|
| 603 |
+
|
| 604 |
+
def compute_best_candidate(
|
| 605 |
+
self,
|
| 606 |
+
candidates: list[InstallationCandidate],
|
| 607 |
+
) -> BestCandidateResult:
|
| 608 |
+
"""
|
| 609 |
+
Compute and return a `BestCandidateResult` instance.
|
| 610 |
+
"""
|
| 611 |
+
applicable_candidates = self.get_applicable_candidates(candidates)
|
| 612 |
+
|
| 613 |
+
best_candidate = self.sort_best_candidate(applicable_candidates)
|
| 614 |
+
|
| 615 |
+
return BestCandidateResult(
|
| 616 |
+
candidates,
|
| 617 |
+
applicable_candidates=applicable_candidates,
|
| 618 |
+
best_candidate=best_candidate,
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
|
| 622 |
+
class PackageFinder:
|
| 623 |
+
"""This finds packages.
|
| 624 |
+
|
| 625 |
+
This is meant to match easy_install's technique for looking for
|
| 626 |
+
packages, by reading pages and looking for appropriate links.
|
| 627 |
+
"""
|
| 628 |
+
|
| 629 |
+
def __init__(
|
| 630 |
+
self,
|
| 631 |
+
link_collector: LinkCollector,
|
| 632 |
+
target_python: TargetPython,
|
| 633 |
+
allow_yanked: bool,
|
| 634 |
+
format_control: FormatControl | None = None,
|
| 635 |
+
candidate_prefs: CandidatePreferences | None = None,
|
| 636 |
+
ignore_requires_python: bool | None = None,
|
| 637 |
+
uploaded_prior_to: datetime.datetime | None = None,
|
| 638 |
+
) -> None:
|
| 639 |
+
"""
|
| 640 |
+
This constructor is primarily meant to be used by the create() class
|
| 641 |
+
method and from tests.
|
| 642 |
+
|
| 643 |
+
:param format_control: A FormatControl object, used to control
|
| 644 |
+
the selection of source packages / binary packages when consulting
|
| 645 |
+
the index and links.
|
| 646 |
+
:param candidate_prefs: Options to use when creating a
|
| 647 |
+
CandidateEvaluator object.
|
| 648 |
+
"""
|
| 649 |
+
if candidate_prefs is None:
|
| 650 |
+
candidate_prefs = CandidatePreferences()
|
| 651 |
+
|
| 652 |
+
format_control = format_control or FormatControl(set(), set())
|
| 653 |
+
|
| 654 |
+
self._allow_yanked = allow_yanked
|
| 655 |
+
self._candidate_prefs = candidate_prefs
|
| 656 |
+
self._ignore_requires_python = ignore_requires_python
|
| 657 |
+
self._link_collector = link_collector
|
| 658 |
+
self._target_python = target_python
|
| 659 |
+
self._uploaded_prior_to = uploaded_prior_to
|
| 660 |
+
|
| 661 |
+
self.format_control = format_control
|
| 662 |
+
|
| 663 |
+
# These are boring links that have already been logged somehow.
|
| 664 |
+
self._logged_links: set[tuple[Link, LinkType, str]] = set()
|
| 665 |
+
|
| 666 |
+
# Cache of the result of finding candidates
|
| 667 |
+
self._all_candidates: dict[str, list[InstallationCandidate]] = {}
|
| 668 |
+
self._best_candidates: dict[
|
| 669 |
+
tuple[str, specifiers.BaseSpecifier | None, Hashes | None],
|
| 670 |
+
BestCandidateResult,
|
| 671 |
+
] = {}
|
| 672 |
+
|
| 673 |
+
# Don't include an allow_yanked default value to make sure each call
|
| 674 |
+
# site considers whether yanked releases are allowed. This also causes
|
| 675 |
+
# that decision to be made explicit in the calling code, which helps
|
| 676 |
+
# people when reading the code.
|
| 677 |
+
@classmethod
|
| 678 |
+
def create(
|
| 679 |
+
cls,
|
| 680 |
+
link_collector: LinkCollector,
|
| 681 |
+
selection_prefs: SelectionPreferences,
|
| 682 |
+
target_python: TargetPython | None = None,
|
| 683 |
+
uploaded_prior_to: datetime.datetime | None = None,
|
| 684 |
+
) -> PackageFinder:
|
| 685 |
+
"""Create a PackageFinder.
|
| 686 |
+
|
| 687 |
+
:param selection_prefs: The candidate selection preferences, as a
|
| 688 |
+
SelectionPreferences object.
|
| 689 |
+
:param target_python: The target Python interpreter to use when
|
| 690 |
+
checking compatibility. If None (the default), a TargetPython
|
| 691 |
+
object will be constructed from the running Python.
|
| 692 |
+
:param uploaded_prior_to: If set, only find links uploaded prior
|
| 693 |
+
to the given datetime.
|
| 694 |
+
"""
|
| 695 |
+
if target_python is None:
|
| 696 |
+
target_python = TargetPython()
|
| 697 |
+
|
| 698 |
+
candidate_prefs = CandidatePreferences(
|
| 699 |
+
prefer_binary=selection_prefs.prefer_binary,
|
| 700 |
+
release_control=selection_prefs.release_control,
|
| 701 |
+
)
|
| 702 |
+
|
| 703 |
+
return cls(
|
| 704 |
+
candidate_prefs=candidate_prefs,
|
| 705 |
+
link_collector=link_collector,
|
| 706 |
+
target_python=target_python,
|
| 707 |
+
allow_yanked=selection_prefs.allow_yanked,
|
| 708 |
+
format_control=selection_prefs.format_control,
|
| 709 |
+
ignore_requires_python=selection_prefs.ignore_requires_python,
|
| 710 |
+
uploaded_prior_to=uploaded_prior_to,
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
@property
|
| 714 |
+
def target_python(self) -> TargetPython:
|
| 715 |
+
return self._target_python
|
| 716 |
+
|
| 717 |
+
@property
|
| 718 |
+
def search_scope(self) -> SearchScope:
|
| 719 |
+
return self._link_collector.search_scope
|
| 720 |
+
|
| 721 |
+
@search_scope.setter
|
| 722 |
+
def search_scope(self, search_scope: SearchScope) -> None:
|
| 723 |
+
self._link_collector.search_scope = search_scope
|
| 724 |
+
|
| 725 |
+
@property
|
| 726 |
+
def find_links(self) -> list[str]:
|
| 727 |
+
return self._link_collector.find_links
|
| 728 |
+
|
| 729 |
+
@property
|
| 730 |
+
def index_urls(self) -> list[str]:
|
| 731 |
+
return self.search_scope.index_urls
|
| 732 |
+
|
| 733 |
+
@property
|
| 734 |
+
def proxy(self) -> str | None:
|
| 735 |
+
return self._link_collector.session.pip_proxy
|
| 736 |
+
|
| 737 |
+
@property
|
| 738 |
+
def trusted_hosts(self) -> Iterable[str]:
|
| 739 |
+
for host_port in self._link_collector.session.pip_trusted_origins:
|
| 740 |
+
yield build_netloc(*host_port)
|
| 741 |
+
|
| 742 |
+
@property
|
| 743 |
+
def custom_cert(self) -> str | None:
|
| 744 |
+
# session.verify is either a boolean (use default bundle/no SSL
|
| 745 |
+
# verification) or a string path to a custom CA bundle to use. We only
|
| 746 |
+
# care about the latter.
|
| 747 |
+
verify = self._link_collector.session.verify
|
| 748 |
+
return verify if isinstance(verify, str) else None
|
| 749 |
+
|
| 750 |
+
@property
|
| 751 |
+
def client_cert(self) -> str | None:
|
| 752 |
+
cert = self._link_collector.session.cert
|
| 753 |
+
assert not isinstance(cert, tuple), "pip only supports PEM client certs"
|
| 754 |
+
return cert
|
| 755 |
+
|
| 756 |
+
@property
|
| 757 |
+
def release_control(self) -> ReleaseControl | None:
|
| 758 |
+
return self._candidate_prefs.release_control
|
| 759 |
+
|
| 760 |
+
def set_release_control(self, release_control: ReleaseControl) -> None:
|
| 761 |
+
self._candidate_prefs.release_control = release_control
|
| 762 |
+
|
| 763 |
+
@property
|
| 764 |
+
def prefer_binary(self) -> bool:
|
| 765 |
+
return self._candidate_prefs.prefer_binary
|
| 766 |
+
|
| 767 |
+
def set_prefer_binary(self) -> None:
|
| 768 |
+
self._candidate_prefs.prefer_binary = True
|
| 769 |
+
|
| 770 |
+
@property
|
| 771 |
+
def uploaded_prior_to(self) -> datetime.datetime | None:
|
| 772 |
+
return self._uploaded_prior_to
|
| 773 |
+
|
| 774 |
+
def requires_python_skipped_reasons(self) -> list[str]:
|
| 775 |
+
reasons = {
|
| 776 |
+
detail
|
| 777 |
+
for _, result, detail in self._logged_links
|
| 778 |
+
if result == LinkType.requires_python_mismatch
|
| 779 |
+
}
|
| 780 |
+
return sorted(reasons)
|
| 781 |
+
|
| 782 |
+
def make_link_evaluator(self, project_name: str) -> LinkEvaluator:
|
| 783 |
+
canonical_name = canonicalize_name(project_name)
|
| 784 |
+
formats = self.format_control.get_allowed_formats(canonical_name)
|
| 785 |
+
|
| 786 |
+
return LinkEvaluator(
|
| 787 |
+
project_name=project_name,
|
| 788 |
+
canonical_name=canonical_name,
|
| 789 |
+
formats=formats,
|
| 790 |
+
target_python=self._target_python,
|
| 791 |
+
allow_yanked=self._allow_yanked,
|
| 792 |
+
ignore_requires_python=self._ignore_requires_python,
|
| 793 |
+
uploaded_prior_to=self._uploaded_prior_to,
|
| 794 |
+
)
|
| 795 |
+
|
| 796 |
+
def _sort_links(self, links: Iterable[Link]) -> list[Link]:
|
| 797 |
+
"""
|
| 798 |
+
Returns elements of links in order, non-egg links first, egg links
|
| 799 |
+
second, while eliminating duplicates
|
| 800 |
+
"""
|
| 801 |
+
eggs, no_eggs = [], []
|
| 802 |
+
seen: set[Link] = set()
|
| 803 |
+
for link in links:
|
| 804 |
+
if link not in seen:
|
| 805 |
+
seen.add(link)
|
| 806 |
+
if link.egg_fragment:
|
| 807 |
+
eggs.append(link)
|
| 808 |
+
else:
|
| 809 |
+
no_eggs.append(link)
|
| 810 |
+
return no_eggs + eggs
|
| 811 |
+
|
| 812 |
+
def _log_skipped_link(self, link: Link, result: LinkType, detail: str) -> None:
|
| 813 |
+
entry = (link, result, detail)
|
| 814 |
+
if entry not in self._logged_links:
|
| 815 |
+
# Put the link at the end so the reason is more visible and because
|
| 816 |
+
# the link string is usually very long.
|
| 817 |
+
logger.debug("Skipping link: %s: %s", detail, link)
|
| 818 |
+
self._logged_links.add(entry)
|
| 819 |
+
|
| 820 |
+
def get_install_candidate(
|
| 821 |
+
self, link_evaluator: LinkEvaluator, link: Link
|
| 822 |
+
) -> InstallationCandidate | None:
|
| 823 |
+
"""
|
| 824 |
+
If the link is a candidate for install, convert it to an
|
| 825 |
+
InstallationCandidate and return it. Otherwise, return None.
|
| 826 |
+
"""
|
| 827 |
+
result, detail = link_evaluator.evaluate_link(link)
|
| 828 |
+
if result == LinkType.upload_time_missing:
|
| 829 |
+
# Fail immediately if the index doesn't provide upload-time
|
| 830 |
+
# when --uploaded-prior-to is specified
|
| 831 |
+
raise InstallationError(detail)
|
| 832 |
+
if result != LinkType.candidate:
|
| 833 |
+
self._log_skipped_link(link, result, detail)
|
| 834 |
+
return None
|
| 835 |
+
|
| 836 |
+
try:
|
| 837 |
+
return InstallationCandidate(
|
| 838 |
+
name=link_evaluator.project_name,
|
| 839 |
+
link=link,
|
| 840 |
+
version=detail,
|
| 841 |
+
)
|
| 842 |
+
except InvalidVersion:
|
| 843 |
+
return None
|
| 844 |
+
|
| 845 |
+
def evaluate_links(
|
| 846 |
+
self, link_evaluator: LinkEvaluator, links: Iterable[Link]
|
| 847 |
+
) -> list[InstallationCandidate]:
|
| 848 |
+
"""
|
| 849 |
+
Convert links that are candidates to InstallationCandidate objects.
|
| 850 |
+
"""
|
| 851 |
+
candidates = []
|
| 852 |
+
for link in self._sort_links(links):
|
| 853 |
+
candidate = self.get_install_candidate(link_evaluator, link)
|
| 854 |
+
if candidate is not None:
|
| 855 |
+
candidates.append(candidate)
|
| 856 |
+
|
| 857 |
+
return candidates
|
| 858 |
+
|
| 859 |
+
def process_project_url(
|
| 860 |
+
self, project_url: Link, link_evaluator: LinkEvaluator
|
| 861 |
+
) -> list[InstallationCandidate]:
|
| 862 |
+
logger.debug(
|
| 863 |
+
"Fetching project page and analyzing links: %s",
|
| 864 |
+
project_url,
|
| 865 |
+
)
|
| 866 |
+
index_response = self._link_collector.fetch_response(project_url)
|
| 867 |
+
if index_response is None:
|
| 868 |
+
return []
|
| 869 |
+
|
| 870 |
+
page_links = list(parse_links(index_response))
|
| 871 |
+
|
| 872 |
+
with indent_log():
|
| 873 |
+
package_links = self.evaluate_links(
|
| 874 |
+
link_evaluator,
|
| 875 |
+
links=page_links,
|
| 876 |
+
)
|
| 877 |
+
|
| 878 |
+
return package_links
|
| 879 |
+
|
| 880 |
+
def find_all_candidates(self, project_name: str) -> list[InstallationCandidate]:
|
| 881 |
+
"""Find all available InstallationCandidate for project_name
|
| 882 |
+
|
| 883 |
+
This checks index_urls and find_links.
|
| 884 |
+
All versions found are returned as an InstallationCandidate list.
|
| 885 |
+
|
| 886 |
+
See LinkEvaluator.evaluate_link() for details on which files
|
| 887 |
+
are accepted.
|
| 888 |
+
"""
|
| 889 |
+
if project_name in self._all_candidates:
|
| 890 |
+
return self._all_candidates[project_name]
|
| 891 |
+
|
| 892 |
+
link_evaluator = self.make_link_evaluator(project_name)
|
| 893 |
+
|
| 894 |
+
collected_sources = self._link_collector.collect_sources(
|
| 895 |
+
project_name=project_name,
|
| 896 |
+
candidates_from_page=functools.partial(
|
| 897 |
+
self.process_project_url,
|
| 898 |
+
link_evaluator=link_evaluator,
|
| 899 |
+
),
|
| 900 |
+
)
|
| 901 |
+
|
| 902 |
+
page_candidates_it = itertools.chain.from_iterable(
|
| 903 |
+
source.page_candidates()
|
| 904 |
+
for sources in collected_sources
|
| 905 |
+
for source in sources
|
| 906 |
+
if source is not None
|
| 907 |
+
)
|
| 908 |
+
page_candidates = list(page_candidates_it)
|
| 909 |
+
|
| 910 |
+
file_links_it = itertools.chain.from_iterable(
|
| 911 |
+
source.file_links()
|
| 912 |
+
for sources in collected_sources
|
| 913 |
+
for source in sources
|
| 914 |
+
if source is not None
|
| 915 |
+
)
|
| 916 |
+
file_candidates = self.evaluate_links(
|
| 917 |
+
link_evaluator,
|
| 918 |
+
sorted(file_links_it, reverse=True),
|
| 919 |
+
)
|
| 920 |
+
|
| 921 |
+
if logger.isEnabledFor(logging.DEBUG) and file_candidates:
|
| 922 |
+
paths = []
|
| 923 |
+
for candidate in file_candidates:
|
| 924 |
+
assert candidate.link.url # we need to have a URL
|
| 925 |
+
try:
|
| 926 |
+
paths.append(candidate.link.file_path)
|
| 927 |
+
except Exception:
|
| 928 |
+
paths.append(candidate.link.url) # it's not a local file
|
| 929 |
+
|
| 930 |
+
logger.debug("Local files found: %s", ", ".join(paths))
|
| 931 |
+
|
| 932 |
+
# This is an intentional priority ordering
|
| 933 |
+
self._all_candidates[project_name] = file_candidates + page_candidates
|
| 934 |
+
|
| 935 |
+
return self._all_candidates[project_name]
|
| 936 |
+
|
| 937 |
+
def make_candidate_evaluator(
|
| 938 |
+
self,
|
| 939 |
+
project_name: str,
|
| 940 |
+
specifier: specifiers.BaseSpecifier | None = None,
|
| 941 |
+
hashes: Hashes | None = None,
|
| 942 |
+
) -> CandidateEvaluator:
|
| 943 |
+
"""Create a CandidateEvaluator object to use."""
|
| 944 |
+
candidate_prefs = self._candidate_prefs
|
| 945 |
+
return CandidateEvaluator.create(
|
| 946 |
+
project_name=project_name,
|
| 947 |
+
target_python=self._target_python,
|
| 948 |
+
prefer_binary=candidate_prefs.prefer_binary,
|
| 949 |
+
release_control=candidate_prefs.release_control,
|
| 950 |
+
specifier=specifier,
|
| 951 |
+
hashes=hashes,
|
| 952 |
+
)
|
| 953 |
+
|
| 954 |
+
def find_best_candidate(
|
| 955 |
+
self,
|
| 956 |
+
project_name: str,
|
| 957 |
+
specifier: specifiers.BaseSpecifier | None = None,
|
| 958 |
+
hashes: Hashes | None = None,
|
| 959 |
+
) -> BestCandidateResult:
|
| 960 |
+
"""Find matches for the given project and specifier.
|
| 961 |
+
|
| 962 |
+
:param specifier: An optional object implementing `filter`
|
| 963 |
+
(e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
|
| 964 |
+
versions.
|
| 965 |
+
|
| 966 |
+
:return: A `BestCandidateResult` instance.
|
| 967 |
+
"""
|
| 968 |
+
if (project_name, specifier, hashes) in self._best_candidates:
|
| 969 |
+
return self._best_candidates[project_name, specifier, hashes]
|
| 970 |
+
|
| 971 |
+
candidates = self.find_all_candidates(project_name)
|
| 972 |
+
candidate_evaluator = self.make_candidate_evaluator(
|
| 973 |
+
project_name=project_name,
|
| 974 |
+
specifier=specifier,
|
| 975 |
+
hashes=hashes,
|
| 976 |
+
)
|
| 977 |
+
self._best_candidates[project_name, specifier, hashes] = (
|
| 978 |
+
candidate_evaluator.compute_best_candidate(candidates)
|
| 979 |
+
)
|
| 980 |
+
|
| 981 |
+
return self._best_candidates[project_name, specifier, hashes]
|
| 982 |
+
|
| 983 |
+
def find_requirement(
|
| 984 |
+
self, req: InstallRequirement, upgrade: bool
|
| 985 |
+
) -> InstallationCandidate | None:
|
| 986 |
+
"""Try to find a Link matching req
|
| 987 |
+
|
| 988 |
+
Expects req, an InstallRequirement and upgrade, a boolean
|
| 989 |
+
Returns a InstallationCandidate if found,
|
| 990 |
+
Raises DistributionNotFound or BestVersionAlreadyInstalled otherwise
|
| 991 |
+
"""
|
| 992 |
+
name = req.name
|
| 993 |
+
assert name is not None, "find_requirement() called with no name"
|
| 994 |
+
|
| 995 |
+
hashes = req.hashes(trust_internet=False)
|
| 996 |
+
best_candidate_result = self.find_best_candidate(
|
| 997 |
+
name,
|
| 998 |
+
specifier=req.specifier,
|
| 999 |
+
hashes=hashes,
|
| 1000 |
+
)
|
| 1001 |
+
best_candidate = best_candidate_result.best_candidate
|
| 1002 |
+
|
| 1003 |
+
installed_version: _BaseVersion | None = None
|
| 1004 |
+
if req.satisfied_by is not None:
|
| 1005 |
+
installed_version = req.satisfied_by.version
|
| 1006 |
+
|
| 1007 |
+
def _format_versions(cand_iter: Iterable[InstallationCandidate]) -> str:
|
| 1008 |
+
# This repeated parse_version and str() conversion is needed to
|
| 1009 |
+
# handle different vendoring sources from pip and pkg_resources.
|
| 1010 |
+
# If we stop using the pkg_resources provided specifier and start
|
| 1011 |
+
# using our own, we can drop the cast to str().
|
| 1012 |
+
return (
|
| 1013 |
+
", ".join(
|
| 1014 |
+
sorted(
|
| 1015 |
+
{str(c.version) for c in cand_iter},
|
| 1016 |
+
key=parse_version,
|
| 1017 |
+
)
|
| 1018 |
+
)
|
| 1019 |
+
or "none"
|
| 1020 |
+
)
|
| 1021 |
+
|
| 1022 |
+
if installed_version is None and best_candidate is None:
|
| 1023 |
+
# Check if only final releases are allowed for this package
|
| 1024 |
+
version_type = "version"
|
| 1025 |
+
if self.release_control is not None:
|
| 1026 |
+
allows_pre = self.release_control.allows_prereleases(
|
| 1027 |
+
canonicalize_name(name)
|
| 1028 |
+
)
|
| 1029 |
+
if allows_pre is False:
|
| 1030 |
+
version_type = "final version"
|
| 1031 |
+
|
| 1032 |
+
logger.critical(
|
| 1033 |
+
"Could not find a %s that satisfies the requirement %s "
|
| 1034 |
+
"(from versions: %s)",
|
| 1035 |
+
version_type,
|
| 1036 |
+
req,
|
| 1037 |
+
_format_versions(best_candidate_result.all_candidates),
|
| 1038 |
+
)
|
| 1039 |
+
|
| 1040 |
+
raise DistributionNotFound(f"No matching distribution found for {req}")
|
| 1041 |
+
|
| 1042 |
+
def _should_install_candidate(
|
| 1043 |
+
candidate: InstallationCandidate | None,
|
| 1044 |
+
) -> TypeGuard[InstallationCandidate]:
|
| 1045 |
+
if installed_version is None:
|
| 1046 |
+
return True
|
| 1047 |
+
if best_candidate is None:
|
| 1048 |
+
return False
|
| 1049 |
+
return best_candidate.version > installed_version
|
| 1050 |
+
|
| 1051 |
+
if not upgrade and installed_version is not None:
|
| 1052 |
+
if _should_install_candidate(best_candidate):
|
| 1053 |
+
logger.debug(
|
| 1054 |
+
"Existing installed version (%s) satisfies requirement "
|
| 1055 |
+
"(most up-to-date version is %s)",
|
| 1056 |
+
installed_version,
|
| 1057 |
+
best_candidate.version,
|
| 1058 |
+
)
|
| 1059 |
+
else:
|
| 1060 |
+
logger.debug(
|
| 1061 |
+
"Existing installed version (%s) is most up-to-date and "
|
| 1062 |
+
"satisfies requirement",
|
| 1063 |
+
installed_version,
|
| 1064 |
+
)
|
| 1065 |
+
return None
|
| 1066 |
+
|
| 1067 |
+
if _should_install_candidate(best_candidate):
|
| 1068 |
+
logger.debug(
|
| 1069 |
+
"Using version %s (newest of versions: %s)",
|
| 1070 |
+
best_candidate.version,
|
| 1071 |
+
_format_versions(best_candidate_result.applicable_candidates),
|
| 1072 |
+
)
|
| 1073 |
+
return best_candidate
|
| 1074 |
+
|
| 1075 |
+
# We have an existing version, and its the best version
|
| 1076 |
+
logger.debug(
|
| 1077 |
+
"Installed version (%s) is most up-to-date (past versions: %s)",
|
| 1078 |
+
installed_version,
|
| 1079 |
+
_format_versions(best_candidate_result.applicable_candidates),
|
| 1080 |
+
)
|
| 1081 |
+
raise BestVersionAlreadyInstalled
|
| 1082 |
+
|
| 1083 |
+
|
| 1084 |
+
def _find_name_version_sep(fragment: str, canonical_name: str) -> int:
|
| 1085 |
+
"""Find the separator's index based on the package's canonical name.
|
| 1086 |
+
|
| 1087 |
+
:param fragment: A <package>+<version> filename "fragment" (stem) or
|
| 1088 |
+
egg fragment.
|
| 1089 |
+
:param canonical_name: The package's canonical name.
|
| 1090 |
+
|
| 1091 |
+
This function is needed since the canonicalized name does not necessarily
|
| 1092 |
+
have the same length as the egg info's name part. An example::
|
| 1093 |
+
|
| 1094 |
+
>>> fragment = 'foo__bar-1.0'
|
| 1095 |
+
>>> canonical_name = 'foo-bar'
|
| 1096 |
+
>>> _find_name_version_sep(fragment, canonical_name)
|
| 1097 |
+
8
|
| 1098 |
+
"""
|
| 1099 |
+
# Project name and version must be separated by one single dash. Find all
|
| 1100 |
+
# occurrences of dashes; if the string in front of it matches the canonical
|
| 1101 |
+
# name, this is the one separating the name and version parts.
|
| 1102 |
+
for i, c in enumerate(fragment):
|
| 1103 |
+
if c != "-":
|
| 1104 |
+
continue
|
| 1105 |
+
if canonicalize_name(fragment[:i]) == canonical_name:
|
| 1106 |
+
return i
|
| 1107 |
+
raise ValueError(f"{fragment} does not match {canonical_name}")
|
| 1108 |
+
|
| 1109 |
+
|
| 1110 |
+
def _extract_version_from_fragment(fragment: str, canonical_name: str) -> str | None:
|
| 1111 |
+
"""Parse the version string from a <package>+<version> filename
|
| 1112 |
+
"fragment" (stem) or egg fragment.
|
| 1113 |
+
|
| 1114 |
+
:param fragment: The string to parse. E.g. foo-2.1
|
| 1115 |
+
:param canonical_name: The canonicalized name of the package this
|
| 1116 |
+
belongs to.
|
| 1117 |
+
"""
|
| 1118 |
+
try:
|
| 1119 |
+
version_start = _find_name_version_sep(fragment, canonical_name) + 1
|
| 1120 |
+
except ValueError:
|
| 1121 |
+
return None
|
| 1122 |
+
version = fragment[version_start:]
|
| 1123 |
+
if not version:
|
| 1124 |
+
return None
|
| 1125 |
+
return version
|
.venv/lib/python3.12/site-packages/pip/_internal/index/sources.py
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 3 |
+
import logging
|
| 4 |
+
import mimetypes
|
| 5 |
+
import os
|
| 6 |
+
from collections import defaultdict
|
| 7 |
+
from collections.abc import Iterable
|
| 8 |
+
from typing import Callable
|
| 9 |
+
|
| 10 |
+
from pip._vendor.packaging.utils import (
|
| 11 |
+
InvalidSdistFilename,
|
| 12 |
+
InvalidWheelFilename,
|
| 13 |
+
canonicalize_name,
|
| 14 |
+
parse_sdist_filename,
|
| 15 |
+
parse_wheel_filename,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
from pip._internal.models.candidate import InstallationCandidate
|
| 19 |
+
from pip._internal.models.link import Link
|
| 20 |
+
from pip._internal.utils.urls import path_to_url, url_to_path
|
| 21 |
+
from pip._internal.vcs import is_url
|
| 22 |
+
|
| 23 |
+
logger = logging.getLogger(__name__)
|
| 24 |
+
|
| 25 |
+
FoundCandidates = Iterable[InstallationCandidate]
|
| 26 |
+
FoundLinks = Iterable[Link]
|
| 27 |
+
CandidatesFromPage = Callable[[Link], Iterable[InstallationCandidate]]
|
| 28 |
+
PageValidator = Callable[[Link], bool]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class LinkSource:
|
| 32 |
+
@property
|
| 33 |
+
def link(self) -> Link | None:
|
| 34 |
+
"""Returns the underlying link, if there's one."""
|
| 35 |
+
raise NotImplementedError()
|
| 36 |
+
|
| 37 |
+
def page_candidates(self) -> FoundCandidates:
|
| 38 |
+
"""Candidates found by parsing an archive listing HTML file."""
|
| 39 |
+
raise NotImplementedError()
|
| 40 |
+
|
| 41 |
+
def file_links(self) -> FoundLinks:
|
| 42 |
+
"""Links found by specifying archives directly."""
|
| 43 |
+
raise NotImplementedError()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _is_html_file(file_url: str) -> bool:
|
| 47 |
+
return mimetypes.guess_type(file_url, strict=False)[0] == "text/html"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class _FlatDirectoryToUrls:
|
| 51 |
+
"""Scans directory and caches results"""
|
| 52 |
+
|
| 53 |
+
def __init__(self, path: str) -> None:
|
| 54 |
+
self._path = path
|
| 55 |
+
self._page_candidates: list[str] = []
|
| 56 |
+
self._project_name_to_urls: dict[str, list[str]] = defaultdict(list)
|
| 57 |
+
self._scanned_directory = False
|
| 58 |
+
|
| 59 |
+
def _scan_directory(self) -> None:
|
| 60 |
+
"""Scans directory once and populates both page_candidates
|
| 61 |
+
and project_name_to_urls at the same time
|
| 62 |
+
"""
|
| 63 |
+
for entry in os.scandir(self._path):
|
| 64 |
+
url = path_to_url(entry.path)
|
| 65 |
+
if _is_html_file(url):
|
| 66 |
+
self._page_candidates.append(url)
|
| 67 |
+
continue
|
| 68 |
+
|
| 69 |
+
# File must have a valid wheel or sdist name,
|
| 70 |
+
# otherwise not worth considering as a package
|
| 71 |
+
try:
|
| 72 |
+
project_filename = parse_wheel_filename(entry.name)[0]
|
| 73 |
+
except InvalidWheelFilename:
|
| 74 |
+
try:
|
| 75 |
+
project_filename = parse_sdist_filename(entry.name)[0]
|
| 76 |
+
except InvalidSdistFilename:
|
| 77 |
+
continue
|
| 78 |
+
|
| 79 |
+
self._project_name_to_urls[project_filename].append(url)
|
| 80 |
+
self._scanned_directory = True
|
| 81 |
+
|
| 82 |
+
@property
|
| 83 |
+
def page_candidates(self) -> list[str]:
|
| 84 |
+
if not self._scanned_directory:
|
| 85 |
+
self._scan_directory()
|
| 86 |
+
|
| 87 |
+
return self._page_candidates
|
| 88 |
+
|
| 89 |
+
@property
|
| 90 |
+
def project_name_to_urls(self) -> dict[str, list[str]]:
|
| 91 |
+
if not self._scanned_directory:
|
| 92 |
+
self._scan_directory()
|
| 93 |
+
|
| 94 |
+
return self._project_name_to_urls
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class _FlatDirectorySource(LinkSource):
|
| 98 |
+
"""Link source specified by ``--find-links=<path-to-dir>``.
|
| 99 |
+
|
| 100 |
+
This looks the content of the directory, and returns:
|
| 101 |
+
|
| 102 |
+
* ``page_candidates``: Links listed on each HTML file in the directory.
|
| 103 |
+
* ``file_candidates``: Archives in the directory.
|
| 104 |
+
"""
|
| 105 |
+
|
| 106 |
+
_paths_to_urls: dict[str, _FlatDirectoryToUrls] = {}
|
| 107 |
+
|
| 108 |
+
def __init__(
|
| 109 |
+
self,
|
| 110 |
+
candidates_from_page: CandidatesFromPage,
|
| 111 |
+
path: str,
|
| 112 |
+
project_name: str,
|
| 113 |
+
) -> None:
|
| 114 |
+
self._candidates_from_page = candidates_from_page
|
| 115 |
+
self._project_name = canonicalize_name(project_name)
|
| 116 |
+
|
| 117 |
+
# Get existing instance of _FlatDirectoryToUrls if it exists
|
| 118 |
+
if path in self._paths_to_urls:
|
| 119 |
+
self._path_to_urls = self._paths_to_urls[path]
|
| 120 |
+
else:
|
| 121 |
+
self._path_to_urls = _FlatDirectoryToUrls(path=path)
|
| 122 |
+
self._paths_to_urls[path] = self._path_to_urls
|
| 123 |
+
|
| 124 |
+
@property
|
| 125 |
+
def link(self) -> Link | None:
|
| 126 |
+
return None
|
| 127 |
+
|
| 128 |
+
def page_candidates(self) -> FoundCandidates:
|
| 129 |
+
for url in self._path_to_urls.page_candidates:
|
| 130 |
+
yield from self._candidates_from_page(Link(url))
|
| 131 |
+
|
| 132 |
+
def file_links(self) -> FoundLinks:
|
| 133 |
+
for url in self._path_to_urls.project_name_to_urls[self._project_name]:
|
| 134 |
+
yield Link(url)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
class _LocalFileSource(LinkSource):
|
| 138 |
+
"""``--find-links=<path-or-url>`` or ``--[extra-]index-url=<path-or-url>``.
|
| 139 |
+
|
| 140 |
+
If a URL is supplied, it must be a ``file:`` URL. If a path is supplied to
|
| 141 |
+
the option, it is converted to a URL first. This returns:
|
| 142 |
+
|
| 143 |
+
* ``page_candidates``: Links listed on an HTML file.
|
| 144 |
+
* ``file_candidates``: The non-HTML file.
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
def __init__(
|
| 148 |
+
self,
|
| 149 |
+
candidates_from_page: CandidatesFromPage,
|
| 150 |
+
link: Link,
|
| 151 |
+
) -> None:
|
| 152 |
+
self._candidates_from_page = candidates_from_page
|
| 153 |
+
self._link = link
|
| 154 |
+
|
| 155 |
+
@property
|
| 156 |
+
def link(self) -> Link | None:
|
| 157 |
+
return self._link
|
| 158 |
+
|
| 159 |
+
def page_candidates(self) -> FoundCandidates:
|
| 160 |
+
if not _is_html_file(self._link.url):
|
| 161 |
+
return
|
| 162 |
+
yield from self._candidates_from_page(self._link)
|
| 163 |
+
|
| 164 |
+
def file_links(self) -> FoundLinks:
|
| 165 |
+
if _is_html_file(self._link.url):
|
| 166 |
+
return
|
| 167 |
+
yield self._link
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
class _RemoteFileSource(LinkSource):
|
| 171 |
+
"""``--find-links=<url>`` or ``--[extra-]index-url=<url>``.
|
| 172 |
+
|
| 173 |
+
This returns:
|
| 174 |
+
|
| 175 |
+
* ``page_candidates``: Links listed on an HTML file.
|
| 176 |
+
* ``file_candidates``: The non-HTML file.
|
| 177 |
+
"""
|
| 178 |
+
|
| 179 |
+
def __init__(
|
| 180 |
+
self,
|
| 181 |
+
candidates_from_page: CandidatesFromPage,
|
| 182 |
+
page_validator: PageValidator,
|
| 183 |
+
link: Link,
|
| 184 |
+
) -> None:
|
| 185 |
+
self._candidates_from_page = candidates_from_page
|
| 186 |
+
self._page_validator = page_validator
|
| 187 |
+
self._link = link
|
| 188 |
+
|
| 189 |
+
@property
|
| 190 |
+
def link(self) -> Link | None:
|
| 191 |
+
return self._link
|
| 192 |
+
|
| 193 |
+
def page_candidates(self) -> FoundCandidates:
|
| 194 |
+
if not self._page_validator(self._link):
|
| 195 |
+
return
|
| 196 |
+
yield from self._candidates_from_page(self._link)
|
| 197 |
+
|
| 198 |
+
def file_links(self) -> FoundLinks:
|
| 199 |
+
yield self._link
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
class _IndexDirectorySource(LinkSource):
|
| 203 |
+
"""``--[extra-]index-url=<path-to-directory>``.
|
| 204 |
+
|
| 205 |
+
This is treated like a remote URL; ``candidates_from_page`` contains logic
|
| 206 |
+
for this by appending ``index.html`` to the link.
|
| 207 |
+
"""
|
| 208 |
+
|
| 209 |
+
def __init__(
|
| 210 |
+
self,
|
| 211 |
+
candidates_from_page: CandidatesFromPage,
|
| 212 |
+
link: Link,
|
| 213 |
+
) -> None:
|
| 214 |
+
self._candidates_from_page = candidates_from_page
|
| 215 |
+
self._link = link
|
| 216 |
+
|
| 217 |
+
@property
|
| 218 |
+
def link(self) -> Link | None:
|
| 219 |
+
return self._link
|
| 220 |
+
|
| 221 |
+
def page_candidates(self) -> FoundCandidates:
|
| 222 |
+
yield from self._candidates_from_page(self._link)
|
| 223 |
+
|
| 224 |
+
def file_links(self) -> FoundLinks:
|
| 225 |
+
return ()
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def build_source(
|
| 229 |
+
location: str,
|
| 230 |
+
*,
|
| 231 |
+
candidates_from_page: CandidatesFromPage,
|
| 232 |
+
page_validator: PageValidator,
|
| 233 |
+
expand_dir: bool,
|
| 234 |
+
cache_link_parsing: bool,
|
| 235 |
+
project_name: str,
|
| 236 |
+
) -> tuple[str | None, LinkSource | None]:
|
| 237 |
+
path: str | None = None
|
| 238 |
+
url: str | None = None
|
| 239 |
+
if os.path.exists(location): # Is a local path.
|
| 240 |
+
url = path_to_url(location)
|
| 241 |
+
path = location
|
| 242 |
+
elif location.startswith("file:"): # A file: URL.
|
| 243 |
+
url = location
|
| 244 |
+
path = url_to_path(location)
|
| 245 |
+
elif is_url(location):
|
| 246 |
+
url = location
|
| 247 |
+
|
| 248 |
+
if url is None:
|
| 249 |
+
msg = (
|
| 250 |
+
"Location '%s' is ignored: "
|
| 251 |
+
"it is either a non-existing path or lacks a specific scheme."
|
| 252 |
+
)
|
| 253 |
+
logger.warning(msg, location)
|
| 254 |
+
return (None, None)
|
| 255 |
+
|
| 256 |
+
if path is None:
|
| 257 |
+
source: LinkSource = _RemoteFileSource(
|
| 258 |
+
candidates_from_page=candidates_from_page,
|
| 259 |
+
page_validator=page_validator,
|
| 260 |
+
link=Link(url, cache_link_parsing=cache_link_parsing),
|
| 261 |
+
)
|
| 262 |
+
return (url, source)
|
| 263 |
+
|
| 264 |
+
if os.path.isdir(path):
|
| 265 |
+
if expand_dir:
|
| 266 |
+
source = _FlatDirectorySource(
|
| 267 |
+
candidates_from_page=candidates_from_page,
|
| 268 |
+
path=path,
|
| 269 |
+
project_name=project_name,
|
| 270 |
+
)
|
| 271 |
+
else:
|
| 272 |
+
source = _IndexDirectorySource(
|
| 273 |
+
candidates_from_page=candidates_from_page,
|
| 274 |
+
link=Link(url, cache_link_parsing=cache_link_parsing),
|
| 275 |
+
)
|
| 276 |
+
return (url, source)
|
| 277 |
+
elif os.path.isfile(path):
|
| 278 |
+
source = _LocalFileSource(
|
| 279 |
+
candidates_from_page=candidates_from_page,
|
| 280 |
+
link=Link(url, cache_link_parsing=cache_link_parsing),
|
| 281 |
+
)
|
| 282 |
+
return (url, source)
|
| 283 |
+
logger.warning(
|
| 284 |
+
"Location '%s' is ignored: it is neither a file nor a directory.",
|
| 285 |
+
location,
|
| 286 |
+
)
|
| 287 |
+
return (url, None)
|