We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
installing from a wheel puts platform files into purelib, ignoring WHEEL Root-Is-Pure: False
When installing a package with C extensions, the platform specific shared libraries should be placed in the 'platform library' install path install_platlib.  On 64 bit linux, this would be /usr/lib64/python2.7/<...>

pip 7.0.3 incorrectly installs these platform specific shared binaries to the 'pure library' install path install_purelib.

This only happens when installing from a wheel file.  The wheel file contains a WHEEL configuration file which indicates the package is not pure (Root-Is-Pure: False), but pip appears to ignore that.

For example, if I were to:

  pip install python-qpid-proton

pip builds the extensions, generates a wheel in the cache, and installs from that wheel.
the shared libraries generated by the extension are placed here:
## $ pip show python-qpid-proton

Metadata-Version: 2.0
Name: python-qpid-proton
Version: 0.9.1.1
Summary: An AMQP based messaging library.
Home-page: http://qpid.apache.org/proton/
Author: Apache Qpid
Author-email: proton@qpid.apache.org
License: Apache Software License
Location: /usr/lib/python2.7/site-packages   <----------------------------

However, if I disable the cache (which skips the wheel building/install) the shared objects are correctly installed:

$ sudo pip --no-cache-dir install python-qpid-proton
## $ pip show python-qpid-proton

Metadata-Version: 1.1
Name: python-qpid-proton
Version: 0.9.1.1
Summary: An AMQP based messaging library.
Home-page: http://qpid.apache.org/proton/
Author: Apache Qpid
Author-email: proton@qpid.apache.org
License: Apache Software License
Location: /usr/lib64/python2.7/site-packages    <-------------------------------------------
Requires: 

It appears that the install_platlib value in the distribution scheme is being incorrectly overridden here

https://github.com/pypa/pip/blob/develop/pip/locations.py#L196

The Distribution instance created here:
https://github.com/pypa/pip/blob/develop/pip/locations.py#L181

is a dummy distribution in the case of a wheel.  It is not the actual distribution as defined by the packages setup.py file.  As such, it will not have any extensions configured.  

But when finalize_options is run on the dummy install instance, distutils checks to see if 'install_lib' is unset, and _if there are no extensions_ it set install_lib to the value of install_purelib.

Which means install_lib will never be set to platlib, even if the package contains binary extensions.
So when the installation path for a platform library is picked here:

https://github.com/pypa/pip/blob/develop/pip/wheel.py#L248

it has been incorrectly set to the pure lib directory.

https://github.com/pypa/pip/blob/develop/pip/wheel.py#L193


