fast-dev-cli 0.7.1__tar.gz → 0.7.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fast_dev_cli-0.7.1 → fast_dev_cli-0.7.2}/PKG-INFO +1 -1
- {fast_dev_cli-0.7.1 → fast_dev_cli-0.7.2}/fast_dev_cli/cli.py +48 -9
- {fast_dev_cli-0.7.1 → fast_dev_cli-0.7.2}/pyproject.toml +1 -1
- {fast_dev_cli-0.7.1 → fast_dev_cli-0.7.2}/LICENSE +0 -0
- {fast_dev_cli-0.7.1 → fast_dev_cli-0.7.2}/README.md +0 -0
- {fast_dev_cli-0.7.1 → fast_dev_cli-0.7.2}/fast_dev_cli/__init__.py +0 -0
- {fast_dev_cli-0.7.1 → fast_dev_cli-0.7.2}/fast_dev_cli/__main__.py +0 -0
- {fast_dev_cli-0.7.1 → fast_dev_cli-0.7.2}/fast_dev_cli/py.typed +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import importlib.metadata
|
|
2
4
|
import os
|
|
3
5
|
import re
|
|
@@ -6,7 +8,7 @@ import sys
|
|
|
6
8
|
from functools import cached_property
|
|
7
9
|
from pathlib import Path
|
|
8
10
|
from subprocess import CompletedProcess
|
|
9
|
-
from typing import Type
|
|
11
|
+
from typing import TYPE_CHECKING, Optional, Type
|
|
10
12
|
|
|
11
13
|
if sys.version_info >= (3, 11):
|
|
12
14
|
from enum import StrEnum
|
|
@@ -15,6 +17,9 @@ else: # pragma: no cover
|
|
|
15
17
|
from strenum import StrEnum # type:ignore[no-redef,assignment]
|
|
16
18
|
from typing_extensions import Self
|
|
17
19
|
|
|
20
|
+
if TYPE_CHECKING:
|
|
21
|
+
from typer.models import OptionInfo
|
|
22
|
+
|
|
18
23
|
|
|
19
24
|
__version__ = importlib.metadata.version(Path(__file__).parent.name)
|
|
20
25
|
|
|
@@ -120,11 +125,17 @@ def get_current_version(verbose=False) -> str:
|
|
|
120
125
|
return capture_cmd_output(cmd)
|
|
121
126
|
|
|
122
127
|
|
|
128
|
+
def _ensure_bool(value: bool | "OptionInfo") -> bool:
|
|
129
|
+
if not isinstance(value, bool):
|
|
130
|
+
value = getattr(value, "default", False)
|
|
131
|
+
return value
|
|
132
|
+
|
|
133
|
+
|
|
123
134
|
def exit_if_run_failed(
|
|
124
135
|
cmd: str, env=None, _exit=False, dry=False, **kw
|
|
125
136
|
) -> CompletedProcess:
|
|
126
137
|
run_and_echo(cmd, dry=True)
|
|
127
|
-
if dry:
|
|
138
|
+
if _ensure_bool(dry):
|
|
128
139
|
return CompletedProcess("", 0)
|
|
129
140
|
if env is not None:
|
|
130
141
|
env = {**os.environ, **env}
|
|
@@ -220,7 +231,7 @@ def bump_version(
|
|
|
220
231
|
dry: bool = Option(False, "--dry", help="Only print, not really run shell command"),
|
|
221
232
|
) -> None:
|
|
222
233
|
"""Bump up version string in pyproject.toml"""
|
|
223
|
-
return BumpUp(commit, part.value, dry=dry).run()
|
|
234
|
+
return BumpUp(_ensure_bool(commit), part.value, dry=dry).run()
|
|
224
235
|
|
|
225
236
|
|
|
226
237
|
def bump() -> None:
|
|
@@ -530,6 +541,8 @@ class LintCode(DryRun):
|
|
|
530
541
|
def lint(files=None, dry=False) -> None:
|
|
531
542
|
if files is None:
|
|
532
543
|
files = parse_files(sys.argv[1:])
|
|
544
|
+
if files and files[0] == "lint":
|
|
545
|
+
files = files[1:]
|
|
533
546
|
LintCode(files, dry=dry).run()
|
|
534
547
|
|
|
535
548
|
|
|
@@ -546,7 +559,7 @@ def make_style(
|
|
|
546
559
|
"""Run: ruff check/format to reformat code and then mypy to check"""
|
|
547
560
|
if isinstance(files, str):
|
|
548
561
|
files = [files]
|
|
549
|
-
if check_only:
|
|
562
|
+
if _ensure_bool(check_only):
|
|
550
563
|
check(files, dry=dry)
|
|
551
564
|
else:
|
|
552
565
|
lint(files, dry=dry)
|
|
@@ -601,18 +614,20 @@ def _should_run_test_script(path: Path) -> bool:
|
|
|
601
614
|
return path.exists()
|
|
602
615
|
|
|
603
616
|
|
|
604
|
-
@cli.command()
|
|
605
|
-
def
|
|
617
|
+
@cli.command(name="test")
|
|
618
|
+
def coverage_test(
|
|
606
619
|
dry: bool = Option(False, "--dry", help="Only print, not really run shell command"),
|
|
607
620
|
ignore_script: bool = Option(False, "--ignore-script", "-i"),
|
|
608
621
|
) -> None:
|
|
609
622
|
"""Run unittest by pytest and report coverage"""
|
|
623
|
+
return test(dry, ignore_script)
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
def test(dry: bool, ignore_script=False) -> None:
|
|
610
627
|
cwd = Path.cwd()
|
|
611
628
|
root = Project.get_work_dir(cwd=cwd, allow_cwd=True)
|
|
612
629
|
test_script = root / "scripts" / "test.sh"
|
|
613
|
-
if not
|
|
614
|
-
ignore_script = getattr(ignore_script, "default", False)
|
|
615
|
-
if not ignore_script and _should_run_test_script(test_script):
|
|
630
|
+
if not _ensure_bool(ignore_script) and _should_run_test_script(test_script):
|
|
616
631
|
cmd = f"sh {test_script.relative_to(root)}"
|
|
617
632
|
if cwd != root:
|
|
618
633
|
cmd = f"cd {root} && " + cmd
|
|
@@ -633,5 +648,29 @@ def upload(
|
|
|
633
648
|
exit_if_run_failed(cmd, dry=dry)
|
|
634
649
|
|
|
635
650
|
|
|
651
|
+
def dev(
|
|
652
|
+
port: int | None | "OptionInfo", host: str | None | "OptionInfo", dry=False
|
|
653
|
+
) -> None:
|
|
654
|
+
cmd = "fastapi dev"
|
|
655
|
+
if (port := getattr(port, "default", port)) and port != 8000:
|
|
656
|
+
cmd += f" --port={port}"
|
|
657
|
+
if (host := getattr(host, "default", host)) and host not in (
|
|
658
|
+
"localhost",
|
|
659
|
+
"127.0.0.1",
|
|
660
|
+
):
|
|
661
|
+
cmd += f" --host={host}"
|
|
662
|
+
exit_if_run_failed(cmd, dry=dry)
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
@cli.command(name="dev")
|
|
666
|
+
def runserver(
|
|
667
|
+
port: Optional[int] = Option(None, "-p", "--port"),
|
|
668
|
+
host: Optional[str] = Option(None, "-h", "--host"),
|
|
669
|
+
dry: bool = Option(False, "--dry", help="Only print, not really run shell command"),
|
|
670
|
+
) -> None:
|
|
671
|
+
"""Check code style without reformat"""
|
|
672
|
+
dev(port, host, dry=dry)
|
|
673
|
+
|
|
674
|
+
|
|
636
675
|
if __name__ == "__main__":
|
|
637
676
|
cli() # pragma: no cover
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|