Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/venv/Lib/site-packages/pip/_internal/commands/download.py
811 views
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, with_cleanup
12
from pip._internal.req.req_tracker import get_requirement_tracker
13
from pip._internal.utils.misc import ensure_dir, normalize_path, write_output
14
from pip._internal.utils.temp_dir import TempDirectory
15
16
logger = logging.getLogger(__name__)
17
18
19
class DownloadCommand(RequirementCommand):
20
"""
21
Download packages from:
22
23
- PyPI (and other indexes) using requirement specifiers.
24
- VCS project urls.
25
- Local project directories.
26
- Local or remote source archives.
27
28
pip also supports downloading from "requirements files", which provide
29
an easy way to specify a whole environment to be downloaded.
30
"""
31
32
usage = """
33
%prog [options] <requirement specifier> [package-index-options] ...
34
%prog [options] -r <requirements file> [package-index-options] ...
35
%prog [options] <vcs project url> ...
36
%prog [options] <local project path> ...
37
%prog [options] <archive url/path> ..."""
38
39
def __init__(self, *args, **kw):
40
super(DownloadCommand, self).__init__(*args, **kw)
41
42
cmd_opts = self.cmd_opts
43
44
cmd_opts.add_option(cmdoptions.constraints())
45
cmd_opts.add_option(cmdoptions.requirements())
46
cmd_opts.add_option(cmdoptions.build_dir())
47
cmd_opts.add_option(cmdoptions.no_deps())
48
cmd_opts.add_option(cmdoptions.global_options())
49
cmd_opts.add_option(cmdoptions.no_binary())
50
cmd_opts.add_option(cmdoptions.only_binary())
51
cmd_opts.add_option(cmdoptions.prefer_binary())
52
cmd_opts.add_option(cmdoptions.src())
53
cmd_opts.add_option(cmdoptions.pre())
54
cmd_opts.add_option(cmdoptions.require_hashes())
55
cmd_opts.add_option(cmdoptions.progress_bar())
56
cmd_opts.add_option(cmdoptions.no_build_isolation())
57
cmd_opts.add_option(cmdoptions.use_pep517())
58
cmd_opts.add_option(cmdoptions.no_use_pep517())
59
60
cmd_opts.add_option(
61
'-d', '--dest', '--destination-dir', '--destination-directory',
62
dest='download_dir',
63
metavar='dir',
64
default=os.curdir,
65
help=("Download packages into <dir>."),
66
)
67
68
cmdoptions.add_target_python_options(cmd_opts)
69
70
index_opts = cmdoptions.make_option_group(
71
cmdoptions.index_group,
72
self.parser,
73
)
74
75
self.parser.insert_option_group(0, index_opts)
76
self.parser.insert_option_group(0, cmd_opts)
77
78
@with_cleanup
79
def run(self, options, args):
80
options.ignore_installed = True
81
# editable doesn't really make sense for `pip download`, but the bowels
82
# of the RequirementSet code require that property.
83
options.editables = []
84
85
cmdoptions.check_dist_restriction(options)
86
87
options.download_dir = normalize_path(options.download_dir)
88
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
)
99
build_delete = (not (options.no_clean or options.build_dir))
100
101
req_tracker = self.enter_context(get_requirement_tracker())
102
103
directory = TempDirectory(
104
options.build_dir,
105
delete=build_delete,
106
kind="download",
107
globally_managed=True,
108
)
109
110
reqs = self.get_requirements(args, options, finder, session)
111
112
preparer = self.make_requirement_preparer(
113
temp_build_dir=directory,
114
options=options,
115
req_tracker=req_tracker,
116
session=session,
117
finder=finder,
118
download_dir=options.download_dir,
119
use_user_site=False,
120
)
121
122
resolver = self.make_resolver(
123
preparer=preparer,
124
finder=finder,
125
options=options,
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 = ' '.join([
136
req.name for req in requirement_set.requirements.values()
137
if req.successfully_downloaded
138
])
139
if downloaded:
140
write_output('Successfully downloaded %s', downloaded)
141
142
return requirement_set
143
144