Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/pip/_internal/commands/download.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 import logging | |
2 import os | |
3 | |
4 from pip._internal.cli import cmdoptions | |
5 from pip._internal.cli.cmdoptions import make_target_python | |
6 from pip._internal.cli.req_command import RequirementCommand, with_cleanup | |
7 from pip._internal.cli.status_codes import SUCCESS | |
8 from pip._internal.req.req_tracker import get_requirement_tracker | |
9 from pip._internal.utils.misc import ensure_dir, normalize_path, write_output | |
10 from pip._internal.utils.temp_dir import TempDirectory | |
11 from pip._internal.utils.typing import MYPY_CHECK_RUNNING | |
12 | |
13 if MYPY_CHECK_RUNNING: | |
14 from optparse import Values | |
15 from typing import List | |
16 | |
17 logger = logging.getLogger(__name__) | |
18 | |
19 | |
20 class DownloadCommand(RequirementCommand): | |
21 """ | |
22 Download packages from: | |
23 | |
24 - PyPI (and other indexes) using requirement specifiers. | |
25 - VCS project urls. | |
26 - Local project directories. | |
27 - Local or remote source archives. | |
28 | |
29 pip also supports downloading from "requirements files", which provide | |
30 an easy way to specify a whole environment to be downloaded. | |
31 """ | |
32 | |
33 usage = """ | |
34 %prog [options] <requirement specifier> [package-index-options] ... | |
35 %prog [options] -r <requirements file> [package-index-options] ... | |
36 %prog [options] <vcs project url> ... | |
37 %prog [options] <local project path> ... | |
38 %prog [options] <archive url/path> ...""" | |
39 | |
40 def add_options(self): | |
41 # type: () -> None | |
42 self.cmd_opts.add_option(cmdoptions.constraints()) | |
43 self.cmd_opts.add_option(cmdoptions.requirements()) | |
44 self.cmd_opts.add_option(cmdoptions.build_dir()) | |
45 self.cmd_opts.add_option(cmdoptions.no_deps()) | |
46 self.cmd_opts.add_option(cmdoptions.global_options()) | |
47 self.cmd_opts.add_option(cmdoptions.no_binary()) | |
48 self.cmd_opts.add_option(cmdoptions.only_binary()) | |
49 self.cmd_opts.add_option(cmdoptions.prefer_binary()) | |
50 self.cmd_opts.add_option(cmdoptions.src()) | |
51 self.cmd_opts.add_option(cmdoptions.pre()) | |
52 self.cmd_opts.add_option(cmdoptions.require_hashes()) | |
53 self.cmd_opts.add_option(cmdoptions.progress_bar()) | |
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.no_use_pep517()) | |
57 self.cmd_opts.add_option(cmdoptions.ignore_requires_python()) | |
58 | |
59 self.cmd_opts.add_option( | |
60 '-d', '--dest', '--destination-dir', '--destination-directory', | |
61 dest='download_dir', | |
62 metavar='dir', | |
63 default=os.curdir, | |
64 help=("Download packages into <dir>."), | |
65 ) | |
66 | |
67 cmdoptions.add_target_python_options(self.cmd_opts) | |
68 | |
69 index_opts = cmdoptions.make_option_group( | |
70 cmdoptions.index_group, | |
71 self.parser, | |
72 ) | |
73 | |
74 self.parser.insert_option_group(0, index_opts) | |
75 self.parser.insert_option_group(0, self.cmd_opts) | |
76 | |
77 @with_cleanup | |
78 def run(self, options, args): | |
79 # type: (Values, List[str]) -> int | |
80 | |
81 options.ignore_installed = True | |
82 # editable doesn't really make sense for `pip download`, but the bowels | |
83 # of the RequirementSet code require that property. | |
84 options.editables = [] | |
85 | |
86 cmdoptions.check_dist_restriction(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 req_tracker = self.enter_context(get_requirement_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 req_tracker=req_tracker, | |
115 session=session, | |
116 finder=finder, | |
117 download_dir=options.download_dir, | |
118 use_user_site=False, | |
119 ) | |
120 | |
121 resolver = self.make_resolver( | |
122 preparer=preparer, | |
123 finder=finder, | |
124 options=options, | |
125 ignore_requires_python=options.ignore_requires_python, | |
126 py_version_info=options.python_version, | |
127 ) | |
128 | |
129 self.trace_basic_info(finder) | |
130 | |
131 requirement_set = resolver.resolve( | |
132 reqs, check_supported_wheels=True | |
133 ) | |
134 | |
135 downloaded = [] # type: List[str] | |
136 for req in requirement_set.requirements.values(): | |
137 if req.satisfied_by is None: | |
138 assert req.name is not None | |
139 preparer.save_linked_requirement(req) | |
140 downloaded.append(req.name) | |
141 if downloaded: | |
142 write_output('Successfully downloaded %s', ' '.join(downloaded)) | |
143 | |
144 return SUCCESS |