comparison planemo/lib/python3.7/site-packages/pip/_internal/locations.py @ 1:56ad4e20f292 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:32:28 -0400
parents
children
comparison
equal deleted inserted replaced
0:d30785e31577 1:56ad4e20f292
1 """Locations where we look for configs, install stuff, etc"""
2 from __future__ import absolute_import
3
4 import os
5 import os.path
6 import platform
7 import site
8 import sys
9 import sysconfig
10 from distutils import sysconfig as distutils_sysconfig
11 from distutils.command.install import SCHEME_KEYS # type: ignore
12
13 from pip._internal.utils import appdirs
14 from pip._internal.utils.compat import WINDOWS
15 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
16 from pip._internal.utils.virtualenv import running_under_virtualenv
17
18 if MYPY_CHECK_RUNNING:
19 from typing import Any, Union, Dict, List, Optional
20
21
22 # Application Directories
23 USER_CACHE_DIR = appdirs.user_cache_dir("pip")
24
25
26 def get_src_prefix():
27 if running_under_virtualenv():
28 src_prefix = os.path.join(sys.prefix, 'src')
29 else:
30 # FIXME: keep src in cwd for now (it is not a temporary folder)
31 try:
32 src_prefix = os.path.join(os.getcwd(), 'src')
33 except OSError:
34 # In case the current working directory has been renamed or deleted
35 sys.exit(
36 "The folder you are executing pip from can no longer be found."
37 )
38
39 # under macOS + virtualenv sys.prefix is not properly resolved
40 # it is something like /path/to/python/bin/..
41 return os.path.abspath(src_prefix)
42
43
44 # FIXME doesn't account for venv linked to global site-packages
45
46 site_packages = sysconfig.get_path("purelib") # type: Optional[str]
47
48 # This is because of a bug in PyPy's sysconfig module, see
49 # https://bitbucket.org/pypy/pypy/issues/2506/sysconfig-returns-incorrect-paths
50 # for more information.
51 if platform.python_implementation().lower() == "pypy":
52 site_packages = distutils_sysconfig.get_python_lib()
53 try:
54 # Use getusersitepackages if this is present, as it ensures that the
55 # value is initialised properly.
56 user_site = site.getusersitepackages()
57 except AttributeError:
58 user_site = site.USER_SITE
59
60 if WINDOWS:
61 bin_py = os.path.join(sys.prefix, 'Scripts')
62 bin_user = os.path.join(user_site, 'Scripts')
63 # buildout uses 'bin' on Windows too?
64 if not os.path.exists(bin_py):
65 bin_py = os.path.join(sys.prefix, 'bin')
66 bin_user = os.path.join(user_site, 'bin')
67 else:
68 bin_py = os.path.join(sys.prefix, 'bin')
69 bin_user = os.path.join(user_site, 'bin')
70
71 # Forcing to use /usr/local/bin for standard macOS framework installs
72 # Also log to ~/Library/Logs/ for use with the Console.app log viewer
73 if sys.platform[:6] == 'darwin' and sys.prefix[:16] == '/System/Library/':
74 bin_py = '/usr/local/bin'
75
76
77 def distutils_scheme(dist_name, user=False, home=None, root=None,
78 isolated=False, prefix=None):
79 # type:(str, bool, str, str, bool, str) -> dict
80 """
81 Return a distutils install scheme
82 """
83 from distutils.dist import Distribution
84
85 scheme = {}
86
87 if isolated:
88 extra_dist_args = {"script_args": ["--no-user-cfg"]}
89 else:
90 extra_dist_args = {}
91 dist_args = {'name': dist_name} # type: Dict[str, Union[str, List[str]]]
92 dist_args.update(extra_dist_args)
93
94 d = Distribution(dist_args)
95 # Ignoring, typeshed issue reported python/typeshed/issues/2567
96 d.parse_config_files()
97 # NOTE: Ignoring type since mypy can't find attributes on 'Command'
98 i = d.get_command_obj('install', create=True) # type: Any
99 assert i is not None
100 # NOTE: setting user or home has the side-effect of creating the home dir
101 # or user base for installations during finalize_options()
102 # ideally, we'd prefer a scheme class that has no side-effects.
103 assert not (user and prefix), "user={} prefix={}".format(user, prefix)
104 assert not (home and prefix), "home={} prefix={}".format(home, prefix)
105 i.user = user or i.user
106 if user or home:
107 i.prefix = ""
108 i.prefix = prefix or i.prefix
109 i.home = home or i.home
110 i.root = root or i.root
111 i.finalize_options()
112 for key in SCHEME_KEYS:
113 scheme[key] = getattr(i, 'install_' + key)
114
115 # install_lib specified in setup.cfg should install *everything*
116 # into there (i.e. it takes precedence over both purelib and
117 # platlib). Note, i.install_lib is *always* set after
118 # finalize_options(); we only want to override here if the user
119 # has explicitly requested it hence going back to the config
120
121 # Ignoring, typeshed issue reported python/typeshed/issues/2567
122 if 'install_lib' in d.get_option_dict('install'): # type: ignore
123 scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))
124
125 if running_under_virtualenv():
126 scheme['headers'] = os.path.join(
127 sys.prefix,
128 'include',
129 'site',
130 'python' + sys.version[:3],
131 dist_name,
132 )
133
134 if root is not None:
135 path_no_drive = os.path.splitdrive(
136 os.path.abspath(scheme["headers"]))[1]
137 scheme["headers"] = os.path.join(
138 root,
139 path_no_drive[1:],
140 )
141
142 return scheme