Skip to content

Commit 958ae17

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 93cdde9 commit 958ae17

File tree

4 files changed

+12
-66
lines changed

4 files changed

+12
-66
lines changed

.circleci/config.yml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ commands:
170170
name: clear cache
171171
command: |
172172
./emcc --clear-cache
173-
- pip-install
174173
- run: apt-get install -q -y ninja-build
175174
- run:
176175
name: embuilder build ALL
@@ -216,12 +215,8 @@ commands:
216215
# Must be absolute path or relative path from working_directory
217216
at: ~/
218217
- checkout
219-
- run:
220-
name: submodule update
221-
command: git submodule update --init
222218
- emsdk-env
223219
- bootstrap
224-
- pip-install
225220
- when:
226221
# We only set EMTEST_RETRY_FLAKY on pull requests. When we run
227222
# normal CI jobs on branches like main we still want to be able to
@@ -339,9 +334,6 @@ commands:
339334
at: ~/
340335
- checkout
341336
- remove-linux-binaries
342-
- run:
343-
name: submodule update
344-
command: git submodule update --init
345337
run-tests-firefox:
346338
description: "Runs emscripten tests under firefox"
347339
parameters:
@@ -791,10 +783,6 @@ jobs:
791783
executor: linux-python
792784
steps:
793785
- checkout
794-
- run:
795-
name: submodule update
796-
command: git submodule update --init
797-
- pip-install
798786
- install-emsdk
799787
- run:
800788
name: install jsc
@@ -816,10 +804,6 @@ jobs:
816804
executor: linux-python
817805
steps:
818806
- checkout
819-
- run:
820-
name: submodule update
821-
command: git submodule update --init
822-
- pip-install
823807
- install-emsdk
824808
- run:
825809
name: install spidermonkey
@@ -846,10 +830,6 @@ jobs:
846830
EMTEST_SKIP_V8: "1"
847831
steps:
848832
- checkout
849-
- run:
850-
name: submodule update
851-
command: git submodule update --init
852-
- pip-install
853833
- install-emsdk
854834
# `install-node-version` only changes the NODE_JS_TEST (the version of
855835
# node used to run test), not NODE_JS (the version of node used to run the
@@ -989,10 +969,6 @@ jobs:
989969
EMTEST_LACKS_WEBGPU: "1"
990970
steps:
991971
- checkout
992-
- run:
993-
name: submodule update
994-
command: git submodule update --init
995-
- pip-install
996972
- install-emsdk
997973
- run-tests-chrome:
998974
title: "browser"
@@ -1082,10 +1058,6 @@ jobs:
10821058
executor: focal
10831059
steps:
10841060
- checkout
1085-
- run:
1086-
name: submodule update
1087-
command: git submodule update --init
1088-
- pip-install
10891061
- install-emsdk
10901062
- run-tests-firefox:
10911063
title: "browser64"
@@ -1114,8 +1086,6 @@ jobs:
11141086
name: Add python to bash path
11151087
command: echo "export PATH=\"$PATH:/c/Python27amd64/\"" >> $BASH_ENV
11161088
- install-emsdk
1117-
- pip-install:
1118-
python: "$EMSDK_PYTHON"
11191089
- run-tests-firefox-windows:
11201090
title: "browser on firefox on windows"
11211091
# skip browser.test_glbook, as it requires mingw32-make, which is not
@@ -1178,8 +1148,6 @@ jobs:
11781148
# note we do *not* build all libraries and freeze the cache; as we run
11791149
# only limited tests here, it's more efficient to build on demand
11801150
- install-emsdk
1181-
- pip-install:
1182-
python: "$EMSDK_PYTHON"
11831151
- run-tests:
11841152
title: "crossplatform tests"
11851153
test_targets: "--crossplatform-only"
@@ -1207,8 +1175,6 @@ jobs:
12071175
- setup-macos
12081176
- install-emsdk
12091177
- freeze-cache
1210-
# TODO: We can't currently do pip install here since numpy and other packages
1211-
# are currently missing arm64 macos binaries.
12121178
- run-tests:
12131179
title: "crossplatform tests"
12141180
test_targets: "--crossplatform-only"

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

test/runner.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@
4343
from common import errlog
4444
from tools import shared, config, utils
4545

46+
# Add `out/python_deps` to pythoon path and make sure we can import out dev dependencies.
47+
sys.path.insert(0, utils.path_from_root('out/python_deps'))
48+
49+
try:
50+
import psutil # noqa: F401
51+
import websockify # noqa: F401
52+
except ModuleNotFoundError as e:
53+
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
4654

47-
sys.path.append(utils.path_from_root('third_party/websockify'))
4855

4956
logger = logging.getLogger("runner")
5057

test/test_sockets.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import shutil
1010
import sys
1111
import time
12+
import websockify
1213
from subprocess import Popen
1314
from typing import List
1415

@@ -25,22 +26,9 @@
2526

2627
npm_checked = False
2728

28-
EMTEST_SKIP_PYTHON_DEV_PACKAGES = int(os.getenv('EMTEST_SKIP_PYTHON_DEV_PACKAGES', '0'))
2929
EMTEST_SKIP_NODE_DEV_PACKAGES = int(os.getenv('EMTEST_SKIP_NODE_DEV_PACKAGES', '0'))
3030

