-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
test_pypy3.py
306 lines (276 loc) · 10.9 KB
/
test_pypy3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
from virtualenv.create.via_global_ref.builtin.pypy.pypy3 import PyPy3Posix
from virtualenv.create.via_global_ref.builtin.ref import ExePathRefToDest, PathRefToDest
from virtualenv.discovery.py_info import PythonInfo
from virtualenv.util.path import Path
# As downloaded from https://www.pypy.org/download.html
PORTABLE_PYPY38 = {
"platform": "linux",
"implementation": "PyPy",
"pypy_version_info": [7, 3, 8, "final", 0],
"version_info": {
"major": 3,
"minor": 8,
"micro": 12,
"releaselevel": "final",
"serial": 0,
},
"architecture": 64,
"version": "3.8.12 (d00b0afd2a5dd3c13fcda75d738262c864c62fa7, Feb 18 2022, 09:52:33)\n"
"[PyPy 7.3.8 with GCC 10.2.1 20210130 (Red Hat 10.2.1-11)]",
"os": "posix",
"prefix": "/tmp/pypy3.8-v7.3.8-linux64",
"base_prefix": "/tmp/pypy3.8-v7.3.8-linux64",
"real_prefix": None,
"base_exec_prefix": "/tmp/pypy3.8-v7.3.8-linux64",
"exec_prefix": "/tmp/pypy3.8-v7.3.8-linux64",
"executable": "/tmp/pypy3.8-v7.3.8-linux64/bin/pypy",
"original_executable": "/tmp/pypy3.8-v7.3.8-linux64/bin/pypy",
"system_executable": "/tmp/pypy3.8-v7.3.8-linux64/bin/pypy",
"has_venv": True,
"path": [
"/tmp/pypy3.8-v7.3.8-linux64/lib/pypy3.8",
"/tmp/pypy3.8-v7.3.8-linux64/lib/pypy3.8/site-packages",
],
"file_system_encoding": "utf-8",
"stdout_encoding": "UTF-8",
"sysconfig_scheme": None,
"sysconfig_paths": {
"stdlib": "{installed_base}/lib/{implementation_lower}{py_version_short}",
"platstdlib": "{platbase}/lib/{implementation_lower}{py_version_short}",
"purelib": "{base}/lib/{implementation_lower}{py_version_short}/site-packages",
"platlib": "{platbase}/lib/{implementation_lower}{py_version_short}/site-packages",
"include": "{installed_base}/include/{implementation_lower}{py_version_short}{abiflags}",
"scripts": "{base}/bin",
"data": "{base}",
},
"distutils_install": {
"purelib": "lib/pypy3.8/site-packages",
"platlib": "lib/pypy3.8/site-packages",
"headers": "include/pypy3.8/UNKNOWN",
"scripts": "bin",
"data": "",
},
"sysconfig": {
"makefile_filename": "/tmp/pypy3.8-v7.3.8-linux64/lib/pypy3.8/config-3.8-x86_64-linux-gnu/Makefile",
},
"sysconfig_vars": {
"installed_base": "/tmp/pypy3.8-v7.3.8-linux64",
"implementation_lower": "pypy",
"py_version_short": "3.8",
"platbase": "/tmp/pypy3.8-v7.3.8-linux64",
"base": "/tmp/pypy3.8-v7.3.8-linux64",
"abiflags": "",
"PYTHONFRAMEWORK": "",
},
"system_stdlib": "/tmp/pypy3.8-v7.3.8-linux64/lib/pypy3.8",
"system_stdlib_platform": "/tmp/pypy3.8-v7.3.8-linux64/lib/pypy3.8",
"max_size": 9223372036854775807,
"_creators": None,
}
# Debian's pypy3 layout, installed to /usr, before 3.8 allowed a /usr prefix
DEB_PYPY37 = {
"platform": "linux",
"implementation": "PyPy",
"pypy_version_info": [7, 3, 7, "final", 0],
"version_info": {
"major": 3,
"minor": 7,
"micro": 12,
"releaselevel": "final",
"serial": 0,
},
"architecture": 64,
"version": "3.7.12 (7.3.7+dfsg-5, Jan 27 2022, 12:27:44)\n[PyPy 7.3.7 with GCC 11.2.0]",
"os": "posix",
"prefix": "/usr/lib/pypy3",
"base_prefix": "/usr/lib/pypy3",
"real_prefix": None,
"base_exec_prefix": "/usr/lib/pypy3",
"exec_prefix": "/usr/lib/pypy3",
"executable": "/usr/bin/pypy3",
"original_executable": "/usr/bin/pypy3",
"system_executable": "/usr/bin/pypy3",
"has_venv": True,
"path": [
"/usr/lib/pypy3/lib_pypy/__extensions__",
"/usr/lib/pypy3/lib_pypy",
"/usr/lib/pypy3/lib-python/3",
"/usr/lib/pypy3/lib-python/3/lib-tk",
"/usr/lib/pypy3/lib-python/3/plat-linux2",
"/usr/local/lib/pypy3.7/dist-packages",
"/usr/lib/python3/dist-packages",
],
"file_system_encoding": "utf-8",
"stdout_encoding": "UTF-8",
"sysconfig_scheme": None,
"sysconfig_paths": {
"stdlib": "{base}/lib-python/{py_version_short}",
"platstdlib": "{base}/lib-python/{py_version_short}",
"purelib": "{base}/../../local/lib/pypy{py_version_short}/lib-python",
"platlib": "{base}/../../local/lib/pypy{py_version_short}/lib-python",
"include": "{base}/include",
"scripts": "{base}/../../local/bin",
"data": "{base}/../../local",
},
"distutils_install": {
"purelib": "site-packages",
"platlib": "site-packages",
"headers": "include/UNKNOWN",
"scripts": "bin",
"data": "",
},
"sysconfig": {
"makefile_filename": "/usr/lib/pypy3/lib-python/3.7/config-3.7-x86_64-linux-gnu/Makefile",
},
"sysconfig_vars": {
"base": "/usr/lib/pypy3",
"py_version_short": "3.7",
"PYTHONFRAMEWORK": "",
},
"system_stdlib": "/usr/lib/pypy3/lib-python/3.7",
"system_stdlib_platform": "/usr/lib/pypy3/lib-python/3.7",
"max_size": 9223372036854775807,
"_creators": None,
}
# Debian's pypy3 >= 3.8, with a /usr prefix
DEB_PYPY38 = {
"platform": "linux",
"implementation": "PyPy",
"pypy_version_info": [7, 3, 8, "final", 0],
"version_info": {
"major": 3,
"minor": 8,
"micro": 12,
"releaselevel": "final",
"serial": 0,
},
"architecture": 64,
"version": "3.8.12 (7.3.8+dfsg-2, Mar 05 2022, 02:04:42)\n[PyPy 7.3.8 with GCC 11.2.0]",
"os": "posix",
"prefix": "/usr",
"base_prefix": "/usr",
"real_prefix": None,
"base_exec_prefix": "/usr",
"exec_prefix": "/usr",
"executable": "/usr/bin/pypy3",
"original_executable": "/usr/bin/pypy3",
"system_executable": "/usr/bin/pypy3",
"has_venv": True,
"path": [
"/usr/lib/pypy3.8",
"/usr/local/lib/pypy3.8/dist-packages",
"/usr/lib/python3/dist-packages",
],
"file_system_encoding": "utf-8",
"stdout_encoding": "UTF-8",
"sysconfig_scheme": None,
"sysconfig_paths": {
"stdlib": "{installed_base}/lib/{implementation_lower}{py_version_short}",
"platstdlib": "{platbase}/lib/{implementation_lower}{py_version_short}",
"purelib": "{base}/local/lib/{implementation_lower}{py_version_short}/dist-packages",
"platlib": "{platbase}/local/lib/{implementation_lower}{py_version_short}/dist-packages",
"include": "{installed_base}/local/include/{implementation_lower}{py_version_short}{abiflags}",
"scripts": "{base}/local/bin",
"data": "{base}",
},
"distutils_install": {
"purelib": "lib/pypy3.8/site-packages",
"platlib": "lib/pypy3.8/site-packages",
"headers": "include/pypy3.8/UNKNOWN",
"scripts": "bin",
"data": "",
},
"sysconfig": {
"makefile_filename": "/usr/lib/pypy3.8/config-3.8-x86_64-linux-gnu/Makefile",
},
"sysconfig_vars": {
"installed_base": "/usr",
"implementation_lower": "pypy",
"py_version_short": "3.8",
"platbase": "/usr",
"base": "/usr",
"abiflags": "",
"PYTHONFRAMEWORK": "",
},
"system_stdlib": "/usr/lib/pypy3.8",
"system_stdlib_platform": "/usr/lib/pypy3.8",
"max_size": 9223372036854775807,
"_creators": None,
}
def assert_contains_exe(sources, src):
"""Assert that the one and only executeable in sources is src"""
exes = [source for source in sources if isinstance(source, ExePathRefToDest)]
assert len(exes) == 1
exe = exes[0]
assert exe.src.as_posix() == src
def assert_contains_ref(sources, src):
"""Assert that src appears in sources"""
assert any(source for source in sources if isinstance(source, PathRefToDest) and source.src.as_posix() == src)
class FakePath(Path):
"""
A Path() fake that only knows about files in existing_paths and the
directories that contain them.
"""
existing_paths = []
if hasattr(Path(""), "_flavour"):
_flavour = Path("")._flavour
def exists(self):
return self.as_posix() in self.existing_paths or self.is_dir()
def resolve(self):
return self
def is_dir(self):
prefix = self.as_posix() + "/"
return any(True for path in self.existing_paths if path.startswith(prefix))
def iterdir(self):
prefix = self.as_posix() + "/"
for path in self.existing_paths:
if path.startswith(prefix) and "/" not in path[len(prefix) :]:
yield FakePath(path)
def __div__(self, key):
return FakePath(super(FakePath, self).__div__(key))
def __truediv__(self, key):
return FakePath(super(FakePath, self).__truediv__(key))
def as_posix(self):
# The vendored version doesn't have this method
return str(self).replace("\\", "/")
def test_portable_pypy3_virtualenvs_get_their_libs(mocker):
portable_pypy3 = PythonInfo._from_dict(PORTABLE_PYPY38)
FakePath.existing_paths = [
"/tmp/pypy3.8-v7.3.8-linux64/bin/pypy",
"/tmp/pypy3.8-v7.3.8-linux64/lib/libgdbm.so.4",
]
mocker.patch("virtualenv.create.via_global_ref.builtin.pypy.common.Path", FakePath)
mocker.patch("virtualenv.create.via_global_ref.builtin.pypy.pypy3.Path", FakePath)
mocker.patch.object(
PyPy3Posix, "_shared_libs", return_value=[Path("/tmp/pypy3.8-v7.3.8-linux64/bin/libpypy3-c.so")]
)
sources = list(PyPy3Posix.sources(interpreter=portable_pypy3))
assert_contains_exe(sources, "/tmp/pypy3.8-v7.3.8-linux64/bin/pypy")
assert len(sources) > 2
assert_contains_ref(sources, "/tmp/pypy3.8-v7.3.8-linux64/bin/libpypy3-c.so")
assert_contains_ref(sources, "/tmp/pypy3.8-v7.3.8-linux64/lib/libgdbm.so.4")
def test_debian_pypy37_virtualenvs(mocker):
deb_pypy3 = PythonInfo._from_dict(DEB_PYPY37)
FakePath.existing_paths = [
"/usr/bin/pypy3",
]
mocker.patch("virtualenv.create.via_global_ref.builtin.pypy.common.Path", FakePath)
mocker.patch("virtualenv.create.via_global_ref.builtin.pypy.pypy3.Path", FakePath)
mocker.patch.object(PyPy3Posix, "_shared_libs", return_value=[Path("/usr/lib/pypy3/bin/libpypy3-c.so")])
sources = list(PyPy3Posix.sources(interpreter=deb_pypy3))
assert_contains_exe(sources, "/usr/bin/pypy3")
assert_contains_ref(sources, "/usr/lib/pypy3/bin/libpypy3-c.so")
assert len(sources) == 2
def test_debian_pypy38_virtualenvs_exclude_usr(mocker):
deb_pypy3 = PythonInfo._from_dict(DEB_PYPY38)
FakePath.existing_paths = [
"/usr/bin/pypy3",
"/usr/lib/foo",
]
mocker.patch("virtualenv.create.via_global_ref.builtin.pypy.common.Path", FakePath)
mocker.patch("virtualenv.create.via_global_ref.builtin.pypy.pypy3.Path", FakePath)
# libpypy3-c.so lives on the ld search path
mocker.patch.object(PyPy3Posix, "_shared_libs", return_value=[])
sources = list(PyPy3Posix.sources(interpreter=deb_pypy3))
assert_contains_exe(sources, "/usr/bin/pypy3")
assert len(sources) == 1