--- 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/locations.py`
Content:
```
1 """Locations where we look for configs, install stuff, etc"""
2 from __future__ import absolute_import
3 
4 import getpass
5 import os
6 import os.path
7 import site
8 import sys
9 
10 from distutils import sysconfig
11 from distutils.command.install import install, SCHEME_KEYS  # noqa
12 
13 from pip.compat import WINDOWS
14 from pip.utils import appdirs
15 
16 
17 # CA Bundle Locations
18 CA_BUNDLE_PATHS = [
19     # Debian/Ubuntu/Gentoo etc.
20     "/etc/ssl/certs/ca-certificates.crt",
21 
22     # Fedora/RHEL
23     "/etc/pki/tls/certs/ca-bundle.crt",
24 
25     # OpenSUSE
26     "/etc/ssl/ca-bundle.pem",
27 
28     # OpenBSD
29     "/etc/ssl/cert.pem",
30 
31     # FreeBSD/DragonFly
32     "/usr/local/share/certs/ca-root-nss.crt",
33 
34     # Homebrew on OSX
35     "/usr/local/etc/openssl/cert.pem",
36 ]
37 
38 # Attempt to locate a CA Bundle that we can pass into requests, we have a list
39 # of possible ones from various systems. If we cannot find one then we'll set
40 # this to None so that we default to whatever requests is setup to handle.
41 #
42 # Note to Downstream: If you wish to disable this autodetection and simply use
43 #                     whatever requests does (likely you've already patched
44 #                     requests.certs.where()) then simply edit this line so
45 #                     that it reads ``CA_BUNDLE_PATH = None``.
46 CA_BUNDLE_PATH = next((x for x in CA_BUNDLE_PATHS if os.path.exists(x)), None)
47 
48 
49 # Application Directories
50 USER_CACHE_DIR = appdirs.user_cache_dir("pip")
51 
52 
53 DELETE_MARKER_MESSAGE = '''\
54 This file is placed here by pip to indicate the source was put
55 here by pip.
56 
57 Once this package is successfully installed this source code will be
58 deleted (unless you remove this file).
59 '''
60 PIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt'
61 
62 
63 def write_delete_marker_file(directory):
64     """
65     Write the pip delete marker file into this directory.
66     """
67     filepath = os.path.join(directory, PIP_DELETE_MARKER_FILENAME)
68     with open(filepath, 'w') as marker_fp:
69         marker_fp.write(DELETE_MARKER_MESSAGE)
70 
71 
72 def running_under_virtualenv():
73     """
74     Return True if we're running inside a virtualenv, False otherwise.
75 
76     """
77     if hasattr(sys, 'real_prefix'):
78         return True
79     elif sys.prefix != getattr(sys, "base_prefix", sys.prefix):
80         return True
81 
82     return False
83 
84 
85 def virtualenv_no_global():
86     """
87     Return True if in a venv and no system site packages.
88     """
89     # this mirrors the logic in virtualenv.py for locating the
90     # no-global-site-packages.txt file
91     site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))
92     no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt')
93     if running_under_virtualenv() and os.path.isfile(no_global_file):
94         return True
95 
96 
97 def __get_username():
98     """ Returns the effective username of the current process. """
99     if WINDOWS:
100         return getpass.getuser()
101     import pwd
102     return pwd.getpwuid(os.geteuid()).pw_name
103 
104 
105 if running_under_virtualenv():
106     src_prefix = os.path.join(sys.prefix, 'src')
107 else:
108     # FIXME: keep src in cwd for now (it is not a temporary folder)
109     try:
110         src_prefix = os.path.join(os.getcwd(), 'src')
111     except OSError:
112         # In case the current working directory has been renamed or deleted
113         sys.exit(
114             "The folder you are executing pip from can no longer be found."
115         )
116 
117 # under Mac OS X + virtualenv sys.prefix is not properly resolved
118 # it is something like /path/to/python/bin/..
119 # Note: using realpath due to tmp dirs on OSX being symlinks
120 src_prefix = os.path.abspath(src_prefix)
121 
122 # FIXME doesn't account for venv linked to global site-packages
123 
124 site_packages = sysconfig.get_python_lib()
125 user_site = site.USER_SITE
126 user_dir = os.path.expanduser('~')
127 if WINDOWS:
128     bin_py = os.path.join(sys.prefix, 'Scripts')
129     bin_user = os.path.join(user_site, 'Scripts')
130     # buildout uses 'bin' on Windows too?
131     if not os.path.exists(bin_py):
132         bin_py = os.path.join(sys.prefix, 'bin')
133         bin_user = os.path.join(user_site, 'bin')
134 
135     config_basename = 'pip.ini'
136 
137     legacy_storage_dir = os.path.join(user_dir, 'pip')
138     legacy_config_file = os.path.join(
139         legacy_storage_dir,
140         config_basename,
141     )
142 else:
143     bin_py = os.path.join(sys.prefix, 'bin')
144     bin_user = os.path.join(user_site, 'bin')
145 
146     config_basename = 'pip.conf'
147 
148     legacy_storage_dir = os.path.join(user_dir, '.pip')
149     legacy_config_file = os.path.join(
150         legacy_storage_dir,
151         config_basename,
152     )
153 
154     # Forcing to use /usr/local/bin for standard Mac OS X framework installs
155     # Also log to ~/Library/Logs/ for use with the Console.app log viewer
156     if sys.platform[:6] == 'darwin' and sys.prefix[:16] == '/System/Library/':
157         bin_py = '/usr/local/bin'
158 
159 site_config_files = [
160     os.path.join(path, config_basename)
161     for path in appdirs.site_config_dirs('pip')
162 ]
163 
164 
165 def distutils_scheme(dist_name, user=False, home=None, root=None,
166                      isolated=False):
167     """
168     Return a distutils install scheme
169     """
170     from distutils.dist import Distribution
171 
172     scheme = {}
173 
174     if isolated:
175         extra_dist_args = {"script_args": ["--no-user-cfg"]}
176     else:
177         extra_dist_args = {}
178     dist_args = {'name': dist_name}
179     dist_args.update(extra_dist_args)
180 
181     d = Distribution(dist_args)
182     d.parse_config_files()
183     i = d.get_command_obj('install', create=True)
184     # NOTE: setting user or home has the side-effect of creating the home dir
185     # or user base for installations during finalize_options()
186     # ideally, we'd prefer a scheme class that has no side-effects.
187     i.user = user or i.user
188     if user:
189         i.prefix = ""
190     i.home = home or i.home
191     i.root = root or i.root
192     i.finalize_options()
193     for key in SCHEME_KEYS:
194         scheme[key] = getattr(i, 'install_' + key)
195 
196     if i.install_lib is not None:
197         # install_lib takes precedence over purelib and platlib
198         scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))
199 
200     if running_under_virtualenv():
201         scheme['headers'] = os.path.join(
202             sys.prefix,
203             'include',
204             'site',
205             'python' + sys.version[:3],
206             dist_name,
207         )
208 
209         if root is not None:
210             scheme["headers"] = os.path.join(
211                 root,
212                 os.path.abspath(scheme["headers"])[1:],
213             )
214 
215     return scheme
216
```
--- 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/locations.py b/pip/locations.py
--- a/pip/locations.py
+++ b/pip/locations.py
@@ -237,8 +237,12 @@
     for key in SCHEME_KEYS:
         scheme[key] = getattr(i, 'install_' + key)
 
-    if i.install_lib is not None:
-        # install_lib takes precedence over purelib and platlib
+    # install_lib specified in setup.cfg should install *everything*
+    # into there (i.e. it takes precedence over both purelib and
+    # platlib).  Note, i.install_lib is *always* set after
+    # finalize_options(); we only want to override here if the user
+    # has explicitly requested it hence going back to the config
+    if 'install_lib' in d.get_option_dict('install'):
         scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))
 
     if running_under_virtualenv():

{"golden_diff": "diff --git a/pip/locations.py b/pip/locations.py\n--- a/pip/locations.py\n+++ b/pip/locations.py\n@@ -237,8 +237,12 @@\n     for key in SCHEME_KEYS:\n         scheme[key] = getattr(i, 'install_' + key)\n \n-    if i.install_lib is not None:\n-        # install_lib takes precedence over purelib and platlib\n+    # install_lib specified in setup.cfg should install *everything*\n+    # into there (i.e. it takes precedence over both purelib and\n+    # platlib).  Note, i.install_lib is *always* set after\n+    # finalize_options(); we only want to override here if the user\n+    # has explicitly requested it hence going back to the config\n+    if 'install_lib' in d.get_option_dict('install'):\n         scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))\n \n     if running_under_virtualenv():\n", "issue": "installing from a wheel puts platform files into purelib, ignoring WHEEL Root-Is-Pure: False\nWhen installing a package with C extensions, the platform specific shared libraries should be placed in the 'platform library' install path install_platlib.  On 64 bit linux, this would be /usr/lib64/python2.7/<...>\n\npip 7.0.3 incorrectly installs these platform specific shared binaries to the 'pure library' install path install_purelib.\n\nThis only happens when installing from a wheel file.  The wheel file contains a WHEEL configuration file which indicates the package is not pure (Root-Is-Pure: False), but pip appears to ignore that.\n\nFor example, if I were to:\n\n  pip install python-qpid-proton\n\npip builds the extensions, generates a wheel in the cache, and installs from that wheel.\nthe shared libraries generated by the extension are placed here:\n## $ pip show python-qpid-proton\n\nMetadata-Version: 2.0\nName: python-qpid-proton\nVersion: 0.9.1.1\nSummary: An AMQP based messaging library.\nHome-page: http://qpid.apache.org/proton/\nAuthor: Apache Qpid\nAuthor-email: proton@qpid.apache.org\nLicense: Apache Software License\nLocation: /usr/lib/python2.7/site-packages   <----------------------------\n\nHowever, if I disable the cache (which skips the wheel building/install) the shared objects are correctly installed:\n\n$ sudo pip --no-cache-dir install python-qpid-proton\n## $ pip show python-qpid-proton\n\nMetadata-Version: 1.1\nName: python-qpid-proton\nVersion: 0.9.1.1\nSummary: An AMQP based messaging library.\nHome-page: http://qpid.apache.org/proton/\nAuthor: Apache Qpid\nAuthor-email: proton@qpid.apache.org\nLicense: Apache Software License\nLocation: /usr/lib64/python2.7/site-packages    <-------------------------------------------\nRequires: \n\nIt appears that the install_platlib value in the distribution scheme is being incorrectly overridden here\n\nhttps://github.com/pypa/pip/blob/develop/pip/locations.py#L196\n\nThe Distribution instance created here:\nhttps://github.com/pypa/pip/blob/develop/pip/locations.py#L181\n\nis a dummy distribution in the case of a wheel.  It is not the actual distribution as defined by the packages setup.py file.  As such, it will not have any extensions configured.  \n\nBut when finalize_options is run on the dummy install instance, distutils checks to see if 'install_lib' is unset, and _if there are no extensions_ it set install_lib to the value of install_purelib.\n\nWhich means install_lib will never be set to platlib, even if the package contains binary extensions.\nSo when the installation path for a platform library is picked here:\n\nhttps://github.com/pypa/pip/blob/develop/pip/wheel.py#L248\n\nit has been incorrectly set to the pure lib directory.\n\nhttps://github.com/pypa/pip/blob/develop/pip/wheel.py#L193\n\n", "before_files": [{"content": "\"\"\"Locations where we look for configs, install stuff, etc\"\"\"\nfrom __future__ import absolute_import\n\nimport getpass\nimport os\nimport os.path\nimport site\nimport sys\n\nfrom distutils import sysconfig\nfrom distutils.command.install import install, SCHEME_KEYS  # noqa\n\nfrom pip.compat import WINDOWS\nfrom pip.utils import appdirs\n\n\n# CA Bundle Locations\nCA_BUNDLE_PATHS = [\n    # Debian/Ubuntu/Gentoo etc.\n    \"/etc/ssl/certs/ca-certificates.crt\",\n\n    # Fedora/RHEL\n    \"/etc/pki/tls/certs/ca-bundle.crt\",\n\n    # OpenSUSE\n    \"/etc/ssl/ca-bundle.pem\",\n\n    # OpenBSD\n    \"/etc/ssl/cert.pem\",\n\n    # FreeBSD/DragonFly\n    \"/usr/local/share/certs/ca-root-nss.crt\",\n\n    # Homebrew on OSX\n    \"/usr/local/etc/openssl/cert.pem\",\n]\n\n# Attempt to locate a CA Bundle that we can pass into requests, we have a list\n# of possible ones from various systems. If we cannot find one then we'll set\n# this to None so that we default to whatever requests is setup to handle.\n#\n# Note to Downstream: If you wish to disable this autodetection and simply use\n#                     whatever requests does (likely you've already patched\n#                     requests.certs.where()) then simply edit this line so\n#                     that it reads ``CA_BUNDLE_PATH = None``.\nCA_BUNDLE_PATH = next((x for x in CA_BUNDLE_PATHS if os.path.exists(x)), None)\n\n\n# Application Directories\nUSER_CACHE_DIR = appdirs.user_cache_dir(\"pip\")\n\n\nDELETE_MARKER_MESSAGE = '''\\\nThis file is placed here by pip to indicate the source was put\nhere by pip.\n\nOnce this package is successfully installed this source code will be\ndeleted (unless you remove this file).\n'''\nPIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt'\n\n\ndef write_delete_marker_file(directory):\n    \"\"\"\n    Write the pip delete marker file into this directory.\n    \"\"\"\n    filepath = os.path.join(directory, PIP_DELETE_MARKER_FILENAME)\n    with open(filepath, 'w') as marker_fp:\n        marker_fp.write(DELETE_MARKER_MESSAGE)\n\n\ndef running_under_virtualenv():\n    \"\"\"\n    Return True if we're running inside a virtualenv, False otherwise.\n\n    \"\"\"\n    if hasattr(sys, 'real_prefix'):\n        return True\n    elif sys.prefix != getattr(sys, \"base_prefix\", sys.prefix):\n        return True\n\n    return False\n\n\ndef virtualenv_no_global():\n    \"\"\"\n    Return True if in a venv and no system site packages.\n    \"\"\"\n    # this mirrors the logic in virtualenv.py for locating the\n    # no-global-site-packages.txt file\n    site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))\n    no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt')\n    if running_under_virtualenv() and os.path.isfile(no_global_file):\n        return True\n\n\ndef __get_username():\n    \"\"\" Returns the effective username of the current process. \"\"\"\n    if WINDOWS:\n        return getpass.getuser()\n    import pwd\n    return pwd.getpwuid(os.geteuid()).pw_name\n\n\nif running_under_virtualenv():\n    src_prefix = os.path.join(sys.prefix, 'src')\nelse:\n    # FIXME: keep src in cwd for now (it is not a temporary folder)\n    try:\n        src_prefix = os.path.join(os.getcwd(), 'src')\n    except OSError:\n        # In case the current working directory has been renamed or deleted\n        sys.exit(\n            \"The folder you are executing pip from can no longer be found.\"\n        )\n\n# under Mac OS X + virtualenv sys.prefix is not properly resolved\n# it is something like /path/to/python/bin/..\n# Note: using realpath due to tmp dirs on OSX being symlinks\nsrc_prefix = os.path.abspath(src_prefix)\n\n# FIXME doesn't account for venv linked to global site-packages\n\nsite_packages = sysconfig.get_python_lib()\nuser_site = site.USER_SITE\nuser_dir = os.path.expanduser('~')\nif WINDOWS:\n    bin_py = os.path.join(sys.prefix, 'Scripts')\n    bin_user = os.path.join(user_site, 'Scripts')\n    # buildout uses 'bin' on Windows too?\n    if not os.path.exists(bin_py):\n        bin_py = os.path.join(sys.prefix, 'bin')\n        bin_user = os.path.join(user_site, 'bin')\n\n    config_basename = 'pip.ini'\n\n    legacy_storage_dir = os.path.join(user_dir, 'pip')\n    legacy_config_file = os.path.join(\n        legacy_storage_dir,\n        config_basename,\n    )\nelse:\n    bin_py = os.path.join(sys.prefix, 'bin')\n    bin_user = os.path.join(user_site, 'bin')\n\n    config_basename = 'pip.conf'\n\n    legacy_storage_dir = os.path.join(user_dir, '.pip')\n    legacy_config_file = os.path.join(\n        legacy_storage_dir,\n        config_basename,\n    )\n\n    # Forcing to use /usr/local/bin for standard Mac OS X framework installs\n    # Also log to ~/Library/Logs/ for use with the Console.app log viewer\n    if sys.platform[:6] == 'darwin' and sys.prefix[:16] == '/System/Library/':\n        bin_py = '/usr/local/bin'\n\nsite_config_files = [\n    os.path.join(path, config_basename)\n    for path in appdirs.site_config_dirs('pip')\n]\n\n\ndef distutils_scheme(dist_name, user=False, home=None, root=None,\n                     isolated=False):\n    \"\"\"\n    Return a distutils install scheme\n    \"\"\"\n    from distutils.dist import Distribution\n\n    scheme = {}\n\n    if isolated:\n        extra_dist_args = {\"script_args\": [\"--no-user-cfg\"]}\n    else:\n        extra_dist_args = {}\n    dist_args = {'name': dist_name}\n    dist_args.update(extra_dist_args)\n\n    d = Distribution(dist_args)\n    d.parse_config_files()\n    i = d.get_command_obj('install', create=True)\n    # NOTE: setting user or home has the side-effect of creating the home dir\n    # or user base for installations during finalize_options()\n    # ideally, we'd prefer a scheme class that has no side-effects.\n    i.user = user or i.user\n    if user:\n        i.prefix = \"\"\n    i.home = home or i.home\n    i.root = root or i.root\n    i.finalize_options()\n    for key in SCHEME_KEYS:\n        scheme[key] = getattr(i, 'install_' + key)\n\n    if i.install_lib is not None:\n        # install_lib takes precedence over purelib and platlib\n        scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))\n\n    if running_under_virtualenv():\n        scheme['headers'] = os.path.join(\n            sys.prefix,\n            'include',\n            'site',\n            'python' + sys.version[:3],\n            dist_name,\n        )\n\n        if root is not None:\n            scheme[\"headers\"] = os.path.join(\n                root,\n                os.path.abspath(scheme[\"headers\"])[1:],\n            )\n\n    return scheme\n", "path": "pip/locations.py"}], "after_files": [{"content": "\"\"\"Locations where we look for configs, install stuff, etc\"\"\"\nfrom __future__ import absolute_import\n\nimport getpass\nimport os\nimport os.path\nimport site\nimport sys\nimport tempfile\n\nfrom distutils import sysconfig\nfrom distutils.command.install import install, SCHEME_KEYS\n\nfrom pip.compat import get_path_uid, WINDOWS\nfrom pip.utils import appdirs\nfrom pip import exceptions\n\n\n# Hack for flake8\ninstall\n\n\n# CA Bundle Locations\nCA_BUNDLE_PATHS = [\n    # Debian/Ubuntu/Gentoo etc.\n    \"/etc/ssl/certs/ca-certificates.crt\",\n\n    # Fedora/RHEL\n    \"/etc/pki/tls/certs/ca-bundle.crt\",\n\n    # OpenSUSE\n    \"/etc/ssl/ca-bundle.pem\",\n\n    # OpenBSD\n    \"/etc/ssl/cert.pem\",\n\n    # FreeBSD/DragonFly\n    \"/usr/local/share/certs/ca-root-nss.crt\",\n\n    # Homebrew on OSX\n    \"/usr/local/etc/openssl/cert.pem\",\n]\n\n# Attempt to locate a CA Bundle that we can pass into requests, we have a list\n# of possible ones from various systems. If we cannot find one then we'll set\n# this to None so that we default to whatever requests is setup to handle.\n#\n# Note to Downstream: If you wish to disable this autodetection and simply use\n#                     whatever requests does (likely you've already patched\n#                     requests.certs.where()) then simply edit this line so\n#                     that it reads ``CA_BUNDLE_PATH = None``.\nCA_BUNDLE_PATH = next((x for x in CA_BUNDLE_PATHS if os.path.exists(x)), None)\n\n\n# Application Directories\nUSER_CACHE_DIR = appdirs.user_cache_dir(\"pip\")\n\n\nDELETE_MARKER_MESSAGE = '''\\\nThis file is placed here by pip to indicate the source was put\nhere by pip.\n\nOnce this package is successfully installed this source code will be\ndeleted (unless you remove this file).\n'''\nPIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt'\n\n\ndef write_delete_marker_file(directory):\n    \"\"\"\n    Write the pip delete marker file into this directory.\n    \"\"\"\n    filepath = os.path.join(directory, PIP_DELETE_MARKER_FILENAME)\n    with open(filepath, 'w') as marker_fp:\n        marker_fp.write(DELETE_MARKER_MESSAGE)\n\n\ndef running_under_virtualenv():\n    \"\"\"\n    Return True if we're running inside a virtualenv, False otherwise.\n\n    \"\"\"\n    if hasattr(sys, 'real_prefix'):\n        return True\n    elif sys.prefix != getattr(sys, \"base_prefix\", sys.prefix):\n        return True\n\n    return False\n\n\ndef virtualenv_no_global():\n    \"\"\"\n    Return True if in a venv and no system site packages.\n    \"\"\"\n    # this mirrors the logic in virtualenv.py for locating the\n    # no-global-site-packages.txt file\n    site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))\n    no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt')\n    if running_under_virtualenv() and os.path.isfile(no_global_file):\n        return True\n\n\ndef __get_username():\n    \"\"\" Returns the effective username of the current process. \"\"\"\n    if WINDOWS:\n        return getpass.getuser()\n    import pwd\n    return pwd.getpwuid(os.geteuid()).pw_name\n\n\ndef _get_build_prefix():\n    \"\"\" Returns a safe build_prefix \"\"\"\n    path = os.path.join(\n        tempfile.gettempdir(),\n        'pip_build_%s' % __get_username().replace(' ', '_')\n    )\n    if WINDOWS:\n        \"\"\" on windows(tested on 7) temp dirs are isolated \"\"\"\n        return path\n    try:\n        os.mkdir(path)\n        write_delete_marker_file(path)\n    except OSError:\n        file_uid = None\n        try:\n            # raises OSError for symlinks\n            # https://github.com/pypa/pip/pull/935#discussion_r5307003\n            file_uid = get_path_uid(path)\n        except OSError:\n            file_uid = None\n\n        if file_uid != os.geteuid():\n            msg = (\n                \"The temporary folder for building (%s) is either not owned by\"\n                \" you, or is a symlink.\" % path\n            )\n            print(msg)\n            print(\n                \"pip will not work until the temporary folder is either \"\n                \"deleted or is a real directory owned by your user account.\"\n            )\n            raise exceptions.InstallationError(msg)\n    return path\n\nif running_under_virtualenv():\n    build_prefix = os.path.join(sys.prefix, 'build')\n    src_prefix = os.path.join(sys.prefix, 'src')\nelse:\n    # Note: intentionally NOT using mkdtemp\n    # See https://github.com/pypa/pip/issues/906 for plan to move to mkdtemp\n    build_prefix = _get_build_prefix()\n\n    # FIXME: keep src in cwd for now (it is not a temporary folder)\n    try:\n        src_prefix = os.path.join(os.getcwd(), 'src')\n    except OSError:\n        # In case the current working directory has been renamed or deleted\n        sys.exit(\n            \"The folder you are executing pip from can no longer be found.\"\n        )\n\n# under Mac OS X + virtualenv sys.prefix is not properly resolved\n# it is something like /path/to/python/bin/..\n# Note: using realpath due to tmp dirs on OSX being symlinks\nbuild_prefix = os.path.abspath(os.path.realpath(build_prefix))\nsrc_prefix = os.path.abspath(src_prefix)\n\n# FIXME doesn't account for venv linked to global site-packages\n\nsite_packages = sysconfig.get_python_lib()\nuser_site = site.USER_SITE\nuser_dir = os.path.expanduser('~')\nif WINDOWS:\n    bin_py = os.path.join(sys.prefix, 'Scripts')\n    bin_user = os.path.join(user_site, 'Scripts')\n    # buildout uses 'bin' on Windows too?\n    if not os.path.exists(bin_py):\n        bin_py = os.path.join(sys.prefix, 'bin')\n        bin_user = os.path.join(user_site, 'bin')\n\n    config_basename = 'pip.ini'\n\n    legacy_storage_dir = os.path.join(user_dir, 'pip')\n    legacy_config_file = os.path.join(\n        legacy_storage_dir,\n        config_basename,\n    )\nelse:\n    bin_py = os.path.join(sys.prefix, 'bin')\n    bin_user = os.path.join(user_site, 'bin')\n\n    config_basename = 'pip.conf'\n\n    legacy_storage_dir = os.path.join(user_dir, '.pip')\n    legacy_config_file = os.path.join(\n        legacy_storage_dir,\n        config_basename,\n    )\n\n    # Forcing to use /usr/local/bin for standard Mac OS X framework installs\n    # Also log to ~/Library/Logs/ for use with the Console.app log viewer\n    if sys.platform[:6] == 'darwin' and sys.prefix[:16] == '/System/Library/':\n        bin_py = '/usr/local/bin'\n\nsite_config_files = [\n    os.path.join(path, config_basename)\n    for path in appdirs.site_config_dirs('pip')\n]\n\n\ndef distutils_scheme(dist_name, user=False, home=None, root=None,\n                     isolated=False):\n    \"\"\"\n    Return a distutils install scheme\n    \"\"\"\n    from distutils.dist import Distribution\n\n    scheme = {}\n\n    if isolated:\n        extra_dist_args = {\"script_args\": [\"--no-user-cfg\"]}\n    else:\n        extra_dist_args = {}\n    dist_args = {'name': dist_name}\n    dist_args.update(extra_dist_args)\n\n    d = Distribution(dist_args)\n    d.parse_config_files()\n    i = d.get_command_obj('install', create=True)\n    # NOTE: setting user or home has the side-effect of creating the home dir\n    # or user base for installations during finalize_options()\n    # ideally, we'd prefer a scheme class that has no side-effects.\n    i.user = user or i.user\n    i.home = home or i.home\n    i.root = root or i.root\n    i.finalize_options()\n    for key in SCHEME_KEYS:\n        scheme[key] = getattr(i, 'install_' + key)\n\n    # install_lib specified in setup.cfg should install *everything*\n    # into there (i.e. it takes precedence over both purelib and\n    # platlib).  Note, i.install_lib is *always* set after\n    # finalize_options(); we only want to override here if the user\n    # has explicitly requested it hence going back to the config\n    if 'install_lib' in d.get_option_dict('install'):\n        scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))\n\n    if running_under_virtualenv():\n        scheme['headers'] = os.path.join(\n            sys.prefix,\n            'include',\n            'site',\n            'python' + sys.version[:3],\n            dist_name,\n        )\n\n        if root is not None:\n            scheme[\"headers\"] = os.path.join(\n                root,\n                os.path.abspath(scheme[\"headers\"])[1:],\n            )\n\n    return scheme\n", "path": "pip/locations.py"}]}