Skip to content

Commit bd4cf0c

Browse files
authored
Merge pull request #6 from code-yeongyu/feature/improve-package
2 parents d6dce25 + a164448 commit bd4cf0c

File tree

10 files changed

+682
-374
lines changed

10 files changed

+682
-374
lines changed

.vscode/settings.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,12 @@
2222
"python.linting.mypyArgs": [
2323
"--config-file ${workspaceFolder}/pyproject.toml"
2424
],
25-
"isort.path": [
26-
"${workspaceFolder}/.venv/bin/isort"
27-
],
2825
"python.testing.pytestEnabled": true,
2926
"python.testing.pytestArgs": [
3027
"."
3128
],
3229
"emeraldwalk.runonsave": {
3330
"commands": [
34-
{
35-
"match": "\\.py$",
36-
"cmd": "${workspaceFolder}/.venv/bin/unify --in-place ${file}"
37-
},
3831
{
3932
"match": "\\.py$",
4033
"cmd": "${workspaceFolder}/.venv/bin/pautoflake --in-place ${file}"

aishell/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .open_ai_response_model import OpenAIResponseModel as OpenAIResponseModel
1+
from .open_ai_response_model import OpenAIResponseModel as OpenAIResponseModel

aishell/query_clients/gpt3_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ def _construct_prompt(self, text: str) -> str:
1919

2020
def query(self, prompt: str) -> str:
2121
prompt = self._construct_prompt(prompt)
22-
23-
completion: OpenAIResponseModel = cast(
22+
completion: OpenAIResponseModel = cast( # type: ignore [no-any-unimported]
2423
OpenAIResponseModel,
2524
openai.Completion.create(
2625
engine='text-davinci-003',

aishell/tests/sample_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
def test_one_plus_one():
2-
assert 1 + 1 == 2
2+
one = 1
3+
two = 2
4+
assert one + one == two

aishell/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .make_executable_command import make_executable_command as make_executable_command
1+
from .make_executable_command import make_executable_command as make_executable_command

aishell/utils/make_executable_command.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
def make_executable_command(command: str) -> str:
2-
# starting '\n' or trailing '\n' should be replaced as ''
3-
# starting ' ' or trailing ' ' should be replaced as ''
42
if command.startswith('\n'):
53
command = command[1:]
64
if command.endswith('\n'):

monkey_patch_invoke.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
def monkey_patch_invoke() -> None:
1010

1111
def _patched_argspec(
12-
self: Any, # pylint: disable=unused-argument
12+
self: Any, # pylint: disable=unused-argument
1313
body: Union[Callable[[Context], None], Context],
1414
) -> Tuple[List[str], Dict[str, object]]:
15-
"""
15+
'''
1616
A monkey patching code for supporting python3
1717
from: https://github.com/pyinvoke/invoke/issues/357#issuecomment-1250744013
18-
"""
18+
'''
1919
signature: inspect.Signature = inspect.Signature()
2020
if isinstance(body, types.FunctionType):
2121
signature = inspect.signature(body)
@@ -37,7 +37,7 @@ def _patched_argspec(
3737
del argument_specs[context_arg]
3838
return parameter_names, argument_specs
3939

40-
Task.argspec = _patched_argspec
40+
Task.argspec = _patched_argspec # type: ignore
4141

4242

4343
monkey_patch_invoke()

poetry.lock

Lines changed: 631 additions & 313 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors = []
1010
readme = "README.md"
1111

1212
[tool.mypy]
13-
strict = true
13+
strict = false
1414
show_error_codes = true
1515
show_column_numbers = true
1616
warn_unused_ignores = true
@@ -20,8 +20,8 @@ namespace_packages = true
2020
allow_redefinition = true
2121
implicit_reexport = false
2222
no_implicit_optional = true
23-
warn_return_any = true
24-
disallow_any_expr = true
23+
warn_return_any = false
24+
disallow_any_expr = false
2525
disallow_any_unimported = true
2626
check_untyped_defs = true
2727
allow_incomplete_defs = true
@@ -48,7 +48,7 @@ reportUnknownMemberType = false
4848

4949
[tool.yapf]
5050
based_on_style = "pep8"
51-
spaces_before_comment = 4
51+
spaces_before_comment = 2
5252
split_before_logical_operator = true
5353
column_limit = 119
5454
allow_split_before_dict_value = false
@@ -86,14 +86,12 @@ multiline-quotes = "single"
8686
[tool.poetry.group.dev.dependencies]
8787
toml = "^0.10.2"
8888
yapf = "^0.32.0"
89-
unify = "^0.5"
9089
pytest = "^7.2.0"
9190
pytest-cov = "^4.0.0"
9291
mypy = "^0.991"
93-
pyright = "^1.1.285"
94-
colorama = "^0.4.6"
9592
invoke = "^1.7.3"
9693
ruff = "^0.0.199"
9794
pyproject-autoflake = "^1.0.2"
9895
types-invoke = "^1.7.3.16"
9996
types-toml = "^0.10.8.1"
97+
pyright = "^1.1.294"

tasks.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
# type: ignore
12
import shutil
3+
import subprocess
24

35
import toml
4-
from colorama import Fore
5-
from colorama import init as init_colorama
66
from invoke import Context, task
7+
from rich.console import Console
78

8-
import monkey_patch_invoke as _ # noqa
9+
import monkey_patch_invoke as _ # noqa: F401
10+
11+
console = Console()
912

1013

1114
def get_pep8_compliant_name(project_name: str) -> str:
@@ -19,6 +22,14 @@ def get_project_path():
1922
return project_name
2023

2124

25+
def execute_command(command: str) -> dict[str, str]:
26+
with subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
27+
stdout, stderr = process.communicate()
28+
if process.returncode != 0:
29+
raise Exception(stderr.decode())
30+
return {'command': command, 'result': stdout.decode()}
31+
32+
2233
@task
2334
def run(context: Context):
2435
context.run(f'python {get_project_path()}/main.py', pty=True)
@@ -30,20 +41,23 @@ def test(context: Context):
3041

3142

3243
@task
33-
def format_code(context: Context) -> None:
34-
init_colorama()
35-
36-
print(f'{Fore.MAGENTA}==========Remove unused imports with `autoflake`=========={Fore.RESET}')
37-
context.run(f'pautoflake {get_project_path()}', pty=True)
38-
39-
print(f'{Fore.MAGENTA}==========Sort imports with `isort`=========={Fore.RESET}')
40-
context.run(f'isort {get_project_path()}', pty=True)
44+
def format_code(context: Context, verbose: bool = False) -> None:
45+
commands = [
46+
f'pautoflake {get_project_path()}',
47+
f'ruff --fix {get_project_path()}',
48+
f'yapf --in-place --recursive --parallel {get_project_path()}',
49+
]
50+
results: list[dict[str, str]] = []
51+
with console.status('[bold green] Formatting code...'):
52+
for command in commands:
53+
results.append(execute_command(command))
4154

42-
print(f'{Fore.MAGENTA}==========Unifying quotes with `unify`=========={Fore.RESET}')
43-
context.run(f'unify --in-place -r {get_project_path()}')
55+
if verbose:
56+
for result in results:
57+
console.print(f'$ {result["command"]}')
58+
console.print(result['result'])
4459

45-
print(f'{Fore.MAGENTA}==========Format code with `yapf`=========={Fore.RESET}')
46-
context.run(f'yapf --in-place --recursive --parallel {get_project_path()}', pty=True)
60+
console.print('[bold green]Success[/bold green]')
4761

4862

4963
@task
@@ -54,32 +68,18 @@ def check(context: Context):
5468

5569
@task
5670
def check_code_style(context: Context):
57-
init_colorama()
71+
commands = [
72+
f'pautoflake {get_project_path()} --check',
73+
f'ruff {get_project_path()}',
74+
f'yapf --diff --recursive --parallel {get_project_path()}',
75+
]
5876

59-
print(f'{Fore.MAGENTA}==========Check Code Styles with `autoflake`=========={Fore.GREEN}')
60-
context.run(f'pautoflake {get_project_path()} --check', pty=True)
61-
62-
print(f'{Fore.MAGENTA}==========Check Code Styles with `isort`=========={Fore.GREEN}')
63-
context.run(f'isort {get_project_path()} --check --diff', pty=True)
64-
print(f'{Fore.GREEN}isort: Success{Fore.RESET}')
65-
66-
print(f'{Fore.MAGENTA}==========Check Code Styles with `pylint`=========={Fore.GREEN}')
67-
context.run(f'pylint {get_project_path()}', pty=True)
68-
69-
print(f'{Fore.MAGENTA}==========Check Code Styles with `yapf`=========={Fore.RESET}')
70-
context.run(f'yapf --diff --recursive --parallel {get_project_path()}', pty=True)
71-
print(f'{Fore.GREEN}yapf: Success{Fore.RESET}')
77+
for command in commands:
78+
context.run(command, pty=True)
7279

7380

7481
@task
7582
def check_types(context: Context):
76-
"""Check types with `pyright` and `mypy`."""
77-
init_colorama()
78-
79-
print(f'{Fore.CYAN}==========Check typings with `pyright`=========={Fore.RESET}')
80-
context.run(f'pyright {get_project_path()}', pty=True)
81-
82-
print(f'\n{Fore.CYAN}==========Check typings with `mypy`=========={Fore.RESET}')
8383
context.run(f'mypy {get_project_path()}', pty=True)
8484

8585

0 commit comments

Comments
 (0)