Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding windows build #149

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .idea/.gitignore
Empty file.
19 changes: 19 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/viser.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 78 additions & 14 deletions src/viser/_client_autobuild.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import subprocess
import sys
import sys,os
from pathlib import Path

import psutil
Expand Down Expand Up @@ -56,19 +56,83 @@ 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"
subprocess.run(
args=(
"bash -c '"
f"source {env_dir / 'bin' / 'activate'};"
f"{npx_path} yarn install;"
f"{npx_path} yarn run build;"
"'"
),
cwd=client_dir,
shell=True,
)
if os.name == "nt":
print("Build on windows")
env_dir = _install_sandboxed_node_win()
env_dir_abs = env_dir / "Scripts"
# 1. 构建 Windows 路径
npx_path = env_dir_abs / "npx.cmd"
yarn_install_cmd = f"{npx_path} yarn install"
yarn_build_cmd = f"{npx_path} yarn run build"
# 激活 Node 环境并运行 yarn 命令
subprocess.run(["cmd", "/c", yarn_install_cmd], cwd=env_dir_abs, shell=True)
print('install yarn done!!!!!!!')
subprocess.run(["cmd", "/c", yarn_build_cmd], cwd=env_dir_abs, shell=True)
print('build yarn done!!!!!!')
# print('构建成功!!!!!!!!!!!!!!!!')
else:
print("Build on other platforms")
env_dir = _install_sandboxed_node()
npx_path = env_dir / "bin" / "npx"
subprocess.run(
args=(
"bash -c '"
f"source {env_dir / 'bin' / 'activate'};"
f"{npx_path} yarn install;"
f"{npx_path} yarn run build;"
"'"
),
cwd=client_dir,
shell=True,
)

def _install_sandboxed_node_win() -> Path:
"""Install a sandboxed copy of nodejs using nodeenv, and return a path to the
environment root."""
# 1 Set the node environment path
env_dir = client_dir / ".nodeenv"
if (env_dir / "Scripts" / "npx.cmd").exists():
rich.print("[bold](viser)[/bold] nodejs is set up!")
return env_dir
####### Installing a node you can run in cmd :
# Administrator permissions Open cmd
# conda activate your python
# python -m nodeenv --node=20.4.0 path\to\your\extern\viser\src\viser\client\.nodeenv
result = subprocess.run(
[sys.executable, "-m", "nodeenv", "--node=20.4.0", env_dir],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
try:
# 首先尝试 UTF-8 编码
error_output = result.stderr.decode('utf-8')
except UnicodeDecodeError:
try:
# 如果 UTF-8 失败,尝试使用 GBK 编码(适用于中文 Windows 系统)
error_output = result.stderr.decode('gbk')
except UnicodeDecodeError:
# 如果其他编码也失败,使用 'replace' 选项替换无法解码的字符
error_output = result.stderr.decode('utf-8', errors='replace')

print(f"Link error: {error_output}")
print('\n###############\n')
print(f"About unable to create link error: Failed to create nodejs.exe link ")
print(
" NOTE: This error does not affect the build process and can be fixed manually if necessary.")
print(
" 1. Open Command Prompt with Administrator privileges\n 2. Navigate to the .nodeenv\\Scripts directory in your project")
print(
" 3. Run the command 'mklink nodejs.exe node.exe' to create the symbolic link\n 4. After this, it should be okay")
print('\n###############\n')

print('node installation complete\n安装node完成!!!!!!!!!!!!!')
subprocess.run(
args=[env_dir / "Scripts" / "npm.cmd", "install", "yarn"],
input="y\n".encode(),
)
print('install yarn done')
assert (env_dir / "Scripts" / "npx.cmd").exists()
return env_dir


def _install_sandboxed_node() -> Path:
Expand Down
Loading