fast-dev-cli 0.14.1__tar.gz → 0.14.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.14.1 → fast_dev_cli-0.14.2}/PKG-INFO +1 -1
- fast_dev_cli-0.14.2/fast_dev_cli/__init__.py +1 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/fast_dev_cli/cli.py +12 -9
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/pyproject.toml +1 -1
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_bump.py +49 -36
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_functions.py +12 -6
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_lint.py +11 -1
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/utils.py +10 -0
- fast_dev_cli-0.14.1/fast_dev_cli/__init__.py +0 -1
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/LICENSE +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/README.md +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/fast_dev_cli/__main__.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/fast_dev_cli/py.typed +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/pdm_build.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/scripts/check.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/scripts/format.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/scripts/test.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/__init__.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/conftest.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_fast_test.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_poetry_version_plugin.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_runserver.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_sync.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_tag.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_upgrade.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_upload.py +0 -0
- {fast_dev_cli-0.14.1 → fast_dev_cli-0.14.2}/tests/test_version.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.14.2"
|
|
@@ -38,6 +38,7 @@ else: # pragma: no cover
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
cli = typer.Typer()
|
|
41
|
+
DryOption = Option(False, "--dry", help="Only print, not really run shell command")
|
|
41
42
|
TOML_FILE = "pyproject.toml"
|
|
42
43
|
ToolName = Literal["poetry", "pdm", "uv"]
|
|
43
44
|
|
|
@@ -348,7 +349,7 @@ def bump_version(
|
|
|
348
349
|
commit: bool = Option(
|
|
349
350
|
False, "--commit", "-c", help="Whether run `git commit` after version changed"
|
|
350
351
|
),
|
|
351
|
-
dry: bool =
|
|
352
|
+
dry: bool = DryOption,
|
|
352
353
|
) -> None:
|
|
353
354
|
"""Bump up version string in pyproject.toml"""
|
|
354
355
|
return BumpUp(_ensure_bool(commit), getattr(part, "value", part), dry=dry).run()
|
|
@@ -612,7 +613,7 @@ class UpgradeDependencies(Project, DryRun):
|
|
|
612
613
|
|
|
613
614
|
@cli.command()
|
|
614
615
|
def upgrade(
|
|
615
|
-
dry: bool =
|
|
616
|
+
dry: bool = DryOption,
|
|
616
617
|
) -> None:
|
|
617
618
|
"""Upgrade dependencies in pyproject.toml to latest versions"""
|
|
618
619
|
if (tool := Project.get_manage_tool()) == "uv":
|
|
@@ -666,7 +667,7 @@ class GitTag(DryRun):
|
|
|
666
667
|
@cli.command()
|
|
667
668
|
def tag(
|
|
668
669
|
message: str = Option("", "-m", "--message"),
|
|
669
|
-
dry: bool =
|
|
670
|
+
dry: bool = DryOption,
|
|
670
671
|
) -> None:
|
|
671
672
|
"""Run shell command: git tag -a <current-version-in-pyproject.toml> -m {message}"""
|
|
672
673
|
GitTag(message, dry=dry).run()
|
|
@@ -720,6 +721,8 @@ class LintCode(DryRun):
|
|
|
720
721
|
skip_mypy: bool = False,
|
|
721
722
|
use_dmypy: bool = False,
|
|
722
723
|
) -> str:
|
|
724
|
+
if paths != "." and all(i.endswith(".html") for i in paths.split()):
|
|
725
|
+
return f"prettier -w {paths}"
|
|
723
726
|
cmd = ""
|
|
724
727
|
tools = ["ruff format", "ruff check --extend-select=I,B,SIM --fix", "mypy"]
|
|
725
728
|
if check_only:
|
|
@@ -802,7 +805,7 @@ def make_style(
|
|
|
802
805
|
use_dmypy: bool = Option(
|
|
803
806
|
False, "--dmypy", help="Use `dmypy run` instead of `mypy`"
|
|
804
807
|
),
|
|
805
|
-
dry: bool =
|
|
808
|
+
dry: bool = DryOption,
|
|
806
809
|
) -> None:
|
|
807
810
|
"""Run: ruff check/format to reformat code and then mypy to check"""
|
|
808
811
|
if getattr(files, "default", files) is None:
|
|
@@ -822,7 +825,7 @@ def make_style(
|
|
|
822
825
|
def only_check(
|
|
823
826
|
bandit: bool = Option(False, "--bandit", help="Run `bandit -r <package_dir>`"),
|
|
824
827
|
skip_mypy: bool = Option(False, "--skip-mypy"),
|
|
825
|
-
dry: bool =
|
|
828
|
+
dry: bool = DryOption,
|
|
826
829
|
) -> None:
|
|
827
830
|
"""Check code style without reformat"""
|
|
828
831
|
check(dry=dry, bandit=bandit, skip_mypy=_ensure_bool(skip_mypy))
|
|
@@ -873,7 +876,7 @@ def sync(
|
|
|
873
876
|
save: bool = Option(
|
|
874
877
|
False, "--save", "-s", help="Whether save the requirement file"
|
|
875
878
|
),
|
|
876
|
-
dry: bool =
|
|
879
|
+
dry: bool = DryOption,
|
|
877
880
|
) -> None:
|
|
878
881
|
"""Export dependencies by poetry to a txt file then install by pip."""
|
|
879
882
|
Sync(filename, extras, save, dry=dry).run()
|
|
@@ -907,7 +910,7 @@ def test(dry: bool, ignore_script=False) -> None:
|
|
|
907
910
|
|
|
908
911
|
@cli.command(name="test")
|
|
909
912
|
def coverage_test(
|
|
910
|
-
dry: bool =
|
|
913
|
+
dry: bool = DryOption,
|
|
911
914
|
ignore_script: bool = Option(False, "--ignore-script", "-i"),
|
|
912
915
|
) -> None:
|
|
913
916
|
"""Run unittest by pytest and report coverage"""
|
|
@@ -930,7 +933,7 @@ class Publish:
|
|
|
930
933
|
|
|
931
934
|
@cli.command()
|
|
932
935
|
def upload(
|
|
933
|
-
dry: bool =
|
|
936
|
+
dry: bool = DryOption,
|
|
934
937
|
) -> None:
|
|
935
938
|
"""Shortcut for package publish"""
|
|
936
939
|
cmd = Publish.gen()
|
|
@@ -969,7 +972,7 @@ def runserver(
|
|
|
969
972
|
file_or_port: Optional[str] = typer.Argument(default=None),
|
|
970
973
|
port: Optional[int] = Option(None, "-p", "--port"),
|
|
971
974
|
host: Optional[str] = Option(None, "-h", "--host"),
|
|
972
|
-
dry: bool =
|
|
975
|
+
dry: bool = DryOption,
|
|
973
976
|
) -> None:
|
|
974
977
|
"""Start a fastapi server(only for fastapi>=0.111.0)"""
|
|
975
978
|
if getattr(file_or_port, "default", file_or_port):
|
|
@@ -17,10 +17,11 @@ from fast_dev_cli.cli import (
|
|
|
17
17
|
StrEnum,
|
|
18
18
|
bump,
|
|
19
19
|
bump_version,
|
|
20
|
+
capture_cmd_output,
|
|
20
21
|
get_current_version,
|
|
21
22
|
)
|
|
22
23
|
|
|
23
|
-
from .utils import chdir, mock_sys_argv
|
|
24
|
+
from .utils import chdir, mock_sys_argv, prepare_poetry_project
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
def test_enum():
|
|
@@ -53,12 +54,14 @@ def test_bump_dry(mocker):
|
|
|
53
54
|
mocker.patch("fast_dev_cli.cli.Project.manage_by_poetry", return_value=True)
|
|
54
55
|
with pytest.raises(ShellCommandError):
|
|
55
56
|
get_current_version()
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
mocker.patch("fast_dev_cli.cli.Project.manage_by_poetry", return_value=False)
|
|
58
|
+
version = get_current_version()
|
|
59
|
+
patch_without_commit, patch_with_commit, minor_with_commit = _bump_commands(
|
|
60
|
+
version, filename="fast_dev_cli/__init__.py"
|
|
61
|
+
)
|
|
62
|
+
assert BumpUp(part="patch", commit=False, dry=True).gen() == patch_without_commit
|
|
63
|
+
assert BumpUp(part="patch", commit=True, dry=True).gen() == patch_with_commit
|
|
64
|
+
assert BumpUp(part="minor", commit=True, dry=True).gen() == minor_with_commit
|
|
62
65
|
|
|
63
66
|
|
|
64
67
|
def test_bump(
|
|
@@ -145,36 +148,46 @@ def test_bump_with_emoji(mocker, tmp_path, monkeypatch):
|
|
|
145
148
|
mocker.patch("fast_dev_cli.cli.Project.manage_by_poetry", return_value=True)
|
|
146
149
|
with pytest.raises(ShellCommandError):
|
|
147
150
|
get_current_version()
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
151
|
+
mocker.patch("fast_dev_cli.cli.Project.manage_by_poetry", return_value=False)
|
|
152
|
+
version = get_current_version()
|
|
153
|
+
patch_without_commit, patch_with_commit, minor_with_commit = _bump_commands(
|
|
154
|
+
version, filename="fast_dev_cli/__init__.py", emoji=True
|
|
155
|
+
)
|
|
156
|
+
last_commit = "📝 Update release notes"
|
|
157
|
+
mocker.patch(
|
|
158
|
+
"fast_dev_cli.cli.BumpUp.get_last_commit_message",
|
|
159
|
+
return_value=last_commit,
|
|
160
|
+
)
|
|
161
|
+
assert BumpUp(part="patch", commit=False, dry=True).gen() == patch_without_commit
|
|
162
|
+
assert BumpUp(part="patch", commit=True, dry=True).gen() == patch_with_commit
|
|
163
|
+
assert BumpUp(part="minor", commit=True, dry=True).gen() == minor_with_commit
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def test_bump_with_emoji_in_poetry_project(mocker, tmp_path, monkeypatch):
|
|
161
167
|
# real bump
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
168
|
+
last_commit = "📝 Update release notes"
|
|
169
|
+
_, patch_with_commit, __ = _bump_commands("0.1.0", emoji=True)
|
|
170
|
+
with prepare_poetry_project(tmp_path):
|
|
171
|
+
subprocess.run(["git", "init"])
|
|
172
|
+
subprocess.run(["git", "add", "."])
|
|
173
|
+
subprocess.run(["git", "config", "user.name", "sb"])
|
|
174
|
+
subprocess.run(["git", "config", "user.email", "sb@foo.com"])
|
|
175
|
+
assert BumpUp.should_add_emoji() is False
|
|
176
|
+
subprocess.run(["git", "commit", "-m", last_commit])
|
|
177
|
+
monkeypatch.setenv("DONT_GIT_PUSH", "1")
|
|
178
|
+
command = BumpUp(part="patch", commit=True).gen()
|
|
179
|
+
expected = patch_with_commit.split("&&")[0].strip().replace('""', '"0.1.0"')
|
|
180
|
+
assert expected == command
|
|
181
|
+
subprocess.run(["poetry", "run", "pip", "install", "bumpversion2"])
|
|
182
|
+
subprocess.run(["fast", "bump", "patch", "--commit"])
|
|
183
|
+
out = capture_cmd_output(["git", "log"])
|
|
184
|
+
assert BumpUp.should_add_emoji()
|
|
185
|
+
Path("a.txt").touch()
|
|
186
|
+
subprocess.run(["git", "add", "."])
|
|
187
|
+
subprocess.run(["git", "commit", "-m", "no emoji"])
|
|
188
|
+
assert BumpUp.should_add_emoji() is False
|
|
189
|
+
new_commit = "⬆️ Bump version: 0.1.0 → 0.1.1"
|
|
190
|
+
assert new_commit in out
|
|
178
191
|
|
|
179
192
|
|
|
180
193
|
def test_bump_with_uv(tmp_path):
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from contextlib import redirect_stdout
|
|
3
3
|
from io import StringIO
|
|
4
|
+
from pathlib import Path
|
|
4
5
|
|
|
5
6
|
import pytest
|
|
6
7
|
import typer
|
|
@@ -16,6 +17,8 @@ from fast_dev_cli.cli import (
|
|
|
16
17
|
run_and_echo,
|
|
17
18
|
)
|
|
18
19
|
|
|
20
|
+
from .utils import prepare_poetry_project
|
|
21
|
+
|
|
19
22
|
|
|
20
23
|
def test_utils(capsys):
|
|
21
24
|
# parse files
|
|
@@ -64,12 +67,6 @@ def test_run_shell():
|
|
|
64
67
|
# current version
|
|
65
68
|
with pytest.raises(ShellCommandError):
|
|
66
69
|
get_current_version(True, is_poetry=True)
|
|
67
|
-
# TODO: add [tool.poetry] to pyproject.toml
|
|
68
|
-
# stream = StringIO()
|
|
69
|
-
# write_to_stream = redirect_stdout(stream)
|
|
70
|
-
# with write_to_stream:
|
|
71
|
-
# get_current_version(True, is_poetry=True)
|
|
72
|
-
# assert "poetry version -s" in stream.getvalue()
|
|
73
70
|
|
|
74
71
|
name = "TEST_EXIT_IF_RUN_FAILED"
|
|
75
72
|
value = "foo"
|
|
@@ -92,6 +89,15 @@ def test_run_shell():
|
|
|
92
89
|
A().run()
|
|
93
90
|
|
|
94
91
|
|
|
92
|
+
def test_get_version_in_poetry_project(tmp_path: Path):
|
|
93
|
+
with prepare_poetry_project(tmp_path):
|
|
94
|
+
stream = StringIO()
|
|
95
|
+
write_to_stream = redirect_stdout(stream)
|
|
96
|
+
with write_to_stream:
|
|
97
|
+
get_current_version(True, is_poetry=True)
|
|
98
|
+
assert "poetry version -s" in stream.getvalue()
|
|
99
|
+
|
|
100
|
+
|
|
95
101
|
def test_ensure_bool():
|
|
96
102
|
assert _ensure_bool(True) is True
|
|
97
103
|
assert _ensure_bool(False) is False
|
|
@@ -65,7 +65,7 @@ def test_check(mock_no_dmypy, monkeypatch, mocker):
|
|
|
65
65
|
for cmd in CHECK_CMD.split(SEP):
|
|
66
66
|
assert cmd in command
|
|
67
67
|
command2 = capture_cmd_output("fast check --bandit --dry")
|
|
68
|
-
assert command2 == command + " && bandit -r
|
|
68
|
+
assert command2 == command + " && bandit -c pyproject.toml -r ."
|
|
69
69
|
monkeypatch.setenv("FASTDEVCLI_BANDIT", "1")
|
|
70
70
|
command3 = capture_cmd_output("fast check --dry")
|
|
71
71
|
assert command3 == command2
|
|
@@ -84,6 +84,7 @@ def test_check_bandit(tmp_path):
|
|
|
84
84
|
src_dir = src_dir.parent / package_path.name
|
|
85
85
|
shutil.rmtree(src_dir)
|
|
86
86
|
with chdir(package_path):
|
|
87
|
+
assert LintCode.get_package_name() == "."
|
|
87
88
|
command = capture_cmd_output("fast check --bandit --dry")
|
|
88
89
|
assert "bandit -r ." in command
|
|
89
90
|
|
|
@@ -132,6 +133,15 @@ def test_lint_cmd(mock_no_dmypy):
|
|
|
132
133
|
)
|
|
133
134
|
|
|
134
135
|
|
|
136
|
+
def test_lint_html():
|
|
137
|
+
run = "pdm run "
|
|
138
|
+
lint_cmd = f"{run}python fast_dev_cli/cli.py lint"
|
|
139
|
+
command = capture_cmd_output(f"{lint_cmd} index.html --dry")
|
|
140
|
+
assert "prettier -w index.html" in command
|
|
141
|
+
command = capture_cmd_output(f"{lint_cmd} index.html flv.html --dry")
|
|
142
|
+
assert "prettier -w index.html flv.html" in command
|
|
143
|
+
|
|
144
|
+
|
|
135
145
|
def test_lint_by_global_fast():
|
|
136
146
|
run = "pdm run "
|
|
137
147
|
fast = Path.home() / ".local" / "bin" / "fast"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import subprocess
|
|
2
3
|
import sys
|
|
3
4
|
from contextlib import contextmanager, redirect_stdout
|
|
4
5
|
from io import StringIO
|
|
@@ -66,3 +67,12 @@ def temp_file(name: str, text=""):
|
|
|
66
67
|
yield
|
|
67
68
|
if path.exists():
|
|
68
69
|
path.unlink()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@contextmanager
|
|
73
|
+
def prepare_poetry_project(tmp_path: Path):
|
|
74
|
+
with chdir(tmp_path):
|
|
75
|
+
project = "foo"
|
|
76
|
+
subprocess.run(["poetry", "new", project])
|
|
77
|
+
with chdir(tmp_path / project):
|
|
78
|
+
yield
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.14.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|