~ibmcharmers/charms/trusty/ibm-dsm-base/trunk

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/site-packages/pip/commands/download.py

  • Committer: anita nayak
  • Date: 2016-12-08 14:39:17 UTC
  • Revision ID: anitanayak@in.ibm.com-20161208143917-3pcyiz4cmbey1fol
Initial Check in for ibm-dsm-base trusty

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import absolute_import
 
2
 
 
3
import logging
 
4
import os
 
5
 
 
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
 
14
 
 
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
    name = 'download'
 
32
 
 
33
    usage = """
 
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> ..."""
 
39
 
 
40
    summary = 'Download packages.'
 
41
 
 
42
    def __init__(self, *args, **kw):
 
43
        super(DownloadCommand, self).__init__(*args, **kw)
 
44
 
 
45
        cmd_opts = self.cmd_opts
 
46
 
 
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())
 
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
        cmd_opts.add_option(
 
69
            '--platform',
 
70
            dest='platform',
 
71
            metavar='platform',
 
72
            default=None,
 
73
            help=("Only download wheels compatible with <platform>. "
 
74
                  "Defaults to the platform of the running system."),
 
75
        )
 
76
 
 
77
        cmd_opts.add_option(
 
78
            '--python-version',
 
79
            dest='python_version',
 
80
            metavar='python_version',
 
81
            default=None,
 
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."),
 
88
        )
 
89
 
 
90
        cmd_opts.add_option(
 
91
            '--implementation',
 
92
            dest='implementation',
 
93
            metavar='implementation',
 
94
            default=None,
 
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."),
 
100
        )
 
101
 
 
102
        cmd_opts.add_option(
 
103
            '--abi',
 
104
            dest='abi',
 
105
            metavar='abi',
 
106
            default=None,
 
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 "
 
112
                  "this option."),
 
113
        )
 
114
 
 
115
        index_opts = cmdoptions.make_option_group(
 
116
            cmdoptions.non_deprecated_index_group,
 
117
            self.parser,
 
118
        )
 
119
 
 
120
        self.parser.insert_option_group(0, index_opts)
 
121
        self.parser.insert_option_group(0, cmd_opts)
 
122
 
 
123
    def run(self, options, args):
 
124
        options.ignore_installed = True
 
125
 
 
126
        if options.python_version:
 
127
            python_versions = [options.python_version]
 
128
        else:
 
129
            python_versions = None
 
130
 
 
131
        dist_restriction_set = any([
 
132
            options.python_version,
 
133
            options.platform,
 
134
            options.abi,
 
135
            options.implementation,
 
136
        ])
 
137
        binary_only = FormatControl(set(), set([':all:']))
 
138
        if dist_restriction_set and options.format_control != binary_only:
 
139
            raise CommandError(
 
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."
 
144
            )
 
145
 
 
146
        options.src_dir = os.path.abspath(options.src_dir)
 
147
        options.download_dir = normalize_path(options.download_dir)
 
148
 
 
149
        ensure_dir(options.download_dir)
 
150
 
 
151
        with self._build_session(options) as session:
 
152
            finder = self._build_package_finder(
 
153
                options=options,
 
154
                session=session,
 
155
                platform=options.platform,
 
156
                python_versions=python_versions,
 
157
                abi=options.abi,
 
158
                implementation=options.implementation,
 
159
            )
 
160
            build_delete = (not (options.no_clean or options.build_dir))
 
161
            if options.cache_dir and not check_path_owner(options.cache_dir):
 
162
                logger.warning(
 
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 "
 
167
                    "sudo's -H flag.",
 
168
                    options.cache_dir,
 
169
                )
 
170
                options.cache_dir = None
 
171
 
 
172
            with BuildDirectory(options.build_dir,
 
173
                                delete=build_delete) as build_dir:
 
174
 
 
175
                requirement_set = RequirementSet(
 
176
                    build_dir=build_dir,
 
177
                    src_dir=options.src_dir,
 
178
                    download_dir=options.download_dir,
 
179
                    ignore_installed=True,
 
180
                    ignore_dependencies=options.ignore_dependencies,
 
181
                    session=session,
 
182
                    isolated=options.isolated_mode,
 
183
                    require_hashes=options.require_hashes
 
184
                )
 
185
                self.populate_requirement_set(
 
186
                    requirement_set,
 
187
                    args,
 
188
                    options,
 
189
                    finder,
 
190
                    session,
 
191
                    self.name,
 
192
                    None
 
193
                )
 
194
 
 
195
                if not requirement_set.has_requirements:
 
196
                    return
 
197
 
 
198
                requirement_set.prepare_files(finder)
 
199
 
 
200
                downloaded = ' '.join([
 
201
                    req.name for req in requirement_set.successfully_downloaded
 
202
                ])
 
203
                if downloaded:
 
204
                    logger.info(
 
205
                        'Successfully downloaded %s', downloaded
 
206
                    )
 
207
 
 
208
                # Clean up
 
209
                if not options.no_clean:
 
210
                    requirement_set.cleanup_files()
 
211
 
 
212
        return requirement_set