Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/pip/_internal/commands/download.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 from __future__ import absolute_import | |
2 | |
3 import logging | |
4 import os | |
5 | |
6 from pip._internal.cli import cmdoptions | |
7 from pip._internal.cli.base_command import RequirementCommand | |
8 from pip._internal.cli.cmdoptions import make_target_python | |
9 from pip._internal.legacy_resolve import Resolver | |
10 from pip._internal.operations.prepare import RequirementPreparer | |
11 from pip._internal.req import RequirementSet | |
12 from pip._internal.req.req_tracker import RequirementTracker | |
13 from pip._internal.utils.filesystem import check_path_owner | |
14 from pip._internal.utils.misc import ensure_dir, normalize_path | |
15 from pip._internal.utils.temp_dir import TempDirectory | |
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 name = 'download' | |
33 | |
34 usage = """ | |
35 %prog [options] <requirement specifier> [package-index-options] ... | |
36 %prog [options] -r <requirements file> [package-index-options] ... | |
37 %prog [options] <vcs project url> ... | |
38 %prog [options] <local project path> ... | |
39 %prog [options] <archive url/path> ...""" | |
40 | |
41 summary = 'Download packages.' | |
42 | |
43 def __init__(self, *args, **kw): | |
44 super(DownloadCommand, self).__init__(*args, **kw) | |
45 | |
46 cmd_opts = self.cmd_opts | |
47 | |
48 cmd_opts.add_option(cmdoptions.constraints()) | |
49 cmd_opts.add_option(cmdoptions.requirements()) | |
50 cmd_opts.add_option(cmdoptions.build_dir()) | |
51 cmd_opts.add_option(cmdoptions.no_deps()) | |
52 cmd_opts.add_option(cmdoptions.global_options()) | |
53 cmd_opts.add_option(cmdoptions.no_binary()) | |
54 cmd_opts.add_option(cmdoptions.only_binary()) | |
55 cmd_opts.add_option(cmdoptions.prefer_binary()) | |
56 cmd_opts.add_option(cmdoptions.src()) | |
57 cmd_opts.add_option(cmdoptions.pre()) | |
58 cmd_opts.add_option(cmdoptions.no_clean()) | |
59 cmd_opts.add_option(cmdoptions.require_hashes()) | |
60 cmd_opts.add_option(cmdoptions.progress_bar()) | |
61 cmd_opts.add_option(cmdoptions.no_build_isolation()) | |
62 cmd_opts.add_option(cmdoptions.use_pep517()) | |
63 cmd_opts.add_option(cmdoptions.no_use_pep517()) | |
64 | |
65 cmd_opts.add_option( | |
66 '-d', '--dest', '--destination-dir', '--destination-directory', | |
67 dest='download_dir', | |
68 metavar='dir', | |
69 default=os.curdir, | |
70 help=("Download packages into <dir>."), | |
71 ) | |
72 | |
73 cmdoptions.add_target_python_options(cmd_opts) | |
74 | |
75 index_opts = cmdoptions.make_option_group( | |
76 cmdoptions.index_group, | |
77 self.parser, | |
78 ) | |
79 | |
80 self.parser.insert_option_group(0, index_opts) | |
81 self.parser.insert_option_group(0, cmd_opts) | |
82 | |
83 def run(self, options, args): | |
84 options.ignore_installed = True | |
85 # editable doesn't really make sense for `pip download`, but the bowels | |
86 # of the RequirementSet code require that property. | |
87 options.editables = [] | |
88 | |
89 cmdoptions.check_dist_restriction(options) | |
90 | |
91 options.src_dir = os.path.abspath(options.src_dir) | |
92 options.download_dir = normalize_path(options.download_dir) | |
93 | |
94 ensure_dir(options.download_dir) | |
95 | |
96 with self._build_session(options) as session: | |
97 target_python = make_target_python(options) | |
98 finder = self._build_package_finder( | |
99 options=options, | |
100 session=session, | |
101 target_python=target_python, | |
102 ) | |
103 build_delete = (not (options.no_clean or options.build_dir)) | |
104 if options.cache_dir and not check_path_owner(options.cache_dir): | |
105 logger.warning( | |
106 "The directory '%s' or its parent directory is not owned " | |
107 "by the current user and caching wheels has been " | |
108 "disabled. check the permissions and owner of that " | |
109 "directory. If executing pip with sudo, you may want " | |
110 "sudo's -H flag.", | |
111 options.cache_dir, | |
112 ) | |
113 options.cache_dir = None | |
114 | |
115 with RequirementTracker() as req_tracker, TempDirectory( | |
116 options.build_dir, delete=build_delete, kind="download" | |
117 ) as directory: | |
118 | |
119 requirement_set = RequirementSet( | |
120 require_hashes=options.require_hashes, | |
121 ) | |
122 self.populate_requirement_set( | |
123 requirement_set, | |
124 args, | |
125 options, | |
126 finder, | |
127 session, | |
128 self.name, | |
129 None | |
130 ) | |
131 | |
132 preparer = RequirementPreparer( | |
133 build_dir=directory.path, | |
134 src_dir=options.src_dir, | |
135 download_dir=options.download_dir, | |
136 wheel_download_dir=None, | |
137 progress_bar=options.progress_bar, | |
138 build_isolation=options.build_isolation, | |
139 req_tracker=req_tracker, | |
140 ) | |
141 | |
142 resolver = Resolver( | |
143 preparer=preparer, | |
144 finder=finder, | |
145 session=session, | |
146 wheel_cache=None, | |
147 use_user_site=False, | |
148 upgrade_strategy="to-satisfy-only", | |
149 force_reinstall=False, | |
150 ignore_dependencies=options.ignore_dependencies, | |
151 py_version_info=options.python_version, | |
152 ignore_requires_python=False, | |
153 ignore_installed=True, | |
154 isolated=options.isolated_mode, | |
155 ) | |
156 resolver.resolve(requirement_set) | |
157 | |
158 downloaded = ' '.join([ | |
159 req.name for req in requirement_set.successfully_downloaded | |
160 ]) | |
161 if downloaded: | |
162 logger.info('Successfully downloaded %s', downloaded) | |
163 | |
164 # Clean up | |
165 if not options.no_clean: | |
166 requirement_set.cleanup_files() | |
167 | |
168 return requirement_set |