Skip to content

Commit a73b170

Browse files
committed
Perform pip install as part of bootstrap.py
Also, install pip packages in local `out/python_deps` directory instead of installing system wide. This means we can consistently expect dev dependencies to be available in test code without needing to include an opt out mechanism. We were already doing this for `psutil`, but for `websockify` we made it optional. This means that only python scripts that explicitly add `out/python_deps` to their python path will be able use the packages, and in particular it means that the emscripten compiler itself won't end up implicitly/accidentally depending on them.
1 parent 41697da commit a73b170

File tree

5 files changed

+15
-46
lines changed

5 files changed

+15
-46
lines changed

.circleci/config.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ commands:
186186
name: clear cache
187187
command: |
188188
./emcc --clear-cache
189-
- pip-install
190189
- run: apt-get install -q -y ninja-build ccache
191190
- run:
192191
name: Ccache stats and configuration
@@ -266,7 +265,6 @@ commands:
266265
- checkout
267266
- emsdk-env
268267
- bootstrap
269-
- pip-install
270268
- when:
271269
# We only set EMTEST_RETRY_FLAKY on pull requests. When we run
272270
# normal CI jobs on branches like main we still want to be able to
@@ -871,7 +869,6 @@ jobs:
871869
executor: linux-python
872870
steps:
873871
- checkout
874-
- pip-install
875872
- install-emsdk
876873
- run:
877874
name: install jsc
@@ -893,7 +890,6 @@ jobs:
893890
executor: linux-python
894891
steps:
895892
- checkout
896-
- pip-install
897893
- install-emsdk
898894
- run:
899895
name: install spidermonkey
@@ -920,7 +916,6 @@ jobs:
920916
EMTEST_SKIP_V8: "1"
921917
steps:
922918
- checkout
923-
- pip-install
924919
- install-emsdk
925920
# `install-node-version` only changes the NODE_JS_TEST (the version of
926921
# node used to run test), not NODE_JS (the version of node used to run the
@@ -1078,7 +1073,6 @@ jobs:
10781073
EMTEST_LACKS_WEBGPU: "1"
10791074
steps:
10801075
- checkout
1081-
- pip-install
10821076
- install-emsdk
10831077
- run-tests-chrome:
10841078
title: "browser"
@@ -1162,7 +1156,6 @@ jobs:
11621156
executor: focal
11631157
steps:
11641158
- checkout
1165-
- pip-install
11661159
- install-emsdk
11671160
- run-tests-firefox:
11681161
title: "browser64"
@@ -1191,8 +1184,6 @@ jobs:
11911184
name: Add python to bash path
11921185
command: echo "export PATH=\"$PATH:/c/Python27amd64/\"" >> $BASH_ENV
11931186
- install-emsdk
1194-
- pip-install:
1195-
python: "$EMSDK_PYTHON"
11961187
- run-tests-firefox-windows:
11971188
title: "browser on firefox on windows"
11981189
# skip browser.test_glbook, as it requires mingw32-make, which is not
@@ -1256,8 +1247,6 @@ jobs:
12561247
# note we do *not* build all libraries and freeze the cache; as we run
12571248
# only limited tests here, it's more efficient to build on demand
12581249
- install-emsdk
1259-
- pip-install:
1260-
python: "$EMSDK_PYTHON"
12611250
- run-tests:
12621251
title: "crossplatform tests"
12631252
test_targets: "--crossplatform-only"
@@ -1285,8 +1274,6 @@ jobs:
12851274
steps:
12861275
- setup-macos
12871276
- install-emsdk
1288-
- pip-install:
1289-
python: "$EMSDK_PYTHON"
12901277
- freeze-cache
12911278
- run-tests:
12921279
title: "crossplatform tests"

bootstrap.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
'test/third_party/googletest',
4040
'test/third_party/wasi-test-suite',
4141
], ['git', 'submodule', 'update', '--init']),
42+
('pip3 install', [
43+
'requirements-dev.txt',
44+
], [sys.executable, '-m', 'pip', 'install', '--target', 'out/python_deps', '-r', 'requirements-dev.txt']),
4245
]
4346

