We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pip install -h output is wrong about pyc
* Pip version: 9.0.1
* Python version: 3.5
* Operating system: Linux

### Description:
pip install -h says

  --compile                   Compile py files to pyc
  --no-compile                Do not compile py files to pyc

pyc is only correct for some Python interpreters. Not for Python, not for windows - I never tried pypy or others. And somebody may set PYTHONOPTIMIZE and get pyo instead of pyc.

Maybe py could also vary, what about pyw on Windows? There could be more in the future.

A correct version could perhaps be

Compile Python source files to byte code

```
pip install -h
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pip/commands/install.py`
Content:
```
1 from __future__ import absolute_import
2 
3 import logging
4 import operator
5 import os
6 import tempfile
7 import shutil
8 try:
9     import wheel
10 except ImportError:
11     wheel = None
12 
13 from pip.req import RequirementSet
14 from pip.basecommand import RequirementCommand
15 from pip.locations import virtualenv_no_global, distutils_scheme
16 from pip.exceptions import (
17     InstallationError, CommandError, PreviousBuildDirError,
18 )
19 from pip import cmdoptions
20 from pip.utils import ensure_dir, get_installed_version
21 from pip.utils.build import BuildDirectory
22 from pip.utils.filesystem import check_path_owner
23 from pip.wheel import WheelCache, WheelBuilder
24 
25 
26 logger = logging.getLogger(__name__)
27 
28 
29 class InstallCommand(RequirementCommand):
30     """
31     Install packages from:
32 
33     - PyPI (and other indexes) using requirement specifiers.
34     - VCS project urls.
35     - Local project directories.
36     - Local or remote source archives.
37 
38     pip also supports installing from "requirements files", which provide
39     an easy way to specify a whole environment to be installed.
40     """
41     name = 'install'
42 
43     usage = """
44       %prog [options] <requirement specifier> [package-index-options] ...
45       %prog [options] -r <requirements file> [package-index-options] ...
46       %prog [options] [-e] <vcs project url> ...
47       %prog [options] [-e] <local project path> ...
48       %prog [options] <archive url/path> ..."""
49 
50     summary = 'Install packages.'
51 
52     def __init__(self, *args, **kw):
53         super(InstallCommand, self).__init__(*args, **kw)
54 
55         cmd_opts = self.cmd_opts
56 
57         cmd_opts.add_option(cmdoptions.requirements())
58         cmd_opts.add_option(cmdoptions.constraints())
59         cmd_opts.add_option(cmdoptions.no_deps())
60         cmd_opts.add_option(cmdoptions.pre())
61 
62         cmd_opts.add_option(cmdoptions.editable())
63         cmd_opts.add_option(
64             '-t', '--target',
65             dest='target_dir',
66             metavar='dir',
67             default=None,
68             help='Install packages into <dir>. '
69                  'By default this will not replace existing files/folders in '
70                  '<dir>. Use --upgrade to replace existing packages in <dir> '
71                  'with new versions.'
72         )
73         cmd_opts.add_option(
74             '--user',
75             dest='use_user_site',
76             action='store_true',
77             help="Install to the Python user install directory for your "
78                  "platform. Typically ~/.local/, or %APPDATA%\\Python on "
79                  "Windows. (See the Python documentation for site.USER_BASE "
80                  "for full details.)")
81         cmd_opts.add_option(
82             '--root',
83             dest='root_path',
84             metavar='dir',
85             default=None,
86             help="Install everything relative to this alternate root "
87                  "directory.")
88         cmd_opts.add_option(
89             '--prefix',
90             dest='prefix_path',
91             metavar='dir',
92             default=None,
93             help="Installation prefix where lib, bin and other top-level "
94                  "folders are placed")
95 
96         cmd_opts.add_option(cmdoptions.build_dir())
97 
98         cmd_opts.add_option(cmdoptions.src())
99 
100         cmd_opts.add_option(
101             '-U', '--upgrade',
102             dest='upgrade',
103             action='store_true',
104             help='Upgrade all specified packages to the newest available '
105                  'version. The handling of dependencies depends on the '
106                  'upgrade-strategy used.'
107         )
108 
109         cmd_opts.add_option(
110             '--upgrade-strategy',
111             dest='upgrade_strategy',
112             default='eager',
113             choices=['only-if-needed', 'eager'],
114             help='Determines how dependency upgrading should be handled '
115                  '(default: %(default)s). '
116                  '"eager" - dependencies are upgraded regardless of '
117                  'whether the currently installed version satisfies the '
118                  'requirements of the upgraded package(s). '
119                  '"only-if-needed" -  are upgraded only when they do not '
120                  'satisfy the requirements of the upgraded package(s).'
121         )
122 
123         cmd_opts.add_option(
124             '--force-reinstall',
125             dest='force_reinstall',
126             action='store_true',
127             help='When upgrading, reinstall all packages even if they are '
128                  'already up-to-date.')
129 
130         cmd_opts.add_option(
131             '-I', '--ignore-installed',
132             dest='ignore_installed',
133             action='store_true',
134             help='Ignore the installed packages (reinstalling instead).')
135 
136         cmd_opts.add_option(cmdoptions.ignore_requires_python())
137 
138         cmd_opts.add_option(cmdoptions.install_options())
139         cmd_opts.add_option(cmdoptions.global_options())
140 
141         cmd_opts.add_option(
142             "--compile",
143             action="store_true",
144             dest="compile",
145             default=True,
146             help="Compile py files to pyc",
147         )
148 
149         cmd_opts.add_option(
150             "--no-compile",
151             action="store_false",
152             dest="compile",
153             help="Do not compile py files to pyc",
154         )
155 
156         cmd_opts.add_option(cmdoptions.no_binary())
157         cmd_opts.add_option(cmdoptions.only_binary())
158         cmd_opts.add_option(cmdoptions.no_clean())
159         cmd_opts.add_option(cmdoptions.require_hashes())
160         cmd_opts.add_option(cmdoptions.progress_bar())
161 
162         index_opts = cmdoptions.make_option_group(
163             cmdoptions.index_group,
164             self.parser,
165         )
166 
167         self.parser.insert_option_group(0, index_opts)
168         self.parser.insert_option_group(0, cmd_opts)
169 
170     def run(self, options, args):
171         cmdoptions.check_install_build_global(options)
172 
173         if options.build_dir:
174             options.build_dir = os.path.abspath(options.build_dir)
175 
176         options.src_dir = os.path.abspath(options.src_dir)
177         install_options = options.install_options or []
178         if options.use_user_site:
179             if options.prefix_path:
180                 raise CommandError(
181                     "Can not combine '--user' and '--prefix' as they imply "
182                     "different installation locations"
183                 )
184             if virtualenv_no_global():
185                 raise InstallationError(
186                     "Can not perform a '--user' install. User site-packages "
187                     "are not visible in this virtualenv."
188                 )
189             install_options.append('--user')
190             install_options.append('--prefix=')
191 
192         temp_target_dir = None
193         if options.target_dir:
194             options.ignore_installed = True
195             temp_target_dir = tempfile.mkdtemp()
196             options.target_dir = os.path.abspath(options.target_dir)
197             if (os.path.exists(options.target_dir) and not
198                     os.path.isdir(options.target_dir)):
199                 raise CommandError(
200                     "Target path exists but is not a directory, will not "
201                     "continue."
202                 )
203             install_options.append('--home=' + temp_target_dir)
204 
205         global_options = options.global_options or []
206 
207         with self._build_session(options) as session:
208 
209             finder = self._build_package_finder(options, session)
210             build_delete = (not (options.no_clean or options.build_dir))
211             wheel_cache = WheelCache(options.cache_dir, options.format_control)
212             if options.cache_dir and not check_path_owner(options.cache_dir):
213                 logger.warning(
214                     "The directory '%s' or its parent directory is not owned "
215                     "by the current user and caching wheels has been "
216                     "disabled. check the permissions and owner of that "
217                     "directory. If executing pip with sudo, you may want "
218                     "sudo's -H flag.",
219                     options.cache_dir,
220                 )
221                 options.cache_dir = None
222 
223             with BuildDirectory(options.build_dir,
224                                 delete=build_delete) as build_dir:
225                 requirement_set = RequirementSet(
226                     build_dir=build_dir,
227                     src_dir=options.src_dir,
228                     upgrade=options.upgrade,
229                     upgrade_strategy=options.upgrade_strategy,
230                     ignore_installed=options.ignore_installed,
231                     ignore_dependencies=options.ignore_dependencies,
232                     ignore_requires_python=options.ignore_requires_python,
233                     force_reinstall=options.force_reinstall,
234                     use_user_site=options.use_user_site,
235                     target_dir=temp_target_dir,
236                     session=session,
237                     pycompile=options.compile,
238                     isolated=options.isolated_mode,
239                     wheel_cache=wheel_cache,
240                     require_hashes=options.require_hashes,
241                     progress_bar=options.progress_bar,
242                 )
243 
244                 self.populate_requirement_set(
245                     requirement_set, args, options, finder, session, self.name,
246                     wheel_cache
247                 )
248 
249                 try:
250                     if (not wheel or not options.cache_dir):
251                         # on -d don't do complex things like building
252                         # wheels, and don't try to build wheels when wheel is
253                         # not installed.
254                         requirement_set.prepare_files(finder)
255                     else:
256                         # build wheels before install.
257                         wb = WheelBuilder(
258                             requirement_set,
259                             finder,
260                             build_options=[],
261                             global_options=[],
262                         )
263                         # Ignore the result: a failed wheel will be
264                         # installed from the sdist/vcs whatever.
265                         wb.build(autobuilding=True)
266 
267                     requirement_set.install(
268                         install_options,
269                         global_options,
270                         root=options.root_path,
271                         prefix=options.prefix_path,
272                     )
273 
274                     possible_lib_locations = get_lib_location_guesses(
275                         user=options.use_user_site,
276                         home=temp_target_dir,
277                         root=options.root_path,
278                         prefix=options.prefix_path,
279                         isolated=options.isolated_mode,
280                     )
281                     reqs = sorted(
282                         requirement_set.successfully_installed,
283                         key=operator.attrgetter('name'))
284                     items = []
285                     for req in reqs:
286                         item = req.name
287                         try:
288                             installed_version = get_installed_version(
289                                 req.name, possible_lib_locations
290                             )
291                             if installed_version:
292                                 item += '-' + installed_version
293                         except Exception:
294                             pass
295                         items.append(item)
296                     installed = ' '.join(items)
297                     if installed:
298                         logger.info('Successfully installed %s', installed)
299                 except PreviousBuildDirError:
300                     options.no_clean = True
301                     raise
302                 finally:
303                     # Clean up
304                     if not options.no_clean:
305                         requirement_set.cleanup_files()
306 
307         if options.target_dir:
308             ensure_dir(options.target_dir)
309 
310             # Checking both purelib and platlib directories for installed
311             # packages to be moved to target directory
312             lib_dir_list = []
313 
314             purelib_dir = distutils_scheme('', home=temp_target_dir)['purelib']
315             platlib_dir = distutils_scheme('', home=temp_target_dir)['platlib']
316             data_dir = distutils_scheme('', home=temp_target_dir)['data']
317 
318             if os.path.exists(purelib_dir):
319                 lib_dir_list.append(purelib_dir)
320             if os.path.exists(platlib_dir) and platlib_dir != purelib_dir:
321                 lib_dir_list.append(platlib_dir)
322             if os.path.exists(data_dir):
323                 lib_dir_list.append(data_dir)
324 
325             for lib_dir in lib_dir_list:
326                 for item in os.listdir(lib_dir):
327                     if lib_dir == data_dir:
328                         ddir = os.path.join(data_dir, item)
329                         if any(s.startswith(ddir) for s in lib_dir_list[:-1]):
330                             continue
331                     target_item_dir = os.path.join(options.target_dir, item)
332                     if os.path.exists(target_item_dir):
333                         if not options.upgrade:
334                             logger.warning(
335                                 'Target directory %s already exists. Specify '
336                                 '--upgrade to force replacement.',
337                                 target_item_dir
338                             )
339                             continue
340                         if os.path.islink(target_item_dir):
341                             logger.warning(
342                                 'Target directory %s already exists and is '
343                                 'a link. Pip will not automatically replace '
344                                 'links, please remove if replacement is '
345                                 'desired.',
346                                 target_item_dir
347                             )
348                             continue
349                         if os.path.isdir(target_item_dir):
350                             shutil.rmtree(target_item_dir)
351                         else:
352                             os.remove(target_item_dir)
353 
354                     shutil.move(
355                         os.path.join(lib_dir, item),
356                         target_item_dir
357                     )
358             shutil.rmtree(temp_target_dir)
359         return requirement_set
360 
361 
362 def get_lib_location_guesses(*args, **kwargs):
363     scheme = distutils_scheme('', *args, **kwargs)
364     return [scheme['purelib'], scheme['platlib']]
365
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pip/commands/install.py b/pip/commands/install.py
--- a/pip/commands/install.py
+++ b/pip/commands/install.py
@@ -143,14 +143,14 @@
             action="store_true",
             dest="compile",
             default=True,
-            help="Compile py files to pyc",
+            help="Compile Python source files to bytecode",
         )
 
         cmd_opts.add_option(
             "--no-compile",
             action="store_false",
             dest="compile",
-            help="Do not compile py files to pyc",
+            help="Do not compile Python source files to bytecode",
         )
 
         cmd_opts.add_option(cmdoptions.no_binary())

{"golden_diff": "diff --git a/pip/commands/install.py b/pip/commands/install.py\n--- a/pip/commands/install.py\n+++ b/pip/commands/install.py\n@@ -143,14 +143,14 @@\n             action=\"store_true\",\n             dest=\"compile\",\n             default=True,\n-            help=\"Compile py files to pyc\",\n+            help=\"Compile Python source files to bytecode\",\n         )\n \n         cmd_opts.add_option(\n             \"--no-compile\",\n             action=\"store_false\",\n             dest=\"compile\",\n-            help=\"Do not compile py files to pyc\",\n+            help=\"Do not compile Python source files to bytecode\",\n         )\n \n         cmd_opts.add_option(cmdoptions.no_binary())\n", "issue": "pip install -h output is wrong about pyc\n* Pip version: 9.0.1\r\n* Python version: 3.5\r\n* Operating system: Linux\r\n\r\n### Description:\r\npip install -h says\r\n\r\n  --compile                   Compile py files to pyc\r\n  --no-compile                Do not compile py files to pyc\r\n\r\npyc is only correct for some Python interpreters. Not for Python, not for windows - I never tried pypy or others. And somebody may set PYTHONOPTIMIZE and get pyo instead of pyc.\r\n\r\nMaybe py could also vary, what about pyw on Windows? There could be more in the future.\r\n\r\nA correct version could perhaps be\r\n\r\nCompile Python source files to byte code\r\n\r\n```\r\npip install -h\r\n```\r\n\n", "before_files": [{"content": "from __future__ import absolute_import\n\nimport logging\nimport operator\nimport os\nimport tempfile\nimport shutil\ntry:\n    import wheel\nexcept ImportError:\n    wheel = None\n\nfrom pip.req import RequirementSet\nfrom pip.basecommand import RequirementCommand\nfrom pip.locations import virtualenv_no_global, distutils_scheme\nfrom pip.exceptions import (\n    InstallationError, CommandError, PreviousBuildDirError,\n)\nfrom pip import cmdoptions\nfrom pip.utils import ensure_dir, get_installed_version\nfrom pip.utils.build import BuildDirectory\nfrom pip.utils.filesystem import check_path_owner\nfrom pip.wheel import WheelCache, WheelBuilder\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass InstallCommand(RequirementCommand):\n    \"\"\"\n    Install packages from:\n\n    - PyPI (and other indexes) using requirement specifiers.\n    - VCS project urls.\n    - Local project directories.\n    - Local or remote source archives.\n\n    pip also supports installing from \"requirements files\", which provide\n    an easy way to specify a whole environment to be installed.\n    \"\"\"\n    name = 'install'\n\n    usage = \"\"\"\n      %prog [options] <requirement specifier> [package-index-options] ...\n      %prog [options] -r <requirements file> [package-index-options] ...\n      %prog [options] [-e] <vcs project url> ...\n      %prog [options] [-e] <local project path> ...\n      %prog [options] <archive url/path> ...\"\"\"\n\n    summary = 'Install packages.'\n\n    def __init__(self, *args, **kw):\n        super(InstallCommand, self).__init__(*args, **kw)\n\n        cmd_opts = self.cmd_opts\n\n        cmd_opts.add_option(cmdoptions.requirements())\n        cmd_opts.add_option(cmdoptions.constraints())\n        cmd_opts.add_option(cmdoptions.no_deps())\n        cmd_opts.add_option(cmdoptions.pre())\n\n        cmd_opts.add_option(cmdoptions.editable())\n        cmd_opts.add_option(\n            '-t', '--target',\n            dest='target_dir',\n            metavar='dir',\n            default=None,\n            help='Install packages into <dir>. '\n                 'By default this will not replace existing files/folders in '\n                 '<dir>. Use --upgrade to replace existing packages in <dir> '\n                 'with new versions.'\n        )\n        cmd_opts.add_option(\n            '--user',\n            dest='use_user_site',\n            action='store_true',\n            help=\"Install to the Python user install directory for your \"\n                 \"platform. Typically ~/.local/, or %APPDATA%\\\\Python on \"\n                 \"Windows. (See the Python documentation for site.USER_BASE \"\n                 \"for full details.)\")\n        cmd_opts.add_option(\n            '--root',\n            dest='root_path',\n            metavar='dir',\n            default=None,\n            help=\"Install everything relative to this alternate root \"\n                 \"directory.\")\n        cmd_opts.add_option(\n            '--prefix',\n            dest='prefix_path',\n            metavar='dir',\n            default=None,\n            help=\"Installation prefix where lib, bin and other top-level \"\n                 \"folders are placed\")\n\n        cmd_opts.add_option(cmdoptions.build_dir())\n\n        cmd_opts.add_option(cmdoptions.src())\n\n        cmd_opts.add_option(\n            '-U', '--upgrade',\n            dest='upgrade',\n            action='store_true',\n            help='Upgrade all specified packages to the newest available '\n                 'version. The handling of dependencies depends on the '\n                 'upgrade-strategy used.'\n        )\n\n        cmd_opts.add_option(\n            '--upgrade-strategy',\n            dest='upgrade_strategy',\n            default='eager',\n            choices=['only-if-needed', 'eager'],\n            help='Determines how dependency upgrading should be handled '\n                 '(default: %(default)s). '\n                 '\"eager\" - dependencies are upgraded regardless of '\n                 'whether the currently installed version satisfies the '\n                 'requirements of the upgraded package(s). '\n                 '\"only-if-needed\" -  are upgraded only when they do not '\n                 'satisfy the requirements of the upgraded package(s).'\n        )\n\n        cmd_opts.add_option(\n            '--force-reinstall',\n            dest='force_reinstall',\n            action='store_true',\n            help='When upgrading, reinstall all packages even if they are '\n                 'already up-to-date.')\n\n        cmd_opts.add_option(\n            '-I', '--ignore-installed',\n            dest='ignore_installed',\n            action='store_true',\n            help='Ignore the installed packages (reinstalling instead).')\n\n        cmd_opts.add_option(cmdoptions.ignore_requires_python())\n\n        cmd_opts.add_option(cmdoptions.install_options())\n        cmd_opts.add_option(cmdoptions.global_options())\n\n        cmd_opts.add_option(\n            \"--compile\",\n            action=\"store_true\",\n            dest=\"compile\",\n            default=True,\n            help=\"Compile py files to pyc\",\n        )\n\n        cmd_opts.add_option(\n            \"--no-compile\",\n            action=\"store_false\",\n            dest=\"compile\",\n            help=\"Do not compile py files to pyc\",\n        )\n\n        cmd_opts.add_option(cmdoptions.no_binary())\n        cmd_opts.add_option(cmdoptions.only_binary())\n        cmd_opts.add_option(cmdoptions.no_clean())\n        cmd_opts.add_option(cmdoptions.require_hashes())\n        cmd_opts.add_option(cmdoptions.progress_bar())\n\n        index_opts = cmdoptions.make_option_group(\n            cmdoptions.index_group,\n            self.parser,\n        )\n\n        self.parser.insert_option_group(0, index_opts)\n        self.parser.insert_option_group(0, cmd_opts)\n\n    def run(self, options, args):\n        cmdoptions.check_install_build_global(options)\n\n        if options.build_dir:\n            options.build_dir = os.path.abspath(options.build_dir)\n\n        options.src_dir = os.path.abspath(options.src_dir)\n        install_options = options.install_options or []\n        if options.use_user_site:\n            if options.prefix_path:\n                raise CommandError(\n                    \"Can not combine '--user' and '--prefix' as they imply \"\n                    \"different installation locations\"\n                )\n            if virtualenv_no_global():\n                raise InstallationError(\n                    \"Can not perform a '--user' install. User site-packages \"\n                    \"are not visible in this virtualenv.\"\n                )\n            install_options.append('--user')\n            install_options.append('--prefix=')\n\n        temp_target_dir = None\n        if options.target_dir:\n            options.ignore_installed = True\n            temp_target_dir = tempfile.mkdtemp()\n            options.target_dir = os.path.abspath(options.target_dir)\n            if (os.path.exists(options.target_dir) and not\n                    os.path.isdir(options.target_dir)):\n                raise CommandError(\n                    \"Target path exists but is not a directory, will not \"\n                    \"continue.\"\n                )\n            install_options.append('--home=' + temp_target_dir)\n\n        global_options = options.global_options or []\n\n        with self._build_session(options) as session:\n\n            finder = self._build_package_finder(options, session)\n            build_delete = (not (options.no_clean or options.build_dir))\n            wheel_cache = WheelCache(options.cache_dir, options.format_control)\n            if options.cache_dir and not check_path_owner(options.cache_dir):\n                logger.warning(\n                    \"The directory '%s' or its parent directory is not owned \"\n                    \"by the current user and caching wheels has been \"\n                    \"disabled. check the permissions and owner of that \"\n                    \"directory. If executing pip with sudo, you may want \"\n                    \"sudo's -H flag.\",\n                    options.cache_dir,\n                )\n                options.cache_dir = None\n\n            with BuildDirectory(options.build_dir,\n                                delete=build_delete) as build_dir:\n                requirement_set = RequirementSet(\n                    build_dir=build_dir,\n                    src_dir=options.src_dir,\n                    upgrade=options.upgrade,\n                    upgrade_strategy=options.upgrade_strategy,\n                    ignore_installed=options.ignore_installed,\n                    ignore_dependencies=options.ignore_dependencies,\n                    ignore_requires_python=options.ignore_requires_python,\n                    force_reinstall=options.force_reinstall,\n                    use_user_site=options.use_user_site,\n                    target_dir=temp_target_dir,\n                    session=session,\n                    pycompile=options.compile,\n                    isolated=options.isolated_mode,\n                    wheel_cache=wheel_cache,\n                    require_hashes=options.require_hashes,\n                    progress_bar=options.progress_bar,\n                )\n\n                self.populate_requirement_set(\n                    requirement_set, args, options, finder, session, self.name,\n                    wheel_cache\n                )\n\n                try:\n                    if (not wheel or not options.cache_dir):\n                        # on -d don't do complex things like building\n                        # wheels, and don't try to build wheels when wheel is\n                        # not installed.\n                        requirement_set.prepare_files(finder)\n                    else:\n                        # build wheels before install.\n                        wb = WheelBuilder(\n                            requirement_set,\n                            finder,\n                            build_options=[],\n                            global_options=[],\n                        )\n                        # Ignore the result: a failed wheel will be\n                        # installed from the sdist/vcs whatever.\n                        wb.build(autobuilding=True)\n\n                    requirement_set.install(\n                        install_options,\n                        global_options,\n                        root=options.root_path,\n                        prefix=options.prefix_path,\n                    )\n\n                    possible_lib_locations = get_lib_location_guesses(\n                        user=options.use_user_site,\n                        home=temp_target_dir,\n                        root=options.root_path,\n                        prefix=options.prefix_path,\n                        isolated=options.isolated_mode,\n                    )\n                    reqs = sorted(\n                        requirement_set.successfully_installed,\n                        key=operator.attrgetter('name'))\n                    items = []\n                    for req in reqs:\n                        item = req.name\n                        try:\n                            installed_version = get_installed_version(\n                                req.name, possible_lib_locations\n                            )\n                            if installed_version:\n                                item += '-' + installed_version\n                        except Exception:\n                            pass\n                        items.append(item)\n                    installed = ' '.join(items)\n                    if installed:\n                        logger.info('Successfully installed %s', installed)\n                except PreviousBuildDirError:\n                    options.no_clean = True\n                    raise\n                finally:\n                    # Clean up\n                    if not options.no_clean:\n                        requirement_set.cleanup_files()\n\n        if options.target_dir:\n            ensure_dir(options.target_dir)\n\n            # Checking both purelib and platlib directories for installed\n            # packages to be moved to target directory\n            lib_dir_list = []\n\n            purelib_dir = distutils_scheme('', home=temp_target_dir)['purelib']\n            platlib_dir = distutils_scheme('', home=temp_target_dir)['platlib']\n            data_dir = distutils_scheme('', home=temp_target_dir)['data']\n\n            if os.path.exists(purelib_dir):\n                lib_dir_list.append(purelib_dir)\n            if os.path.exists(platlib_dir) and platlib_dir != purelib_dir:\n                lib_dir_list.append(platlib_dir)\n            if os.path.exists(data_dir):\n                lib_dir_list.append(data_dir)\n\n            for lib_dir in lib_dir_list:\n                for item in os.listdir(lib_dir):\n                    if lib_dir == data_dir:\n                        ddir = os.path.join(data_dir, item)\n                        if any(s.startswith(ddir) for s in lib_dir_list[:-1]):\n                            continue\n                    target_item_dir = os.path.join(options.target_dir, item)\n                    if os.path.exists(target_item_dir):\n                        if not options.upgrade:\n                            logger.warning(\n                                'Target directory %s already exists. Specify '\n                                '--upgrade to force replacement.',\n                                target_item_dir\n                            )\n                            continue\n                        if os.path.islink(target_item_dir):\n                            logger.warning(\n                                'Target directory %s already exists and is '\n                                'a link. Pip will not automatically replace '\n                                'links, please remove if replacement is '\n                                'desired.',\n                                target_item_dir\n                            )\n                            continue\n                        if os.path.isdir(target_item_dir):\n                            shutil.rmtree(target_item_dir)\n                        else:\n                            os.remove(target_item_dir)\n\n                    shutil.move(\n                        os.path.join(lib_dir, item),\n                        target_item_dir\n                    )\n            shutil.rmtree(temp_target_dir)\n        return requirement_set\n\n\ndef get_lib_location_guesses(*args, **kwargs):\n    scheme = distutils_scheme('', *args, **kwargs)\n    return [scheme['purelib'], scheme['platlib']]\n", "path": "pip/commands/install.py"}], "after_files": [{"content": "from __future__ import absolute_import\n\nimport logging\nimport operator\nimport os\nimport tempfile\nimport shutil\ntry:\n    import wheel\nexcept ImportError:\n    wheel = None\n\nfrom pip.req import RequirementSet\nfrom pip.basecommand import RequirementCommand\nfrom pip.locations import virtualenv_no_global, distutils_scheme\nfrom pip.exceptions import (\n    InstallationError, CommandError, PreviousBuildDirError,\n)\nfrom pip import cmdoptions\nfrom pip.utils import ensure_dir, get_installed_version\nfrom pip.utils.build import BuildDirectory\nfrom pip.utils.filesystem import check_path_owner\nfrom pip.wheel import WheelCache, WheelBuilder\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass InstallCommand(RequirementCommand):\n    \"\"\"\n    Install packages from:\n\n    - PyPI (and other indexes) using requirement specifiers.\n    - VCS project urls.\n    - Local project directories.\n    - Local or remote source archives.\n\n    pip also supports installing from \"requirements files\", which provide\n    an easy way to specify a whole environment to be installed.\n    \"\"\"\n    name = 'install'\n\n    usage = \"\"\"\n      %prog [options] <requirement specifier> [package-index-options] ...\n      %prog [options] -r <requirements file> [package-index-options] ...\n      %prog [options] [-e] <vcs project url> ...\n      %prog [options] [-e] <local project path> ...\n      %prog [options] <archive url/path> ...\"\"\"\n\n    summary = 'Install packages.'\n\n    def __init__(self, *args, **kw):\n        super(InstallCommand, self).__init__(*args, **kw)\n\n        cmd_opts = self.cmd_opts\n\n        cmd_opts.add_option(cmdoptions.requirements())\n        cmd_opts.add_option(cmdoptions.constraints())\n        cmd_opts.add_option(cmdoptions.no_deps())\n        cmd_opts.add_option(cmdoptions.pre())\n\n        cmd_opts.add_option(cmdoptions.editable())\n        cmd_opts.add_option(\n            '-t', '--target',\n            dest='target_dir',\n            metavar='dir',\n            default=None,\n            help='Install packages into <dir>. '\n                 'By default this will not replace existing files/folders in '\n                 '<dir>. Use --upgrade to replace existing packages in <dir> '\n                 'with new versions.'\n        )\n        cmd_opts.add_option(\n            '--user',\n            dest='use_user_site',\n            action='store_true',\n            help=\"Install to the Python user install directory for your \"\n                 \"platform. Typically ~/.local/, or %APPDATA%\\\\Python on \"\n                 \"Windows. (See the Python documentation for site.USER_BASE \"\n                 \"for full details.)\")\n        cmd_opts.add_option(\n            '--root',\n            dest='root_path',\n            metavar='dir',\n            default=None,\n            help=\"Install everything relative to this alternate root \"\n                 \"directory.\")\n        cmd_opts.add_option(\n            '--prefix',\n            dest='prefix_path',\n            metavar='dir',\n            default=None,\n            help=\"Installation prefix where lib, bin and other top-level \"\n                 \"folders are placed\")\n\n        cmd_opts.add_option(cmdoptions.build_dir())\n\n        cmd_opts.add_option(cmdoptions.src())\n\n        cmd_opts.add_option(\n            '-U', '--upgrade',\n            dest='upgrade',\n            action='store_true',\n            help='Upgrade all specified packages to the newest available '\n                 'version. The handling of dependencies depends on the '\n                 'upgrade-strategy used.'\n        )\n\n        cmd_opts.add_option(\n            '--upgrade-strategy',\n            dest='upgrade_strategy',\n            default='eager',\n            choices=['only-if-needed', 'eager'],\n            help='Determines how dependency upgrading should be handled '\n                 '(default: %(default)s). '\n                 '\"eager\" - dependencies are upgraded regardless of '\n                 'whether the currently installed version satisfies the '\n                 'requirements of the upgraded package(s). '\n                 '\"only-if-needed\" -  are upgraded only when they do not '\n                 'satisfy the requirements of the upgraded package(s).'\n        )\n\n        cmd_opts.add_option(\n            '--force-reinstall',\n            dest='force_reinstall',\n            action='store_true',\n            help='When upgrading, reinstall all packages even if they are '\n                 'already up-to-date.')\n\n        cmd_opts.add_option(\n            '-I', '--ignore-installed',\n            dest='ignore_installed',\n            action='store_true',\n            help='Ignore the installed packages (reinstalling instead).')\n\n        cmd_opts.add_option(cmdoptions.ignore_requires_python())\n\n        cmd_opts.add_option(cmdoptions.install_options())\n        cmd_opts.add_option(cmdoptions.global_options())\n\n        cmd_opts.add_option(\n            \"--compile\",\n            action=\"store_true\",\n            dest=\"compile\",\n            default=True,\n            help=\"Compile Python source files to bytecode\",\n        )\n\n        cmd_opts.add_option(\n            \"--no-compile\",\n            action=\"store_false\",\n            dest=\"compile\",\n            help=\"Do not compile Python source files to bytecode\",\n        )\n\n        cmd_opts.add_option(cmdoptions.no_binary())\n        cmd_opts.add_option(cmdoptions.only_binary())\n        cmd_opts.add_option(cmdoptions.no_clean())\n        cmd_opts.add_option(cmdoptions.require_hashes())\n        cmd_opts.add_option(cmdoptions.progress_bar())\n\n        index_opts = cmdoptions.make_option_group(\n            cmdoptions.index_group,\n            self.parser,\n        )\n\n        self.parser.insert_option_group(0, index_opts)\n        self.parser.insert_option_group(0, cmd_opts)\n\n    def run(self, options, args):\n        cmdoptions.check_install_build_global(options)\n\n        if options.build_dir:\n            options.build_dir = os.path.abspath(options.build_dir)\n\n        options.src_dir = os.path.abspath(options.src_dir)\n        install_options = options.install_options or []\n        if options.use_user_site:\n            if options.prefix_path:\n                raise CommandError(\n                    \"Can not combine '--user' and '--prefix' as they imply \"\n                    \"different installation locations\"\n                )\n            if virtualenv_no_global():\n                raise InstallationError(\n                    \"Can not perform a '--user' install. User site-packages \"\n                    \"are not visible in this virtualenv.\"\n                )\n            install_options.append('--user')\n            install_options.append('--prefix=')\n\n        temp_target_dir = None\n        if options.target_dir:\n            options.ignore_installed = True\n            temp_target_dir = tempfile.mkdtemp()\n            options.target_dir = os.path.abspath(options.target_dir)\n            if (os.path.exists(options.target_dir) and not\n                    os.path.isdir(options.target_dir)):\n                raise CommandError(\n                    \"Target path exists but is not a directory, will not \"\n                    \"continue.\"\n                )\n            install_options.append('--home=' + temp_target_dir)\n\n        global_options = options.global_options or []\n\n        with self._build_session(options) as session:\n\n            finder = self._build_package_finder(options, session)\n            build_delete = (not (options.no_clean or options.build_dir))\n            wheel_cache = WheelCache(options.cache_dir, options.format_control)\n            if options.cache_dir and not check_path_owner(options.cache_dir):\n                logger.warning(\n                    \"The directory '%s' or its parent directory is not owned \"\n                    \"by the current user and caching wheels has been \"\n                    \"disabled. check the permissions and owner of that \"\n                    \"directory. If executing pip with sudo, you may want \"\n                    \"sudo's -H flag.\",\n                    options.cache_dir,\n                )\n                options.cache_dir = None\n\n            with BuildDirectory(options.build_dir,\n                                delete=build_delete) as build_dir:\n                requirement_set = RequirementSet(\n                    build_dir=build_dir,\n                    src_dir=options.src_dir,\n                    upgrade=options.upgrade,\n                    upgrade_strategy=options.upgrade_strategy,\n                    ignore_installed=options.ignore_installed,\n                    ignore_dependencies=options.ignore_dependencies,\n                    ignore_requires_python=options.ignore_requires_python,\n                    force_reinstall=options.force_reinstall,\n                    use_user_site=options.use_user_site,\n                    target_dir=temp_target_dir,\n                    session=session,\n                    pycompile=options.compile,\n                    isolated=options.isolated_mode,\n                    wheel_cache=wheel_cache,\n                    require_hashes=options.require_hashes,\n                    progress_bar=options.progress_bar,\n                )\n\n                self.populate_requirement_set(\n                    requirement_set, args, options, finder, session, self.name,\n                    wheel_cache\n                )\n\n                try:\n                    if (not wheel or not options.cache_dir):\n                        # on -d don't do complex things like building\n                        # wheels, and don't try to build wheels when wheel is\n                        # not installed.\n                        requirement_set.prepare_files(finder)\n                    else:\n                        # build wheels before install.\n                        wb = WheelBuilder(\n                            requirement_set,\n                            finder,\n                            build_options=[],\n                            global_options=[],\n                        )\n                        # Ignore the result: a failed wheel will be\n                        # installed from the sdist/vcs whatever.\n                        wb.build(autobuilding=True)\n\n                    requirement_set.install(\n                        install_options,\n                        global_options,\n                        root=options.root_path,\n                        prefix=options.prefix_path,\n                    )\n\n                    possible_lib_locations = get_lib_location_guesses(\n                        user=options.use_user_site,\n                        home=temp_target_dir,\n                        root=options.root_path,\n                        prefix=options.prefix_path,\n                        isolated=options.isolated_mode,\n                    )\n                    reqs = sorted(\n                        requirement_set.successfully_installed,\n                        key=operator.attrgetter('name'))\n                    items = []\n                    for req in reqs:\n                        item = req.name\n                        try:\n                            installed_version = get_installed_version(\n                                req.name, possible_lib_locations\n                            )\n                            if installed_version:\n                                item += '-' + installed_version\n                        except Exception:\n                            pass\n                        items.append(item)\n                    installed = ' '.join(items)\n                    if installed:\n                        logger.info('Successfully installed %s', installed)\n                except PreviousBuildDirError:\n                    options.no_clean = True\n                    raise\n                finally:\n                    # Clean up\n                    if not options.no_clean:\n                        requirement_set.cleanup_files()\n\n        if options.target_dir:\n            ensure_dir(options.target_dir)\n\n            # Checking both purelib and platlib directories for installed\n            # packages to be moved to target directory\n            lib_dir_list = []\n\n            purelib_dir = distutils_scheme('', home=temp_target_dir)['purelib']\n            platlib_dir = distutils_scheme('', home=temp_target_dir)['platlib']\n            data_dir = distutils_scheme('', home=temp_target_dir)['data']\n\n            if os.path.exists(purelib_dir):\n                lib_dir_list.append(purelib_dir)\n            if os.path.exists(platlib_dir) and platlib_dir != purelib_dir:\n                lib_dir_list.append(platlib_dir)\n            if os.path.exists(data_dir):\n                lib_dir_list.append(data_dir)\n\n            for lib_dir in lib_dir_list:\n                for item in os.listdir(lib_dir):\n                    if lib_dir == data_dir:\n                        ddir = os.path.join(data_dir, item)\n                        if any(s.startswith(ddir) for s in lib_dir_list[:-1]):\n                            continue\n                    target_item_dir = os.path.join(options.target_dir, item)\n                    if os.path.exists(target_item_dir):\n                        if not options.upgrade:\n                            logger.warning(\n                                'Target directory %s already exists. Specify '\n                                '--upgrade to force replacement.',\n                                target_item_dir\n                            )\n                            continue\n                        if os.path.islink(target_item_dir):\n                            logger.warning(\n                                'Target directory %s already exists and is '\n                                'a link. Pip will not automatically replace '\n                                'links, please remove if replacement is '\n                                'desired.',\n                                target_item_dir\n                            )\n                            continue\n                        if os.path.isdir(target_item_dir):\n                            shutil.rmtree(target_item_dir)\n                        else:\n                            os.remove(target_item_dir)\n\n                    shutil.move(\n                        os.path.join(lib_dir, item),\n                        target_item_dir\n                    )\n            shutil.rmtree(temp_target_dir)\n        return requirement_set\n\n\ndef get_lib_location_guesses(*args, **kwargs):\n    scheme = distutils_scheme('', *args, **kwargs)\n    return [scheme['purelib'], scheme['platlib']]\n", "path": "pip/commands/install.py"}]}