Skip to content

Commit

Permalink
Raise error in build step if custom component package is not installed (
Browse files Browse the repository at this point in the history
#7046)

* Check installation

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
freddyaboulton and gradio-pr-bot committed Jan 18, 2024
1 parent 8e5ab31 commit 9201f86
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/huge-dogs-suffer.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Raise error in build step if custom component package is not installed
9 changes: 9 additions & 0 deletions gradio/cli/commands/components/build.py
@@ -1,3 +1,4 @@
import importlib
import shutil
import subprocess
from pathlib import Path
Expand Down Expand Up @@ -34,6 +35,14 @@ def _build(
f":package: Building package in [orange3]{str(name.name)}[/]", add_sleep=0.2
)
pyproject_toml = parse((path / "pyproject.toml").read_text())
package_name = pyproject_toml["project"]["name"] # type: ignore
try:
importlib.import_module(package_name) # type: ignore
except ModuleNotFoundError as e:
raise ValueError(
f"Your custom component package ({package_name}) is not installed! "
"Please install it with the gradio cc install command before buillding it."
) from e
if bump_version:
pyproject_toml = parse((path / "pyproject.toml").read_text())
version = semantic_version.Version(
Expand Down
17 changes: 17 additions & 0 deletions test/test_gradio_component_cli.py
Expand Up @@ -5,6 +5,7 @@
import pytest

from gradio.cli.commands.components._create_utils import OVERRIDES
from gradio.cli.commands.components.build import _build
from gradio.cli.commands.components.create import _create
from gradio.cli.commands.components.publish import _get_version_from_file
from gradio.cli.commands.components.show import _show
Expand Down Expand Up @@ -146,6 +147,22 @@ def test_build(template, virtualenv):
shutil.rmtree(str(dir_), ignore_errors=True)


def test_build_fails_if_component_not_installed(tmp_path):
_create(
"MyComponent",
tmp_path,
template="SimpleTextbox",
overwrite=True,
install=False,
configure_metadata=False,
)
with pytest.raises(
ValueError,
match=r"Your custom component package \(gradio_mycomponent\) is not installed!",
):
_build(tmp_path)


def test_fallback_template_app(tmp_path):
_create(
"SimpleComponent2",
Expand Down

0 comments on commit 9201f86

Please sign in to comment.