4447

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ mypy_path = "third_party/,third_party/ply,third_party/websockify"
8686
files = [ "." ]
8787
exclude = '''
8888
(?x)(
89+
out |
8990
cache |
9091
third_party |
9192
conf\.py |

test/runner.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@
3636

3737
__rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
3838
sys.path.insert(0, __rootpath__)
39+
# Add `out/python_deps` to ensure that we can import our dev dependencies.
40+
sys.path.insert(0, os.path.join(__rootpath__, 'out', 'python_deps'))
41+
# Now explictly import some dev dependencies so we can error early if they
42+
# Are missing
43+
try:
44+
import psutil # noqa: F401
45+
import websockify # type: ignore # noqa: F401
46+
except ModuleNotFoundError as e:
47+
raise Exception('Unable to import python dev dependencies (psutil/websockify). Run "./bootstrap" (or "python3 -m pip -r requirements-dev.txt --target out/python_deps") to install') from e
3948

4049
import common
4150
import jsrun
@@ -44,8 +53,6 @@
4453

4554
from tools import config, shared, utils
4655

47-
sys.path.append(utils.path_from_root('third_party/websockify'))
48-
4956
logger = logging.getLogger("runner")
5057

5158

test/test_sockets.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from subprocess import Popen
1313
from typing import List
1414

15+
import websockify # type: ignore
16+
1517
if __name__ == '__main__':
1618
raise Exception('do not run this file directly; do something like: test/runner sockets')
1719

@@ -33,22 +35,9 @@
3335

3436
npm_checked = False
3537

36-
EMTEST_SKIP_PYTHON_DEV_PACKAGES = int(os.getenv('EMTEST_SKIP_PYTHON_DEV_PACKAGES', '0'))
3738
EMTEST_SKIP_NODE_DEV_PACKAGES = int(os.getenv('EMTEST_SKIP_NODE_DEV_PACKAGES', '0'))
3839

3940

40-
def requires_python_dev_packages(func):
41-
assert callable(func)
42-
43-
@common.wraps(func)
44-
def decorated(self, *args, **kwargs):
45-
if EMTEST_SKIP_PYTHON_DEV_PACKAGES:
46-
return self.skipTest('python websockify based tests are disabled by EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
47-
return func(self, *args, **kwargs)
48-
49-
return decorated
50-
51-
5241
def clean_processes(processes):
5342
for p in processes:
5443
if getattr(p, 'exitcode', None) is None and getattr(p, 'returncode', None) is None:
@@ -85,11 +74,6 @@ def __enter__(self):
8574
process = Popen([os.path.abspath('server')])
8675
self.processes.append(process)
8776

88-
try:
89-
import websockify # type: ignore # noqa: PLC0415
90-
except ModuleNotFoundError:
91-
raise Exception('Unable to import module websockify. Run "python3 -m pip install websockify" or set environment variable EMTEST_SKIP_PYTHON_DEV_PACKAGES=1 to skip this test.') from None
92-
9377
# start the websocket proxy
9478
print('running websockify on %d, forward to tcp %d' % (self.listen_port, self.target_port), file=sys.stderr)
9579
# source_is_ipv6=True here signals to websockify that it should prefer ipv6 address when
@@ -210,8 +194,6 @@ def setUpClass(cls):
210194
def test_sockets_echo(self, harness_class, port, args):
211195
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
212196
self.skipTest('requires native clang')
213-
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
214-
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
215197
if harness_class == CompiledServerHarness and EMTEST_SKIP_NODE_DEV_PACKAGES:
216198
self.skipTest('requires node ws and EMTEST_SKIP_NODE_DEV_PACKAGES=1')
217199

@@ -238,8 +220,6 @@ def test_sdl2_sockets_echo(self):
238220
def test_sockets_async_echo(self, harness_class, port, args):
239221
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
240222
self.skipTest('requires native clang')
241-
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
242-
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
243223
if harness_class == CompiledServerHarness and EMTEST_SKIP_NODE_DEV_PACKAGES:
244224
self.skipTest('requires node ws and EMTEST_SKIP_NODE_DEV_PACKAGES=1')
245225

@@ -260,8 +240,6 @@ def test_sockets_async_bad_port(self):
260240
def test_sockets_echo_bigdata(self, harness_class, port, args):
261241
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
262242
self.skipTest('requires native clang')
263-
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
264-
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
265243
if harness_class == CompiledServerHarness and EMTEST_SKIP_NODE_DEV_PACKAGES:
266244
self.skipTest('requires node ws and EMTEST_SKIP_NODE_DEV_PACKAGES=1')
267245
sockets_include = '-I' + test_file('sockets')
@@ -279,7 +257,6 @@ def test_sockets_echo_bigdata(self, harness_class, port, args):
279257
self.btest_exit('test_sockets_echo_bigdata.c', cflags=[sockets_include, '-DSOCKK=%d' % harness.listen_port] + args)
280258

281259
@no_windows('This test is Unix-specific.')
282-
@requires_python_dev_packages
283260
@requires_dev_dependency('ws')
284261
def test_sockets_partial(self):
285262
for harness in [
@@ -290,7 +267,6 @@ def test_sockets_partial(self):
290267
self.btest_exit('sockets/test_sockets_partial_client.c', assert_returncode=165, cflags=['-DSOCKK=%d' % harness.listen_port])
291268

292269
@no_windows('This test is Unix-specific.')
293-
@requires_python_dev_packages
294270
@requires_dev_dependency('ws')
295271
def test_sockets_select_server_down(self):
296272
for harness in [
@@ -301,7 +277,6 @@ def test_sockets_select_server_down(self):
301277
self.btest_exit('sockets/test_sockets_select_server_down_client.c', cflags=['-DSOCKK=%d' % harness.listen_port])
302278

303279
@no_windows('This test is Unix-specific.')
304-
@requires_python_dev_packages
305280
@requires_dev_dependency('ws')
306281
def test_sockets_select_server_closes_connection_rw(self):
307282
for harness in [
@@ -334,8 +309,6 @@ def test_enet(self):
334309
def test_nodejs_sockets_echo(self, harness_class, port, args):
335310
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
336311
self.skipTest('requires native clang')
337-
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
338-
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
339312
if harness_class == CompiledServerHarness and EMTEST_SKIP_NODE_DEV_PACKAGES:
340313
self.skipTest('requires node ws and EMTEST_SKIP_NODE_DEV_PACKAGES=1')
341314

@@ -348,7 +321,6 @@ def test_nodejs_sockets_connect_failure(self):
348321
self.do_runf('sockets/test_sockets_echo_client.c', r'connect failed: (Connection refused|Host is unreachable)', regex=True, cflags=['-DSOCKK=666'], assert_returncode=NON_ZERO)
349322

350323
@requires_native_clang
351-
@requires_python_dev_packages
352324
def test_nodejs_sockets_echo_subprotocol(self):
353325
# Test against a Websockified server with compile time configured WebSocket subprotocol. We use a Websockified
354326
# server because as long as the subprotocol list contains binary it will configure itself to accept binary
@@ -361,7 +333,6 @@ def test_nodejs_sockets_echo_subprotocol(self):
361333
self.assertContained(['connect: ws://127.0.0.1:59168, base64,binary', 'connect: ws://127.0.0.1:59168/, base64,binary'], out)
362334

363335
@requires_native_clang
364-
@requires_python_dev_packages
365336
def test_nodejs_sockets_echo_subprotocol_runtime(self):
366337
# Test against a Websockified server with runtime WebSocket configuration. We specify both url and subprotocol.
367338
# In this test we have *deliberately* used the wrong port '-DSOCKK=12345' to configure the echo_client.c, so

0 commit comments

Comments
 (0)