comparison env/lib/python3.9/site-packages/pip/_internal/utils/setuptools_build.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import sys
2
3 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
4
5 if MYPY_CHECK_RUNNING:
6 from typing import List, Optional, Sequence
7
8 # Shim to wrap setup.py invocation with setuptools
9 #
10 # We set sys.argv[0] to the path to the underlying setup.py file so
11 # setuptools / distutils don't take the path to the setup.py to be "-c" when
12 # invoking via the shim. This avoids e.g. the following manifest_maker
13 # warning: "warning: manifest_maker: standard file '-c' not found".
14 _SETUPTOOLS_SHIM = (
15 "import sys, setuptools, tokenize; sys.argv[0] = {0!r}; __file__={0!r};"
16 "f=getattr(tokenize, 'open', open)(__file__);"
17 "code=f.read().replace('\\r\\n', '\\n');"
18 "f.close();"
19 "exec(compile(code, __file__, 'exec'))"
20 )
21
22
23 def make_setuptools_shim_args(
24 setup_py_path, # type: str
25 global_options=None, # type: Sequence[str]
26 no_user_config=False, # type: bool
27 unbuffered_output=False # type: bool
28 ):
29 # type: (...) -> List[str]
30 """
31 Get setuptools command arguments with shim wrapped setup file invocation.
32
33 :param setup_py_path: The path to setup.py to be wrapped.
34 :param global_options: Additional global options.
35 :param no_user_config: If True, disables personal user configuration.
36 :param unbuffered_output: If True, adds the unbuffered switch to the
37 argument list.
38 """
39 args = [sys.executable]
40 if unbuffered_output:
41 args += ["-u"]
42 args += ["-c", _SETUPTOOLS_SHIM.format(setup_py_path)]
43 if global_options:
44 args += global_options
45 if no_user_config:
46 args += ["--no-user-cfg"]
47 return args
48
49
50 def make_setuptools_bdist_wheel_args(
51 setup_py_path, # type: str
52 global_options, # type: Sequence[str]
53 build_options, # type: Sequence[str]
54 destination_dir, # type: str
55 ):
56 # type: (...) -> List[str]
57 # NOTE: Eventually, we'd want to also -S to the flags here, when we're
58 # isolating. Currently, it breaks Python in virtualenvs, because it
59 # relies on site.py to find parts of the standard library outside the
60 # virtualenv.
61 args = make_setuptools_shim_args(
62 setup_py_path,
63 global_options=global_options,
64 unbuffered_output=True
65 )
66 args += ["bdist_wheel", "-d", destination_dir]
67 args += build_options
68 return args
69
70
71 def make_setuptools_clean_args(
72 setup_py_path, # type: str
73 global_options, # type: Sequence[str]
74 ):
75 # type: (...) -> List[str]
76 args = make_setuptools_shim_args(
77 setup_py_path,
78 global_options=global_options,
79 unbuffered_output=True
80 )
81 args += ["clean", "--all"]
82 return args
83
84
85 def make_setuptools_develop_args(
86 setup_py_path, # type: str
87 global_options, # type: Sequence[str]
88 install_options, # type: Sequence[str]
89 no_user_config, # type: bool
90 prefix, # type: Optional[str]
91 home, # type: Optional[str]
92 use_user_site, # type: bool
93 ):
94 # type: (...) -> List[str]
95 assert not (use_user_site and prefix)
96
97 args = make_setuptools_shim_args(
98 setup_py_path,
99 global_options=global_options,
100 no_user_config=no_user_config,
101 )
102
103 args += ["develop", "--no-deps"]
104
105 args += install_options
106
107 if prefix:
108 args += ["--prefix", prefix]
109 if home is not None:
110 args += ["--home", home]
111
112 if use_user_site:
113 args += ["--user", "--prefix="]
114
115 return args
116
117
118 def make_setuptools_egg_info_args(
119 setup_py_path, # type: str
120 egg_info_dir, # type: Optional[str]
121 no_user_config, # type: bool
122 ):
123 # type: (...) -> List[str]
124 args = make_setuptools_shim_args(
125 setup_py_path, no_user_config=no_user_config
126 )
127
128 args += ["egg_info"]
129
130 if egg_info_dir:
131 args += ["--egg-base", egg_info_dir]
132
133 return args
134
135
136 def make_setuptools_install_args(
137 setup_py_path, # type: str
138 global_options, # type: Sequence[str]
139 install_options, # type: Sequence[str]
140 record_filename, # type: str
141 root, # type: Optional[str]
142 prefix, # type: Optional[str]
143 header_dir, # type: Optional[str]
144 home, # type: Optional[str]
145 use_user_site, # type: bool
146 no_user_config, # type: bool
147 pycompile # type: bool
148 ):
149 # type: (...) -> List[str]
150 assert not (use_user_site and prefix)
151 assert not (use_user_site and root)
152
153 args = make_setuptools_shim_args(
154 setup_py_path,
155 global_options=global_options,
156 no_user_config=no_user_config,
157 unbuffered_output=True
158 )
159 args += ["install", "--record", record_filename]
160 args += ["--single-version-externally-managed"]
161
162 if root is not None:
163 args += ["--root", root]
164 if prefix is not None:
165 args += ["--prefix", prefix]
166 if home is not None:
167 args += ["--home", home]
168 if use_user_site:
169 args += ["--user", "--prefix="]
170
171 if pycompile:
172 args += ["--compile"]
173 else:
174 args += ["--no-compile"]
175
176 if header_dir:
177 args += ["--install-headers", header_dir]
178
179 args += install_options
180
181 return args