From f70b3dc1b3e8d6465a4cb5d8a01bb07d99ccdd70 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 8 Feb 2024 09:11:27 +0100 Subject: [PATCH 1/3] If no .nodenv/bin is found, try .nodeenv/Scripts --- src/viser/_client_autobuild.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/viser/_client_autobuild.py b/src/viser/_client_autobuild.py index b27ef30f0..be0c1461a 100644 --- a/src/viser/_client_autobuild.py +++ b/src/viser/_client_autobuild.py @@ -57,12 +57,14 @@ def ensure_client_is_built() -> None: # Install nodejs and build if necessary. We assume bash is installed. if build: - env_dir = _install_sandboxed_node() - npx_path = env_dir / "bin" / "npx" + node_exec_dir = _install_sandboxed_node() + npx_path = node_exec_dir / "npx" + + subprocess.run( args=( "bash -c '" - f"source {env_dir / 'bin' / 'activate'};" + f"source {node_exec_dir / 'activate'};" f"{npx_path} yarn install;" f"{npx_path} yarn run build;" "'" @@ -77,20 +79,26 @@ def _install_sandboxed_node() -> Path: """Install a sandboxed copy of nodejs using nodeenv, and return a path to the environment root.""" env_dir = client_dir / ".nodeenv" - if (env_dir / "bin" / "npx").exists(): + node_exec_dir = env_dir / "bin" + + """On windows inside .nodeenv no bin-folder exists. Instead the executables are kept in Scripts.""" + if not node_exec_dir.exists(): + node_exec_dir = env_dir / "Scripts" + + if (node_exec_dir / "npx").exists(): rich.print("[bold](viser)[/bold] nodejs is set up!") - return env_dir + return node_exec_dir subprocess.run( [sys.executable, "-m", "nodeenv", "--node=20.4.0", env_dir], check=False ) subprocess.run( - args=[env_dir / "bin" / "npm", "install", "yarn"], + args=[node_exec_dir / "npm", "install", "yarn"], input="y\n".encode(), check=False, ) - assert (env_dir / "bin" / "npx").exists() - return env_dir + assert (node_exec_dir / "npx").exists() + return node_exec_dir def _modified_time_recursive(dir: Path) -> float: From dfe9504540c2da7a4714fee16d2bf477523b0f3c Mon Sep 17 00:00:00 2001 From: Brent Yi Date: Sat, 23 Mar 2024 01:36:01 -0700 Subject: [PATCH 2/3] (WIP) fixes for autobuild on Windows --- pyproject.toml | 2 +- src/viser/_client_autobuild.py | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2b43732d6..3ab29a7e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ dependencies = [ "numpy>=1.0.0", "msgpack>=1.0.7", "imageio>=2.0.0", - "pyliblzfse>=0.4.1", + "pyliblzfse>=0.4.1; platform_system!='Windows'", "scikit-image>=0.18.0", "scipy>=1.7.3", "tqdm>=4.0.0", diff --git a/src/viser/_client_autobuild.py b/src/viser/_client_autobuild.py index be0c1461a..414bdacf0 100644 --- a/src/viser/_client_autobuild.py +++ b/src/viser/_client_autobuild.py @@ -60,15 +60,20 @@ def ensure_client_is_built() -> None: node_exec_dir = _install_sandboxed_node() npx_path = node_exec_dir / "npx" - + import os + subprocess_env = os.environ.copy() + subprocess_env["NODE_VIRTUAL_ENV"] = str(node_exec_dir.parent) + subprocess_env["PATH"] = str(node_exec_dir) + ";" + subprocess_env["PATH"] subprocess.run( - args=( - "bash -c '" - f"source {node_exec_dir / 'activate'};" - f"{npx_path} yarn install;" - f"{npx_path} yarn run build;" - "'" - ), + args=f"{npx_path} --yes yarn install", + env=subprocess_env, + cwd=client_dir, + shell=True, + check=False, + ) + subprocess.run( + args=f"{npx_path} --yes yarn run build", + env=subprocess_env, cwd=client_dir, shell=True, check=False, @@ -92,11 +97,6 @@ def _install_sandboxed_node() -> Path: subprocess.run( [sys.executable, "-m", "nodeenv", "--node=20.4.0", env_dir], check=False ) - subprocess.run( - args=[node_exec_dir / "npm", "install", "yarn"], - input="y\n".encode(), - check=False, - ) assert (node_exec_dir / "npx").exists() return node_exec_dir From f4bac0ff6a818d62d3fe9889fed3c0e57e63bed0 Mon Sep 17 00:00:00 2001 From: Brent Yi Date: Sat, 23 Mar 2024 01:49:52 -0700 Subject: [PATCH 3/3] Fix for POSIX systems --- src/viser/_client_autobuild.py | 42 ++++++++++++------- .../client/src/ControlPanel/ControlPanel.tsx | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/viser/_client_autobuild.py b/src/viser/_client_autobuild.py index 414bdacf0..84e17ebcc 100644 --- a/src/viser/_client_autobuild.py +++ b/src/viser/_client_autobuild.py @@ -1,3 +1,4 @@ +import os import subprocess import sys from pathlib import Path @@ -57,13 +58,16 @@ def ensure_client_is_built() -> None: # Install nodejs and build if necessary. We assume bash is installed. if build: - node_exec_dir = _install_sandboxed_node() - npx_path = node_exec_dir / "npx" + node_bin_dir = _install_sandboxed_node() + npx_path = node_bin_dir / "npx" - import os subprocess_env = os.environ.copy() - subprocess_env["NODE_VIRTUAL_ENV"] = str(node_exec_dir.parent) - subprocess_env["PATH"] = str(node_exec_dir) + ";" + subprocess_env["PATH"] + subprocess_env["NODE_VIRTUAL_ENV"] = str(node_bin_dir.parent) + subprocess_env["PATH"] = ( + str(node_bin_dir) + + (";" if sys.platform == "win32" else ":") + + subprocess_env["PATH"] + ) subprocess.run( args=f"{npx_path} --yes yarn install", env=subprocess_env, @@ -82,23 +86,31 @@ def ensure_client_is_built() -> None: def _install_sandboxed_node() -> Path: """Install a sandboxed copy of nodejs using nodeenv, and return a path to the - environment root.""" - env_dir = client_dir / ".nodeenv" - node_exec_dir = env_dir / "bin" + environment's bin directory (`.nodeenv/bin` or `.nodeenv/Scripts`). + + On Windows, the `.nodeenv/bin` does not exist. Instead, executables are + installed to `.nodeenv/Scripts`.""" - """On windows inside .nodeenv no bin-folder exists. Instead the executables are kept in Scripts.""" - if not node_exec_dir.exists(): - node_exec_dir = env_dir / "Scripts" + def get_node_bin_dir() -> Path: + env_dir = client_dir / ".nodeenv" + node_bin_dir = env_dir / "bin" + if not node_bin_dir.exists(): + node_bin_dir = env_dir / "Scripts" + return node_bin_dir - if (node_exec_dir / "npx").exists(): + node_bin_dir = get_node_bin_dir() + if (node_bin_dir / "npx").exists(): rich.print("[bold](viser)[/bold] nodejs is set up!") - return node_exec_dir + return node_bin_dir + env_dir = client_dir / ".nodeenv" subprocess.run( [sys.executable, "-m", "nodeenv", "--node=20.4.0", env_dir], check=False ) - assert (node_exec_dir / "npx").exists() - return node_exec_dir + + node_bin_dir = get_node_bin_dir() + assert (node_bin_dir / "npx").exists() + return node_bin_dir def _modified_time_recursive(dir: Path) -> float: diff --git a/src/viser/client/src/ControlPanel/ControlPanel.tsx b/src/viser/client/src/ControlPanel/ControlPanel.tsx index b444fc1a3..d6e4a8984 100644 --- a/src/viser/client/src/ControlPanel/ControlPanel.tsx +++ b/src/viser/client/src/ControlPanel/ControlPanel.tsx @@ -1,4 +1,4 @@ -import { useDisclosure, useMediaQuery, useToggle } from "@mantine/hooks"; +import { useDisclosure, useMediaQuery } from "@mantine/hooks"; import GeneratedGuiContainer from "./Generated"; import { ViewerContext } from "../App";