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

Raise error in build step if custom component package is not installed #7046

Merged
merged 3 commits into from Jan 18, 2024
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/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
Comment on lines +38 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

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