Skip to content

Commit

Permalink
chore(python): use nodejs-wheel in place of nodejs-bin dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jbms committed Feb 23, 2024
1 parent 08f639c commit c9c6951
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 36 deletions.
5 changes: 2 additions & 3 deletions python/neuroglancer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"--",
Expand Down
1 change: 0 additions & 1 deletion python/requirements-mypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ pytest-html
requests
filelock
argcomplete
nodejs-bin
1 change: 1 addition & 0 deletions python/requirements-nodejs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs-wheel>=20.11
4 changes: 2 additions & 2 deletions python/requirements-test-browser.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
selenium>=4
nodejs-bin[cmd]
-r requirements-webdriver.txt
-r requirements-nodejs.txt
1 change: 1 addition & 0 deletions python/requirements-webdriver.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
selenium>=4
7 changes: 7 additions & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Pillow>=3.2.0
numpy>=1.11.0
requests
tornado
google-apitools
google-auth
atomicwrites
26 changes: 11 additions & 15 deletions python/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down
33 changes: 18 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pathlib
import platform
import shutil
import subprocess
import tempfile

import setuptools
Expand All @@ -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",
Expand All @@ -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:
Expand Down Expand Up @@ -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
)


Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c9c6951

Please sign in to comment.