Skip to content

Move project_type validation higher #145

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

Merged
merged 1 commit into from
Mar 21, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/pyscript/_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,17 @@ def create_project(
if not pyscript_version:
pyscript_version = _get_latest_pyscript_version()

if project_type == "app":
template = "basic.html"
else:
raise ValueError(
f"Unknown project type: {project_type}. Valid values are: 'app'"
)

context = {
"name": app_name,
"description": app_description,
"type": "app",
"type": project_type,
"author_name": author_name,
"author_email": author_email,
"version": "latest",
Expand All @@ -125,13 +132,6 @@ def create_project(
save_config_file(manifest_file, context)
output_path = app_dir / "index.html" if output is None else app_dir / output

if project_type == "app":
template = "basic.html"
else:
raise ValueError(
f"Unknown project type: {project_type}. Valid values are: 'app'"
)

python_filepath = app_dir / "main.py"

if not wrap:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ def test_create_command(
assert 'author_email = ""' in config_text


def test_create_command_bad_app_type(
invoke_cli: CLIInvoker, tmp_path: Path, app_details_args: list[str], auto_enter
) -> None:
result = invoke_cli("create", "myapp", "--project-type", "bad_type")
assert (
str(result.exception)
== "Unknown project type: bad_type. Valid values are: 'app'"
)


def test_create_command_no_app_name(
invoke_cli: CLIInvoker, tmp_path: Path, app_details_args: list[str], auto_enter
) -> None:
Expand Down