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

Add Error + test #5738

Merged
merged 2 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/old-heads-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Add Error + test
4 changes: 3 additions & 1 deletion gradio/cli/commands/components/_create_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def _create_backend(
module = "layouts"
else:
raise ValueError(
f"Cannot find {component.template} in gradio.components or gradio.layouts"
f"Cannot find {component.template} in gradio.components or gradio.layouts. "
"Please pass in a valid component name via the --template option. "
"It must match the name of the python class exactly."
)

backend = directory / "backend" / package_name
Expand Down
12 changes: 6 additions & 6 deletions gradio/cli/commands/components/create.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pathlib
import shutil
import subprocess
from pathlib import Path
from typing import Optional

import typer
Expand All @@ -20,7 +20,7 @@ def _create(
),
],
directory: Annotated[
Optional[pathlib.Path],
Optional[Path],
typer.Option(
help="Directory to create the component in. Default is None. If None, will be created in <component-name> directory in the current directory."
),
Expand Down Expand Up @@ -51,7 +51,7 @@ def _create(
] = False,
):
if not directory:
directory = pathlib.Path(name.lower())
directory = Path(name.lower())
if not package_name:
package_name = f"gradio_{name.lower()}"

Expand Down Expand Up @@ -90,12 +90,12 @@ def _create(

component = _create_utils._get_component_code(template)

_create_utils._create_frontend(name.lower(), component, directory=directory)
live.update(":art: Created frontend code", add_sleep=0.2)

_create_utils._create_backend(name, component, directory, package_name)
live.update(":snake: Created backend code", add_sleep=0.2)

_create_utils._create_frontend(name.lower(), component, directory=directory)
live.update(":art: Created frontend code", add_sleep=0.2)

if install:
cmds = ["pip", "install", "-e", f"{str(directory)}"]
live.update(
Expand Down
13 changes: 13 additions & 0 deletions test/test_gradio_component_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from gradio.cli.commands.components.create import _create


def test_raise_error_component_template_does_not_exist(tmp_path):
with pytest.raises(
ValueError,
match="Cannot find NonExistentComponent in gradio.components or gradio.layouts",
):
_create(
"MyComponent", tmp_path, template="NonExistentComponent", overwrite=True
)
Loading