Skip to content

Commit

Permalink
Allow description, name and email to be empty (#136)
Browse files Browse the repository at this point in the history
* Allow description, name and email to be empty

* Add test

* Bump pre-commit versions

* Copy from pyscript config

* Run pre-commit and update tests

* trigger pre-commit
  • Loading branch information
FabioRosado authored Feb 14, 2024
1 parent 1546129 commit 3c76353
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ coverage.xml
# Generated documentation
/docs/build/
/docs/source/api/

pyscript.egg-info/
build/
24 changes: 14 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
# This is the configuration for pre-commit, a local framework for managing pre-commit hooks
# Check out the docs at: https://pre-commit.com/
ci:
#skip: [eslint]
autoupdate_schedule: monthly

default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.10.0
rev: v2.12.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '4']
- id: pretty-format-toml
args: [--autofix]
- repo: https://github.com/sondrelg/pep585-upgrade
rev: v1.0
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: upgrade-type-hints
args: [--futures=true]
- id: pyupgrade
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort
name: isort (python)
args: [--profile, black]
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Documentation configuration for `pyscript-cli`."""

from __future__ import annotations

import sys
Expand Down
1 change: 1 addition & 0 deletions src/pyscript/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A CLI for PyScript!"""

import json
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions src/pyscript/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The main CLI entrypoint and commands."""

import sys
from typing import Any, Optional

Expand Down
6 changes: 3 additions & 3 deletions src/pyscript/plugins/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def create(
)

if not app_description:
app_description = typer.prompt("App description")
app_description = typer.prompt("App description", default="")
if not author_name:
author_name = typer.prompt("Author name")
author_name = typer.prompt("Author name", default="")
if not author_email:
author_email = typer.prompt("Author email")
author_email = typer.prompt("Author email", default="")

try:
create_project(
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
from _pytest.monkeypatch import MonkeyPatch


@pytest.fixture
def auto_enter(monkeypatch):
"""
Monkey patch 'typer.confirm' to always hit <Enter>".
"""

def user_hit_enter(*args, **kwargs):
return ""

monkeypatch.setattr("typer.prompt", user_hit_enter)


@pytest.fixture()
def tmp_cwd(monkeypatch: MonkeyPatch, tmp_path: Path) -> Path:
"""Create & return a temporary directory after setting current working directory to it."""
Expand Down
32 changes: 28 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, Callable, Optional
from typing import TYPE_CHECKING, Callable

import pytest
from mypy_extensions import VarArg
Expand Down Expand Up @@ -29,7 +29,7 @@ def app_details_args():


@pytest.fixture()
def invoke_cli(tmp_path: Path, monkeypatch: "MonkeyPatch") -> CLIInvoker:
def invoke_cli(tmp_path: Path, monkeypatch: MonkeyPatch) -> CLIInvoker:
"""Returns a function, which can be used to call the CLI from within a temporary directory."""
runner = CliRunner()

Expand All @@ -48,6 +48,30 @@ def test_version() -> None:
assert f"PyScript CLI version: {__version__}" in result.stdout


def test_create_command(
invoke_cli: CLIInvoker, tmp_path: Path, app_details_args: list[str], auto_enter
) -> None:
result = invoke_cli("create", "myapp")
assert result.exit_code == 0

expected_path = tmp_path / "myapp"
assert expected_path.exists()

expected_main_py_path = expected_path / "main.py"
assert expected_main_py_path.exists()

expected_config_path = expected_path / config["project_config_filename"]
assert expected_config_path.exists()
with expected_config_path.open() as fp:
config_text = fp.read()

assert 'name = "myapp' in config_text
# Assert that description, author name and email are empty
assert 'description = ""' in config_text
assert 'author_name = ""' in config_text
assert 'author_email = ""' in config_text


@pytest.mark.parametrize("flag", ["-c", "--command"])
def test_wrap_command(
invoke_cli: CLIInvoker, tmp_path: Path, flag: str, app_details_args: list[str]
Expand Down Expand Up @@ -116,7 +140,7 @@ def test_wrap_file(
)
def test_wrap_pyscript_version(
invoke_cli: CLIInvoker,
version: Optional[str],
version: str | None,
expected_version: str,
tmp_path: Path,
app_details_args: list[str],
Expand Down Expand Up @@ -166,7 +190,7 @@ def test_wrap_pyscript_version(
)
def test_wrap_pyscript_version_file(
invoke_cli: CLIInvoker,
version: Optional[str],
version: str | None,
expected_version: str,
tmp_path: Path,
app_details_args: list[str],
Expand Down
1 change: 1 addition & 0 deletions tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exercised because of limitations in the Typer testing framework (specifically,
multiple "prompt" arguments).
"""

import json
from pathlib import Path
from textwrap import dedent
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@pytest.fixture()
def invoke_cli(tmp_path: Path, monkeypatch: "MonkeyPatch") -> CLIInvoker:
def invoke_cli(tmp_path: Path, monkeypatch: MonkeyPatch) -> CLIInvoker:
"""Returns a function, which can be used to call the CLI from within a temporary directory."""
runner = CliRunner()

Expand Down

0 comments on commit 3c76353

Please sign in to comment.