mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-24 10:54:04 +08:00
Raise error in build step if custom component package is not installed (#7046)
* Check installation * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
8e5ab31d75
commit
9201f86450
5
.changeset/huge-dogs-suffer.md
Normal file
5
.changeset/huge-dogs-suffer.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Raise error in build step if custom component package is not installed
|
@ -1,3 +1,4 @@
|
||||
import importlib
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
@ -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(
|
||||
|
@ -5,6 +5,7 @@ from pathlib import Path
|
||||
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
|
||||
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user