Skip to content

Commit 3c76353

Browse files
authored
Allow description, name and email to be empty (#136)
* 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
1 parent 1546129 commit 3c76353

File tree

10 files changed

+65
-18
lines changed

10 files changed

+65
-18
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ coverage.xml
3030
# Generated documentation
3131
/docs/build/
3232
/docs/source/api/
33+
34+
pyscript.egg-info/
35+
build/

.pre-commit-config.yaml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
# This is the configuration for pre-commit, a local framework for managing pre-commit hooks
22
# Check out the docs at: https://pre-commit.com/
3+
ci:
4+
#skip: [eslint]
5+
autoupdate_schedule: monthly
36

7+
default_stages: [commit]
48
repos:
59
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.4.0
10+
rev: v4.5.0
711
hooks:
812
- id: end-of-file-fixer
913
- id: trailing-whitespace
1014
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
11-
rev: v2.10.0
15+
rev: v2.12.0
1216
hooks:
1317
- id: pretty-format-yaml
1418
args: [--autofix, --indent, '4']
1519
- id: pretty-format-toml
1620
args: [--autofix]
17-
- repo: https://github.com/sondrelg/pep585-upgrade
18-
rev: v1.0
21+
- repo: https://github.com/asottile/pyupgrade
22+
rev: v3.15.0
1923
hooks:
20-
- id: upgrade-type-hints
21-
args: [--futures=true]
24+
- id: pyupgrade
2225
- repo: https://github.com/pycqa/isort
23-
rev: 5.12.0
26+
rev: 5.13.2
2427
hooks:
2528
- id: isort
26-
name: isort
29+
name: isort (python)
30+
args: [--profile, black]
2731
- repo: https://github.com/psf/black
28-
rev: 23.7.0
32+
rev: 24.2.0
2933
hooks:
3034
- id: black
3135
- repo: https://github.com/pycqa/flake8
32-
rev: 6.1.0
36+
rev: 7.0.0
3337
hooks:
3438
- id: flake8

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Documentation configuration for `pyscript-cli`."""
2+
23
from __future__ import annotations
34

45
import sys

src/pyscript/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""A CLI for PyScript!"""
2+
23
import json
34
from pathlib import Path
45

src/pyscript/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""The main CLI entrypoint and commands."""
2+
23
import sys
34
from typing import Any, Optional
45

src/pyscript/plugins/create.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ def create(
6363
)
6464

6565
if not app_description:
66-
app_description = typer.prompt("App description")
66+
app_description = typer.prompt("App description", default="")
6767
if not author_name:
68-
author_name = typer.prompt("Author name")
68+
author_name = typer.prompt("Author name", default="")
6969
if not author_email:
70-
author_email = typer.prompt("Author email")
70+
author_email = typer.prompt("Author email", default="")
7171

7272
try:
7373
create_project(

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
from _pytest.monkeypatch import MonkeyPatch
66

77

8+
@pytest.fixture
9+
def auto_enter(monkeypatch):
10+
"""
11+
Monkey patch 'typer.confirm' to always hit <Enter>".
12+
"""
13+
14+
def user_hit_enter(*args, **kwargs):
15+
return ""
16+
17+
monkeypatch.setattr("typer.prompt", user_hit_enter)
18+
19+
820
@pytest.fixture()
921
def tmp_cwd(monkeypatch: MonkeyPatch, tmp_path: Path) -> Path:
1022
"""Create & return a temporary directory after setting current working directory to it."""

tests/test_cli.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import TYPE_CHECKING, Callable, Optional
4+
from typing import TYPE_CHECKING, Callable
55

66
import pytest
77
from mypy_extensions import VarArg
@@ -29,7 +29,7 @@ def app_details_args():
2929

3030

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

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

5050

51+
def test_create_command(
52+
invoke_cli: CLIInvoker, tmp_path: Path, app_details_args: list[str], auto_enter
53+
) -> None:
54+
result = invoke_cli("create", "myapp")
55+
assert result.exit_code == 0
56+
57+
expected_path = tmp_path / "myapp"
58+
assert expected_path.exists()
59+
60+
expected_main_py_path = expected_path / "main.py"
61+
assert expected_main_py_path.exists()
62+
63+
expected_config_path = expected_path / config["project_config_filename"]
64+
assert expected_config_path.exists()
65+
with expected_config_path.open() as fp:
66+
config_text = fp.read()
67+
68+
assert 'name = "myapp' in config_text
69+
# Assert that description, author name and email are empty
70+
assert 'description = ""' in config_text
71+
assert 'author_name = ""' in config_text
72+
assert 'author_email = ""' in config_text
73+
74+
5175
@pytest.mark.parametrize("flag", ["-c", "--command"])
5276
def test_wrap_command(
5377
invoke_cli: CLIInvoker, tmp_path: Path, flag: str, app_details_args: list[str]
@@ -116,7 +140,7 @@ def test_wrap_file(
116140
)
117141
def test_wrap_pyscript_version(
118142
invoke_cli: CLIInvoker,
119-
version: Optional[str],
143+
version: str | None,
120144
expected_version: str,
121145
tmp_path: Path,
122146
app_details_args: list[str],
@@ -166,7 +190,7 @@ def test_wrap_pyscript_version(
166190
)
167191
def test_wrap_pyscript_version_file(
168192
invoke_cli: CLIInvoker,
169-
version: Optional[str],
193+
version: str | None,
170194
expected_version: str,
171195
tmp_path: Path,
172196
app_details_args: list[str],

tests/test_generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exercised because of limitations in the Typer testing framework (specifically,
44
multiple "prompt" arguments).
55
"""
6+
67
import json
78
from pathlib import Path
89
from textwrap import dedent

tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

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

0 commit comments

Comments
 (0)