Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/pip/locations.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
| author | bcclaywell |
|---|---|
| date | Mon, 12 Oct 2015 17:43:33 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d67268158946 |
|---|---|
| 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 import tempfile | |
| 10 | |
| 11 from distutils import sysconfig | |
| 12 from distutils.command.install import install, SCHEME_KEYS | |
| 13 | |
| 14 from pip.compat import get_path_uid, WINDOWS | |
| 15 from pip.utils import appdirs | |
| 16 from pip import exceptions | |
| 17 | |
| 18 | |
| 19 # Hack for flake8 | |
| 20 install | |
| 21 | |
| 22 | |
| 23 # CA Bundle Locations | |
| 24 CA_BUNDLE_PATHS = [ | |
| 25 # Debian/Ubuntu/Gentoo etc. | |
| 26 "/etc/ssl/certs/ca-certificates.crt", | |
| 27 | |
| 28 # Fedora/RHEL | |
| 29 "/etc/pki/tls/certs/ca-bundle.crt", | |
| 30 | |
| 31 # OpenSUSE | |
| 32 "/etc/ssl/ca-bundle.pem", | |
| 33 | |
| 34 # OpenBSD | |
| 35 "/etc/ssl/cert.pem", | |
| 36 | |
| 37 # FreeBSD/DragonFly | |
| 38 "/usr/local/share/certs/ca-root-nss.crt", | |
| 39 | |
| 40 # Homebrew on OSX | |
| 41 "/usr/local/etc/openssl/cert.pem", | |
| 42 ] | |
| 43 | |
| 44 # Attempt to locate a CA Bundle that we can pass into requests, we have a list | |
| 45 # of possible ones from various systems. If we cannot find one then we'll set | |
| 46 # this to None so that we default to whatever requests is setup to handle. | |
| 47 # | |
| 48 # Note to Downstream: If you wish to disable this autodetection and simply use | |
| 49 # whatever requests does (likely you've already patched | |
| 50 # requests.certs.where()) then simply edit this line so | |
| 51 # that it reads ``CA_BUNDLE_PATH = None``. | |
| 52 CA_BUNDLE_PATH = next((x for x in CA_BUNDLE_PATHS if os.path.exists(x)), None) | |
| 53 | |
| 54 | |
| 55 # Application Directories | |
| 56 USER_CACHE_DIR = appdirs.user_cache_dir("pip") | |
| 57 | |
| 58 | |
| 59 DELETE_MARKER_MESSAGE = '''\ | |
| 60 This file is placed here by pip to indicate the source was put | |
| 61 here by pip. | |
| 62 | |
| 63 Once this package is successfully installed this source code will be | |
| 64 deleted (unless you remove this file). | |
| 65 ''' | |
| 66 PIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt' | |
| 67 | |
| 68 | |
| 69 def write_delete_marker_file(directory): | |
| 70 """ | |
| 71 Write the pip delete marker file into this directory. | |
| 72 """ | |
| 73 filepath = os.path.join(directory, PIP_DELETE_MARKER_FILENAME) | |
| 74 with open(filepath, 'w') as marker_fp: | |
| 75 marker_fp.write(DELETE_MARKER_MESSAGE) | |
| 76 | |
| 77 | |
| 78 def running_under_virtualenv(): | |
| 79 """ | |
| 80 Return True if we're running inside a virtualenv, False otherwise. | |
| 81 | |
| 82 """ | |
| 83 if hasattr(sys, 'real_prefix'): | |
| 84 return True | |
| 85 elif sys.prefix != getattr(sys, "base_prefix", sys.prefix): | |
| 86 return True | |
| 87 | |
| 88 return False | |
| 89 | |
| 90 | |
| 91 def virtualenv_no_global(): | |
| 92 """ | |
| 93 Return True if in a venv and no system site packages. | |
| 94 """ | |
| 95 # this mirrors the logic in virtualenv.py for locating the | |
| 96 # no-global-site-packages.txt file | |
| 97 site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) | |
| 98 no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') | |
| 99 if running_under_virtualenv() and os.path.isfile(no_global_file): | |
| 100 return True | |
| 101 | |
| 102 | |
| 103 def __get_username(): | |
| 104 """ Returns the effective username of the current process. """ | |
| 105 if WINDOWS: | |
| 106 return getpass.getuser() | |
| 107 import pwd | |
| 108 return pwd.getpwuid(os.geteuid()).pw_name | |
| 109 | |
| 110 | |
| 111 def _get_build_prefix(): | |
| 112 """ Returns a safe build_prefix """ | |
| 113 path = os.path.join( | |
| 114 tempfile.gettempdir(), | |
| 115 'pip_build_%s' % __get_username().replace(' ', '_') | |
| 116 ) | |
| 117 if WINDOWS: | |
| 118 """ on windows(tested on 7) temp dirs are isolated """ | |
| 119 return path | |
| 120 try: | |
| 121 os.mkdir(path) | |
| 122 write_delete_marker_file(path) | |
| 123 except OSError: | |
| 124 file_uid = None | |
| 125 try: | |
| 126 # raises OSError for symlinks | |
| 127 # https://github.com/pypa/pip/pull/935#discussion_r5307003 | |
| 128 file_uid = get_path_uid(path) | |
| 129 except OSError: | |
| 130 file_uid = None | |
| 131 | |
| 132 if file_uid != os.geteuid(): | |
| 133 msg = ( | |
| 134 "The temporary folder for building (%s) is either not owned by" | |
| 135 " you, or is a symlink." % path | |
| 136 ) | |
| 137 print(msg) | |
| 138 print( | |
| 139 "pip will not work until the temporary folder is either " | |
| 140 "deleted or is a real directory owned by your user account." | |
| 141 ) | |
| 142 raise exceptions.InstallationError(msg) | |
| 143 return path | |
| 144 | |
| 145 if running_under_virtualenv(): | |
| 146 build_prefix = os.path.join(sys.prefix, 'build') | |
| 147 src_prefix = os.path.join(sys.prefix, 'src') | |
| 148 else: | |
| 149 # Note: intentionally NOT using mkdtemp | |
| 150 # See https://github.com/pypa/pip/issues/906 for plan to move to mkdtemp | |
| 151 build_prefix = _get_build_prefix() | |
| 152 | |
| 153 # FIXME: keep src in cwd for now (it is not a temporary folder) | |
| 154 try: | |
| 155 src_prefix = os.path.join(os.getcwd(), 'src') | |
| 156 except OSError: | |
| 157 # In case the current working directory has been renamed or deleted | |
| 158 sys.exit( | |
| 159 "The folder you are executing pip from can no longer be found." | |
| 160 ) | |
| 161 | |
| 162 # under Mac OS X + virtualenv sys.prefix is not properly resolved | |
| 163 # it is something like /path/to/python/bin/.. | |
| 164 # Note: using realpath due to tmp dirs on OSX being symlinks | |
| 165 build_prefix = os.path.abspath(os.path.realpath(build_prefix)) | |
| 166 src_prefix = os.path.abspath(src_prefix) | |
| 167 | |
| 168 # FIXME doesn't account for venv linked to global site-packages | |
| 169 | |
| 170 site_packages = sysconfig.get_python_lib() | |
| 171 user_site = site.USER_SITE | |
| 172 user_dir = os.path.expanduser('~') | |
| 173 if WINDOWS: | |
| 174 bin_py = os.path.join(sys.prefix, 'Scripts') | |
| 175 bin_user = os.path.join(user_site, 'Scripts') | |
| 176 # buildout uses 'bin' on Windows too? | |
| 177 if not os.path.exists(bin_py): | |
| 178 bin_py = os.path.join(sys.prefix, 'bin') | |
| 179 bin_user = os.path.join(user_site, 'bin') | |
| 180 | |
| 181 config_basename = 'pip.ini' | |
| 182 | |
| 183 legacy_storage_dir = os.path.join(user_dir, 'pip') | |
| 184 legacy_config_file = os.path.join( | |
| 185 legacy_storage_dir, | |
| 186 config_basename, | |
| 187 ) | |
| 188 else: | |
| 189 bin_py = os.path.join(sys.prefix, 'bin') | |
| 190 bin_user = os.path.join(user_site, 'bin') | |
| 191 | |
| 192 config_basename = 'pip.conf' | |
| 193 | |
| 194 legacy_storage_dir = os.path.join(user_dir, '.pip') | |
| 195 legacy_config_file = os.path.join( | |
| 196 legacy_storage_dir, | |
| 197 config_basename, | |
| 198 ) | |
| 199 | |
| 200 # Forcing to use /usr/local/bin for standard Mac OS X framework installs | |
| 201 # Also log to ~/Library/Logs/ for use with the Console.app log viewer | |
| 202 if sys.platform[:6] == 'darwin' and sys.prefix[:16] == '/System/Library/': | |
| 203 bin_py = '/usr/local/bin' | |
| 204 | |
| 205 site_config_files = [ | |
| 206 os.path.join(path, config_basename) | |
| 207 for path in appdirs.site_config_dirs('pip') | |
| 208 ] | |
| 209 | |
| 210 | |
| 211 def distutils_scheme(dist_name, user=False, home=None, root=None, | |
| 212 isolated=False): | |
| 213 """ | |
| 214 Return a distutils install scheme | |
| 215 """ | |
| 216 from distutils.dist import Distribution | |
| 217 | |
| 218 scheme = {} | |
| 219 | |
| 220 if isolated: | |
| 221 extra_dist_args = {"script_args": ["--no-user-cfg"]} | |
| 222 else: | |
| 223 extra_dist_args = {} | |
| 224 dist_args = {'name': dist_name} | |
| 225 dist_args.update(extra_dist_args) | |
| 226 | |
| 227 d = Distribution(dist_args) | |
| 228 d.parse_config_files() | |
| 229 i = d.get_command_obj('install', create=True) | |
| 230 # NOTE: setting user or home has the side-effect of creating the home dir | |
| 231 # or user base for installations during finalize_options() | |
| 232 # ideally, we'd prefer a scheme class that has no side-effects. | |
| 233 i.user = user or i.user | |
| 234 i.home = home or i.home | |
| 235 i.root = root or i.root | |
| 236 i.finalize_options() | |
| 237 for key in SCHEME_KEYS: | |
| 238 scheme[key] = getattr(i, 'install_' + key) | |
| 239 | |
| 240 if i.install_lib is not None: | |
| 241 # install_lib takes precedence over purelib and platlib | |
| 242 scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib)) | |
| 243 | |
| 244 if running_under_virtualenv(): | |
| 245 scheme['headers'] = os.path.join( | |
| 246 sys.prefix, | |
| 247 'include', | |
| 248 'site', | |
| 249 'python' + sys.version[:3], | |
| 250 dist_name, | |
| 251 ) | |
| 252 | |
| 253 if root is not None: | |
| 254 scheme["headers"] = os.path.join( | |
| 255 root, | |
| 256 os.path.abspath(scheme["headers"])[1:], | |
| 257 ) | |
| 258 | |
| 259 return scheme |