3131

32-
def requires_python_dev_packages(func):
33-
assert callable(func)
34-
35-
@common.wraps(func)
36-
def decorated(self, *args, **kwargs):
37-
if EMTEST_SKIP_PYTHON_DEV_PACKAGES:
38-
return self.skipTest('python websockify based tests are disabled by EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
39-
return func(self, *args, **kwargs)
40-
41-
return decorated
42-
43-
4432
def clean_processes(processes):
4533
for p in processes:
4634
if getattr(p, 'exitcode', None) is None and getattr(p, 'returncode', None) is None:
@@ -77,11 +65,6 @@ def __enter__(self):
7765
process = Popen([os.path.abspath('server')])
7866
self.processes.append(process)
7967

80-
try:
81-
import websockify # type: ignore
82-
except ModuleNotFoundError:
83-
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
84-
8568
# start the websocket proxy
8669
print('running websockify on %d, forward to tcp %d' % (self.listen_port, self.target_port), file=sys.stderr)
8770
# source_is_ipv6=True here signals to websockify that it should prefer ipv6 address when
@@ -202,8 +185,6 @@ def setUpClass(cls):
202185
def test_sockets_echo(self, harness_class, port, args):
203186
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
204187
self.skipTest('requires native clang')
205-
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
206-
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
207188
if harness_class == CompiledServerHarness and EMTEST_SKIP_NODE_DEV_PACKAGES:
208189
self.skipTest('requires node ws and EMTEST_SKIP_NODE_DEV_PACKAGES=1')
209190

@@ -230,8 +211,6 @@ def test_sdl2_sockets_echo(self):
230211
def test_sockets_async_echo(self, harness_class, port, args):
231212
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
232213
self.skipTest('requires native clang')
233-
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
234-
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
235214
if harness_class == CompiledServerHarness and EMTEST_SKIP_NODE_DEV_PACKAGES:
236215
self.skipTest('requires node ws and EMTEST_SKIP_NODE_DEV_PACKAGES=1')
237216

@@ -252,8 +231,6 @@ def test_sockets_async_bad_port(self):
252231
def test_sockets_echo_bigdata(self, harness_class, port, args):
253232
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
254233
self.skipTest('requires native clang')
255-
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
256-
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
257234
if harness_class == CompiledServerHarness and EMTEST_SKIP_NODE_DEV_PACKAGES:
258235
self.skipTest('requires node ws and EMTEST_SKIP_NODE_DEV_PACKAGES=1')
259236
sockets_include = '-I' + test_file('sockets')
@@ -271,7 +248,6 @@ def test_sockets_echo_bigdata(self, harness_class, port, args):
271248
self.btest_exit('test_sockets_echo_bigdata.c', cflags=[sockets_include, '-DSOCKK=%d' % harness.listen_port] + args)
272249

273250
@no_windows('This test is Unix-specific.')
274-
@requires_python_dev_packages
275251
@requires_dev_dependency('ws')
276252
def test_sockets_partial(self):
277253
for harness in [
@@ -282,7 +258,6 @@ def test_sockets_partial(self):
282258
self.btest_exit('sockets/test_sockets_partial_client.c', assert_returncode=165, cflags=['-DSOCKK=%d' % harness.listen_port])
283259

284260
@no_windows('This test is Unix-specific.')
285-
@requires_python_dev_packages
286261
@requires_dev_dependency('ws')
287262
def test_sockets_select_server_down(self):
288263
for harness in [
@@ -293,7 +268,6 @@ def test_sockets_select_server_down(self):
293268
self.btest_exit('sockets/test_sockets_select_server_down_client.c', cflags=['-DSOCKK=%d' % harness.listen_port])
294269

295270
@no_windows('This test is Unix-specific.')
296-
@requires_python_dev_packages
297271
@requires_dev_dependency('ws')
298272
def test_sockets_select_server_closes_connection_rw(self):
299273
for harness in [
@@ -326,8 +300,6 @@ def test_enet(self):
326300
def test_nodejs_sockets_echo(self, harness_class, port, args):
327301
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
328302
self.skipTest('requires native clang')
329-
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
330-
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
331303
if harness_class == CompiledServerHarness and EMTEST_SKIP_NODE_DEV_PACKAGES:
332304
self.skipTest('requires node ws and EMTEST_SKIP_NODE_DEV_PACKAGES=1')
333305

@@ -340,7 +312,6 @@ def test_nodejs_sockets_connect_failure(self):
340312
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)
341313

342314
@requires_native_clang
343-
@requires_python_dev_packages
344315
def test_nodejs_sockets_echo_subprotocol(self):
345316
# Test against a Websockified server with compile time configured WebSocket subprotocol. We use a Websockified
346317
# server because as long as the subprotocol list contains binary it will configure itself to accept binary
@@ -353,7 +324,6 @@ def test_nodejs_sockets_echo_subprotocol(self):
353324
self.assertContained(['connect: ws://127.0.0.1:59168, base64,binary', 'connect: ws://127.0.0.1:59168/, base64,binary'], out)
354325

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

0 commit comments

Comments
 (0)