From c9c69516b02d07ebb893150d997f7cfafc759882 Mon Sep 17 00:00:00 2001 From: Jeremy Maitin-Shepard Date: Fri, 23 Feb 2024 10:19:44 -0800 Subject: [PATCH] chore(python): use nodejs-wheel in place of nodejs-bin dependency --- python/neuroglancer/server.py | 5 ++--- python/requirements-mypy.txt | 1 - python/requirements-nodejs.txt | 1 + python/requirements-test-browser.txt | 4 ++-- python/requirements-webdriver.txt | 1 + python/requirements.txt | 7 ++++++ python/tests/client_test.py | 26 ++++++++++------------ setup.py | 33 +++++++++++++++------------- 8 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 python/requirements-nodejs.txt create mode 100644 python/requirements-webdriver.txt create mode 100644 python/requirements.txt diff --git a/python/neuroglancer/server.py b/python/neuroglancer/server.py index c979838e87..8d033cc405 100644 --- a/python/neuroglancer/server.py +++ b/python/neuroglancer/server.py @@ -519,12 +519,11 @@ def set_static_content_source(*args, **kwargs): def set_dev_server_content_source(): - import nodejs - static_content_url = None root_dir = os.path.join(os.path.dirname(__file__), "..", "..") - build_process = nodejs.npm.Popen( + build_process = subprocess.Popen( [ + "npm", "run", "dev-server-python", "--", diff --git a/python/requirements-mypy.txt b/python/requirements-mypy.txt index c3d8a561da..d95013aa27 100644 --- a/python/requirements-mypy.txt +++ b/python/requirements-mypy.txt @@ -11,4 +11,3 @@ pytest-html requests filelock argcomplete -nodejs-bin diff --git a/python/requirements-nodejs.txt b/python/requirements-nodejs.txt new file mode 100644 index 0000000000..4cf4543b6e --- /dev/null +++ b/python/requirements-nodejs.txt @@ -0,0 +1 @@ +nodejs-wheel>=20.11 diff --git a/python/requirements-test-browser.txt b/python/requirements-test-browser.txt index 62a7b829d1..4da09c67a3 100644 --- a/python/requirements-test-browser.txt +++ b/python/requirements-test-browser.txt @@ -1,2 +1,2 @@ -selenium>=4 -nodejs-bin[cmd] +-r requirements-webdriver.txt +-r requirements-nodejs.txt diff --git a/python/requirements-webdriver.txt b/python/requirements-webdriver.txt new file mode 100644 index 0000000000..6328dd1d51 --- /dev/null +++ b/python/requirements-webdriver.txt @@ -0,0 +1 @@ +selenium>=4 diff --git a/python/requirements.txt b/python/requirements.txt new file mode 100644 index 0000000000..b2beea7eb1 --- /dev/null +++ b/python/requirements.txt @@ -0,0 +1,7 @@ +Pillow>=3.2.0 +numpy>=1.11.0 +requests +tornado +google-apitools +google-auth +atomicwrites diff --git a/python/tests/client_test.py b/python/tests/client_test.py index f7f9379dc3..fb41a6afcf 100644 --- a/python/tests/client_test.py +++ b/python/tests/client_test.py @@ -32,8 +32,6 @@ def capture_screenshot_from_dev_server( webdriver, example_dir, test_fragment, extra_args=None ): - import nodejs - if sys.platform == "win32": process_group_args = dict(creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) else: @@ -43,8 +41,8 @@ def capture_screenshot_from_dev_server( # causes this test to hang when using a new process group rather than a # new session. process_group_args = dict(start_new_session=True) - p = nodejs.npm.Popen( - ["run", "dev-server"] + (extra_args or []), + p = subprocess.Popen( + ["npm", "run", "dev-server"] + (extra_args or []), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, @@ -102,9 +100,9 @@ def capture_screenshot_from_build( output_dir=None, extra_args=None, ): - import nodejs - - nodejs.npm.run(["run", "build"] + (extra_args or []), cwd=example_dir, check=True) + subprocess.run( + ["npm", "run", "build"] + (extra_args or []), cwd=example_dir, check=True + ) if output_dir is None: output_dir = os.path.join(example_dir, "dist") @@ -195,10 +193,10 @@ def example_dir(request): @pytest.fixture(scope="session") def built_package(request): def do_build(): - import nodejs - - nodejs.npm.run(["install", "--no-fund", "--no-audit"], cwd=root_dir, check=True) - nodejs.npm.run(["run", "build-package"], cwd=root_dir, check=True) + subprocess.run( + ["npm", "install", "--no-fund", "--no-audit"], cwd=root_dir, check=True + ) + subprocess.run(["npm", "run", "build-package"], cwd=root_dir, check=True) get_xdist_session_value( do_build, @@ -209,10 +207,8 @@ def do_build(): @pytest.fixture(scope="session") def installed_example_dir(request, example_dir): def do_install(): - import nodejs - - nodejs.npm.run( - ["install", "--no-fund", "--no-audit"], + subprocess.run( + ["npm", "install", "--no-fund", "--no-audit"], cwd=os.path.join(root_dir, example_dir), check=True, ) diff --git a/setup.py b/setup.py index 2e057d2323..fb84e9cb37 100755 --- a/setup.py +++ b/setup.py @@ -8,6 +8,7 @@ import pathlib import platform import shutil +import subprocess import tempfile import setuptools @@ -26,6 +27,11 @@ python_dir, "ext", "third_party", "openmesh", "OpenMesh", "src" ) + +def _read_requirements(path: str) -> list[str]: + return pathlib.Path(path).read_text(encoding="utf-8").splitlines() + + _SETUP_REQUIRES = [ "setuptools_scm>=4.1.2", "numpy>=1.11.0", @@ -35,7 +41,9 @@ _PACKAGE_JSON_EXISTS = os.path.exists(os.path.join(root_dir, "package.json")) if _PACKAGE_JSON_EXISTS: - _SETUP_REQUIRES.append("nodejs-bin[cmd]") + _SETUP_REQUIRES.extend( + _read_requirements(os.path.join(python_dir, "requirements-nodejs.txt")) + ) with open(os.path.join(python_dir, "README.md"), encoding="utf-8") as f: @@ -226,11 +234,9 @@ def run(self): if self.skip_npm_reinstall and os.path.exists(node_modules_path): print(f"Skipping `npm install` since {node_modules_path} already exists") else: - import nodejs - - nodejs.npm.run(["install"], cwd=root_dir, check=True) - nodejs.npm.run( - ["run", t, "--", f"--output={output_dir}"], cwd=root_dir, check=True + subprocess.run(["npm", "install"], cwd=root_dir, check=True) + subprocess.run( + ["npm", "run", t, "--", f"--output={output_dir}"], cwd=root_dir, check=True ) @@ -295,15 +301,12 @@ def _no_guess_dev_version(version): "": "python", }, setup_requires=_SETUP_REQUIRES, - install_requires=[ - "Pillow>=3.2.0", - "numpy>=1.11.0", - "requests", - "tornado", - "google-apitools", - "google-auth", - "atomicwrites", - ], + install_requires=_read_requirements(os.path.join(python_dir, "requirements.txt")), + extras_require={ + "webdriver": _read_requirements( + os.path.join(python_dir, "requirements-webdriver.txt") + ), + }, ext_modules=[ setuptools.Extension( "neuroglancer._neuroglancer",