Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_internal/commands/download.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9e54283cc701 |
---|---|
1 # The following comment should be removed at some point in the future. | |
2 # mypy: disallow-untyped-defs=False | |
3 | |
4 from __future__ import absolute_import | |
5 | |
6 import logging | |
7 import os | |
8 | |
9 from pip._internal.cli import cmdoptions | |
10 from pip._internal.cli.cmdoptions import make_target_python | |
11 from pip._internal.cli.req_command import RequirementCommand | |
12 from pip._internal.req import RequirementSet | |
13 from pip._internal.req.req_tracker import get_requirement_tracker | |
14 from pip._internal.utils.misc import ensure_dir, normalize_path, write_output | |
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 | |
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 __init__(self, *args, **kw): | |
41 super(DownloadCommand, self).__init__(*args, **kw) | |
42 | |
43 cmd_opts = self.cmd_opts | |
44 | |
45 cmd_opts.add_option(cmdoptions.constraints()) | |
46 cmd_opts.add_option(cmdoptions.requirements()) | |
47 cmd_opts.add_option(cmdoptions.build_dir()) | |
48 cmd_opts.add_option(cmdoptions.no_deps()) | |
49 cmd_opts.add_option(cmdoptions.global_options()) | |
50 cmd_opts.add_option(cmdoptions.no_binary()) | |
51 cmd_opts.add_option(cmdoptions.only_binary()) | |
52 cmd_opts.add_option(cmdoptions.prefer_binary()) | |
53 cmd_opts.add_option(cmdoptions.src()) | |
54 cmd_opts.add_option(cmdoptions.pre()) | |
55 cmd_opts.add_option(cmdoptions.no_clean()) | |
56 cmd_opts.add_option(cmdoptions.require_hashes()) | |
57 cmd_opts.add_option(cmdoptions.progress_bar()) | |
58 cmd_opts.add_option(cmdoptions.no_build_isolation()) | |
59 cmd_opts.add_option(cmdoptions.use_pep517()) | |
60 cmd_opts.add_option(cmdoptions.no_use_pep517()) | |
61 | |
62 cmd_opts.add_option( | |
63 '-d', '--dest', '--destination-dir', '--destination-directory', | |
64 dest='download_dir', | |
65 metavar='dir', | |
66 default=os.curdir, | |
67 help=("Download packages into <dir>."), | |
68 ) | |
69 | |
70 cmdoptions.add_target_python_options(cmd_opts) | |
71 | |
72 index_opts = cmdoptions.make_option_group( | |
73 cmdoptions.index_group, | |
74 self.parser, | |
75 ) | |
76 | |
77 self.parser.insert_option_group(0, index_opts) | |
78 self.parser.insert_option_group(0, cmd_opts) | |
79 | |
80 def run(self, options, args): | |
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 | |
90 ensure_dir(options.download_dir) | |
91 | |
92 session = self.get_default_session(options) | |
93 | |
94 target_python = make_target_python(options) | |
95 finder = self._build_package_finder( | |
96 options=options, | |
97 session=session, | |
98 target_python=target_python, | |
99 ) | |
100 build_delete = (not (options.no_clean or options.build_dir)) | |
101 | |
102 with get_requirement_tracker() as req_tracker, TempDirectory( | |
103 options.build_dir, delete=build_delete, kind="download" | |
104 ) as directory: | |
105 | |
106 requirement_set = RequirementSet() | |
107 self.populate_requirement_set( | |
108 requirement_set, | |
109 args, | |
110 options, | |
111 finder, | |
112 session, | |
113 None | |
114 ) | |
115 | |
116 preparer = self.make_requirement_preparer( | |
117 temp_build_dir=directory, | |
118 options=options, | |
119 req_tracker=req_tracker, | |
120 session=session, | |
121 finder=finder, | |
122 download_dir=options.download_dir, | |
123 use_user_site=False, | |
124 ) | |
125 | |
126 resolver = self.make_resolver( | |
127 preparer=preparer, | |
128 finder=finder, | |
129 options=options, | |
130 py_version_info=options.python_version, | |
131 ) | |
132 | |
133 self.trace_basic_info(finder) | |
134 | |
135 resolver.resolve(requirement_set) | |
136 | |
137 downloaded = ' '.join([ | |
138 req.name for req in requirement_set.successfully_downloaded | |
139 ]) | |
140 if downloaded: | |
141 write_output('Successfully downloaded %s', downloaded) | |
142 | |
143 # Clean up | |
144 if not options.no_clean: | |
145 requirement_set.cleanup_files() | |
146 | |
147 return requirement_set |