1
from __future__ import absolute_import
6
from pip.exceptions import CommandError
7
from pip.index import FormatControl
8
from pip.req import RequirementSet
9
from pip.basecommand import RequirementCommand
10
from pip import cmdoptions
11
from pip.utils import ensure_dir, normalize_path
12
from pip.utils.build import BuildDirectory
13
from pip.utils.filesystem import check_path_owner
16
logger = logging.getLogger(__name__)
19
class DownloadCommand(RequirementCommand):
21
Download packages from:
23
- PyPI (and other indexes) using requirement specifiers.
25
- Local project directories.
26
- Local or remote source archives.
28
pip also supports downloading from "requirements files", which provide
29
an easy way to specify a whole environment to be downloaded.
34
%prog [options] <requirement specifier> [package-index-options] ...
35
%prog [options] -r <requirements file> [package-index-options] ...
36
%prog [options] [-e] <vcs project url> ...
37
%prog [options] [-e] <local project path> ...
38
%prog [options] <archive url/path> ..."""
40
summary = 'Download packages.'
42
def __init__(self, *args, **kw):
43
super(DownloadCommand, self).__init__(*args, **kw)
45
cmd_opts = self.cmd_opts
47
cmd_opts.add_option(cmdoptions.constraints())
48
cmd_opts.add_option(cmdoptions.editable())
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.src())
56
cmd_opts.add_option(cmdoptions.pre())
57
cmd_opts.add_option(cmdoptions.no_clean())
58
cmd_opts.add_option(cmdoptions.require_hashes())
61
'-d', '--dest', '--destination-dir', '--destination-directory',
65
help=("Download packages into <dir>."),
73
help=("Only download wheels compatible with <platform>. "
74
"Defaults to the platform of the running system."),
79
dest='python_version',
80
metavar='python_version',
82
help=("Only download wheels compatible with Python "
83
"interpreter version <version>. If not specified, then the "
84
"current system interpreter minor version is used. A major "
85
"version (e.g. '2') can be specified to match all "
86
"minor revs of that major version. A minor version "
87
"(e.g. '34') can also be specified."),
92
dest='implementation',
93
metavar='implementation',
95
help=("Only download wheels compatible with Python "
96
"implementation <implementation>, e.g. 'pp', 'jy', 'cp', "
97
" or 'ip'. If not specified, then the current "
98
"interpreter implementation is used. Use 'py' to force "
99
"implementation-agnostic wheels."),
107
help=("Only download wheels compatible with Python "
108
"abi <abi>, e.g. 'pypy_41'. If not specified, then the "
109
"current interpreter abi tag is used. Generally "
110
"you will need to specify --implementation, "
111
"--platform, and --python-version when using "
115
index_opts = cmdoptions.make_option_group(
116
cmdoptions.non_deprecated_index_group,
120
self.parser.insert_option_group(0, index_opts)
121
self.parser.insert_option_group(0, cmd_opts)
123
def run(self, options, args):
124
options.ignore_installed = True
126
if options.python_version:
127
python_versions = [options.python_version]
129
python_versions = None
131
dist_restriction_set = any([
132
options.python_version,
135
options.implementation,
137
binary_only = FormatControl(set(), set([':all:']))
138
if dist_restriction_set and options.format_control != binary_only:
140
"--only-binary=:all: must be set and --no-binary must not "
141
"be set (or must be set to :none:) when restricting platform "
142
"and interpreter constraints using --python-version, "
143
"--platform, --abi, or --implementation."
146
options.src_dir = os.path.abspath(options.src_dir)
147
options.download_dir = normalize_path(options.download_dir)
149
ensure_dir(options.download_dir)
151
with self._build_session(options) as session:
152
finder = self._build_package_finder(
155
platform=options.platform,
156
python_versions=python_versions,
158
implementation=options.implementation,
160
build_delete = (not (options.no_clean or options.build_dir))
161
if options.cache_dir and not check_path_owner(options.cache_dir):
163
"The directory '%s' or its parent directory is not owned "
164
"by the current user and caching wheels has been "
165
"disabled. check the permissions and owner of that "
166
"directory. If executing pip with sudo, you may want "
170
options.cache_dir = None
172
with BuildDirectory(options.build_dir,
173
delete=build_delete) as build_dir:
175
requirement_set = RequirementSet(
177
src_dir=options.src_dir,
178
download_dir=options.download_dir,
179
ignore_installed=True,
180
ignore_dependencies=options.ignore_dependencies,
182
isolated=options.isolated_mode,
183
require_hashes=options.require_hashes
185
self.populate_requirement_set(
195
if not requirement_set.has_requirements:
198
requirement_set.prepare_files(finder)
200
downloaded = ' '.join([
201
req.name for req in requirement_set.successfully_downloaded
205
'Successfully downloaded %s', downloaded
209
if not options.no_clean:
210
requirement_set.cleanup_files()
212
return requirement_set