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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use path to npm executable in subprocess #5736

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-banks-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Use path to npm executable in subprocess
12 changes: 12 additions & 0 deletions gradio/cli/commands/components/create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pathlib
import shutil
import subprocess
from typing import Optional

Expand Down Expand Up @@ -66,6 +67,17 @@ def _create(
if _create_utils._in_test_dir():
npm_install = "pnpm i --ignore-scripts"

npm_install = npm_install.strip()
if npm_install == "npm install":
npm = shutil.which("npm")
if not npm:
raise ValueError(
"By default, the install command uses npm to install "
"the frontend dependencies. Please install npm or pass your own install command "
"via the --npm-install option."
)
npm_install = f"{npm} install"

with LivePanelDisplay() as live:
live.update(
f":building_construction: Creating component [orange3]{name}[/] in directory [orange3]{directory}[/]",
Expand Down
7 changes: 6 additions & 1 deletion gradio/cli/commands/components/dev.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
import subprocess
from pathlib import Path

Expand Down Expand Up @@ -30,9 +31,13 @@ def _dev(

print(f":recycle: [green]Launching[/] {app} in reload mode\n")

node = shutil.which("node")
if not node:
raise ValueError("node must be installed in order to run dev mode.")

proc = subprocess.Popen(
[
"node",
node,
gradio_node_path,
"--component-directory",
component_directory,
Expand Down