Skip to content

Commit 421fbaa

Browse files
committed
fix ruff rule I and format Q
1 parent 9cdfae2 commit 421fbaa

File tree

11 files changed

+108
-102
lines changed

11 files changed

+108
-102
lines changed

fastapi_ccli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
__version__ = "0.0.2"
4+
__version__ = '0.0.2'

fastapi_ccli/cloner/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import typer
44

55
# Boolean fonts
6-
GREEN = typer.style("True", fg="green", bold=True)
7-
RED = typer.style("False", fg="red", bold=True)
6+
GREEN = typer.style('True', fg='green', bold=True)
7+
RED = typer.style('False', fg='red', bold=True)
88

99
# GitHub src
10-
github_fba_src = "https://github.com/wu-clan/fastapi_best_architecture.git"
11-
github_ftm_src = "https://github.com/wu-clan/fastapi_tortoise_mysql.git"
12-
github_fsm_src = "https://github.com/fastapi-practices/fastapi_sqlmodel_mysql.git"
10+
github_fba_src = 'https://github.com/wu-clan/fastapi_best_architecture.git'
11+
github_ftm_src = 'https://github.com/wu-clan/fastapi_tortoise_mysql.git'
12+
github_fsm_src = 'https://github.com/fastapi-practices/fastapi_sqlmodel_mysql.git'
1313

1414
# Gitee src
15-
gitee_fba_src = "https://gitee.com/wu_cl/fastapi_best_architecture.git"
16-
gitee_ftm_src = "https://gitee.com/wu_cl/fastapi_tortoise_mysql.git"
15+
gitee_fba_src = 'https://gitee.com/wu_cl/fastapi_best_architecture.git'
16+
gitee_ftm_src = 'https://gitee.com/wu_cl/fastapi_tortoise_mysql.git'

fastapi_ccli/cloner/cloner_en.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
import os
44
import re
55
import time
6+
67
from pathlib import Path
78
from typing import Optional
89

910
import typer
11+
1012
from rich import print
1113

1214
from fastapi_ccli import __version__
13-
from fastapi_ccli.cloner import GREEN, RED, github_fba_src, github_ftm_src, github_fsm_src, gitee_fba_src, gitee_ftm_src
15+
from fastapi_ccli.cloner import GREEN, RED, gitee_fba_src, gitee_ftm_src, github_fba_src, github_fsm_src, github_ftm_src
1416
from fastapi_ccli.utils.get_country import get_current_country
1517
from fastapi_ccli.utils.get_ip import get_net_ip
1618
from fastapi_ccli.utils.get_path import get_project_path
1719

18-
app_en = typer.Typer(rich_markup_mode="rich")
20+
app_en = typer.Typer(rich_markup_mode='rich')
1921

2022

2123
def is_china(dns: bool) -> str:
@@ -25,7 +27,7 @@ def is_china(dns: bool) -> str:
2527
:param dns:
2628
:return:
2729
"""
28-
with typer.progressbar(range(5), label="Analyzing") as progress:
30+
with typer.progressbar(range(5), label='Analyzing') as progress:
2931
for i in progress:
3032
ip = get_net_ip()
3133
if ip:
@@ -36,7 +38,7 @@ def is_china(dns: bool) -> str:
3638
progress.update(i)
3739
continue
3840
rp = get_current_country(ip)
39-
if "CN" in rp:
41+
if 'CN' in rp:
4042
ending = GREEN if dns else RED
4143
else:
4244
ending = RED if dns else GREEN
@@ -53,47 +55,47 @@ def exec_clone(orm: str, country: str, project: str, path: str) -> None:
5355
:param path:
5456
:return:
5557
"""
56-
typer.echo("Project name: " + typer.style(project, fg="blue", bold=True))
57-
typer.echo("Select orm: " + orm)
58-
if orm == "sqlalchemy":
59-
source = github_fba_src if "True" in country else gitee_fba_src
60-
elif orm == "tortoise":
61-
source = github_ftm_src if "True" in country else gitee_ftm_src
62-
elif orm == "sqlmodel":
58+
typer.echo('Project name: ' + typer.style(project, fg='blue', bold=True))
59+
typer.echo('Select orm: ' + orm)
60+
if orm == 'sqlalchemy':
61+
source = github_fba_src if 'True' in country else gitee_fba_src
62+
elif orm == 'tortoise':
63+
source = github_ftm_src if 'True' in country else gitee_ftm_src
64+
elif orm == 'sqlmodel':
6365
source = github_fsm_src
6466
try:
6567
print(f"⏳ Start clone {source.split('/')[-1].split('.')[0]} project...") # noqa
66-
out = os.system(f"git clone {source} {path}")
68+
out = os.system(f'git clone {source} {path}')
6769
if out != 0:
6870
raise RuntimeError(out)
6971
except Exception as e:
70-
print(f"❌ Clone project failed: {e}")
72+
print(f'❌ Clone project failed: {e}')
7173
raise typer.Exit(1)
7274
else:
73-
print("✅ The project was cloned successfully")
75+
print('✅ The project was cloned successfully')
7476
typer.echo(f"Please go to the directory {typer.style(path, fg='green', bold=True)} to view")
7577

7678

77-
@app_en.command(epilog="Made by :beating_heart: wu-clan")
79+
@app_en.command(epilog='Made by :beating_heart: wu-clan')
7880
def cloner(
7981
version: Optional[bool] = typer.Option(
8082
None,
81-
"--version",
82-
"-V",
83-
help="Print version information.",
83+
'--version',
84+
'-V',
85+
help='Print version information.',
8486
),
8587
orm: Optional[str] = typer.Option(
86-
"sqlalchemy",
87-
"--orm",
88-
"-o",
89-
metavar="<ORM>",
88+
'sqlalchemy',
89+
'--orm',
90+
'-o',
91+
metavar='<ORM>',
9092
help="Select the orm to use, the default is sqlalchemy, support 'sqlalchemy' / 'tortoise' / 'sqlmodel'.",
9193
),
9294
project_path: Optional[str] = typer.Option(
9395
None,
94-
"--path",
95-
"-p",
96-
metavar="<PATH>",
96+
'--path',
97+
'-p',
98+
metavar='<PATH>',
9799
show_default=False,
98100
help="Project clone path, the default is '../fastapi_project', supports absolute path or relative path.",
99101
),
@@ -102,16 +104,16 @@ def cloner(
102104
FastAPI project cloner
103105
"""
104106
if version:
105-
typer.secho("\n🔥 FastAPI CCLI " + __version__, fg="green", bold=True)
107+
typer.secho('\n🔥 FastAPI CCLI ' + __version__, fg='green', bold=True)
106108
if orm:
107-
if orm not in ["sqlalchemy", "tortoise", "sqlmodel"]:
109+
if orm not in ['sqlalchemy', 'tortoise', 'sqlmodel']:
108110
raise typer.BadParameter("Enter unknown parameters, only allowed 'sqlalchemy' / 'tortoise' / 'sqlmodel'")
109111
if project_path:
110112
if not Path(project_path).is_dir():
111-
raise typer.BadParameter("Wrong parameter input, please enter the correct path")
112-
use_project_name = project_path or "../fastapi_project"
113+
raise typer.BadParameter('Wrong parameter input, please enter the correct path')
114+
use_project_name = project_path or '../fastapi_project'
113115
path = get_project_path(use_project_name)
114-
project_name = re.split(r"/|\'|\\|\\\\", use_project_name)[-1]
115-
_country = typer.confirm("Is your region China?", default=False)
116+
project_name = re.split(r'/|\'|\\|\\\\', use_project_name)[-1]
117+
_country = typer.confirm('Is your region China?', default=False)
116118
country = is_china(_country)
117119
exec_clone(orm, country, project_name, path)
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
import re
4+
45
from pathlib import Path
56
from typing import Optional
67

@@ -11,22 +12,22 @@
1112
from fastapi_ccli.cloner.cloner_en import exec_clone, is_china
1213
from fastapi_ccli.utils.get_path import get_project_path
1314

14-
app_en_form = typer.Typer(rich_markup_mode="rich")
15+
app_en_form = typer.Typer(rich_markup_mode='rich')
1516

1617

17-
@app_en_form.command(epilog="Made by :beating_heart: wu-clan")
18+
@app_en_form.command(epilog='Made by :beating_heart: wu-clan')
1819
def cloner(
1920
version: Optional[bool] = typer.Option(
2021
None,
21-
"--version",
22-
"-V",
23-
help="Print version information.",
22+
'--version',
23+
'-V',
24+
help='Print version information.',
2425
),
2526
project_path: Optional[str] = typer.Option(
2627
None,
27-
"--path",
28-
"-p",
29-
metavar="<PATH>",
28+
'--path',
29+
'-p',
30+
metavar='<PATH>',
3031
show_default=False,
3132
help="Project clone path, the default is '../fastapi_project', supports absolute path or relative path.",
3233
),
@@ -35,23 +36,23 @@ def cloner(
3536
FastAPI project cloner
3637
"""
3738
if version:
38-
typer.secho("\n🔥 FastAPI CCLI " + __version__, fg="green", bold=True)
39+
typer.secho('\n🔥 FastAPI CCLI ' + __version__, fg='green', bold=True)
3940
if project_path:
4041
if not Path(project_path).is_dir():
41-
raise typer.BadParameter("Wrong parameter input, please enter the correct path")
42-
use_project_name = project_path or "../fastapi_project"
42+
raise typer.BadParameter('Wrong parameter input, please enter the correct path')
43+
use_project_name = project_path or '../fastapi_project'
4344
path = get_project_path(use_project_name)
44-
project_name = re.split(r"/|\'|\\|\\\\", use_project_name)[-1]
45+
project_name = re.split(r'/|\'|\\|\\\\', use_project_name)[-1]
4546
result_if = questionary.form(
4647
orm=questionary.select(
47-
"Please select the orm you want to use:",
48-
choices=["sqlalchemy", "tortoise", "sqlmodel"],
49-
default="sqlalchemy",
48+
'Please select the orm you want to use:',
49+
choices=['sqlalchemy', 'tortoise', 'sqlmodel'],
50+
default='sqlalchemy',
5051
),
51-
country=questionary.select("Is your region China?", choices=["Yes", "No"], default="No"),
52+
country=questionary.select('Is your region China?', choices=['Yes', 'No'], default='No'),
5253
).ask()
5354
if len(result_if) == 0:
5455
raise typer.Exit(1)
55-
country = is_china(result_if["country"])
56-
orm = result_if["orm"]
56+
country = is_china(result_if['country'])
57+
orm = result_if['orm']
5758
exec_clone(orm, country, project_name, path)

fastapi_ccli/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@
1111

1212
def run():
1313
if not len(sys.argv) > 1:
14-
typer.secho("\nMissing command line parameters, try '--help' for help.", fg="red")
14+
typer.secho("\nMissing command line parameters, try '--help' for help.", fg='red')
1515
else:
16-
if any(sys.argv[1] == _ for _ in ["--version", "-V"]):
16+
if any(sys.argv[1] == _ for _ in ['--version', '-V']):
1717
app_en()
1818
else:
1919
select_run_type = questionary.form(
2020
interactive=questionary.select(
21-
"Whether to run in interactive mode?",
22-
choices=["yes", "no"],
23-
default="yes",
21+
'Whether to run in interactive mode?',
22+
choices=['yes', 'no'],
23+
default='yes',
2424
)
2525
).ask()
2626
if len(select_run_type) == 0:
2727
raise typer.Exit(1)
28-
if select_run_type.get("interactive") == "yes":
28+
if select_run_type.get('interactive') == 'yes':
2929
app_en_form()
3030
else:
3131
app_en()
3232

3333

34-
if __name__ == "__main__":
34+
if __name__ == '__main__':
3535
run()

fastapi_ccli/utils/get_country.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ def get_current_country(ip: Union[str, None]) -> str:
1212
:param ip:
1313
:return:
1414
"""
15-
proxy = {"http": None, "https": None} # extra
15+
proxy = {'http': None, 'https': None} # extra
1616
try:
1717
if ip:
18-
rp = request.get(f"https://ip.useragentinfo.com/json?ip={ip}", proxies=proxy).json()["short_name"]
18+
rp = request.get(f'https://ip.useragentinfo.com/json?ip={ip}', proxies=proxy).json()['short_name']
1919
else:
20-
rp = request.get("https://ip.useragentinfo.com/json?ip=", proxies=proxy).json()["short_name"]
20+
rp = request.get('https://ip.useragentinfo.com/json?ip=', proxies=proxy).json()['short_name']
2121
except Exception: # noqa
22-
rp = "Unknown"
22+
rp = 'Unknown'
2323

2424
return rp

fastapi_ccli/utils/get_ip.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ def get_net_ip() -> str:
1313
"""
1414
timeout = 3
1515
try:
16-
ip = request.get("https://checkip.amazonaws.com/", timeout=timeout).text.strip()
16+
ip = request.get('https://checkip.amazonaws.com/', timeout=timeout).text.strip()
1717
if not ip:
18-
ip = request.get("https://jsonip.com/", timeout=timeout).json()["ip"]
18+
ip = request.get('https://jsonip.com/', timeout=timeout).json()['ip']
1919
except JSONDecodeError:
20-
ip = request.get("https://api.ipify.org/", timeout=timeout).text.strip()
20+
ip = request.get('https://api.ipify.org/', timeout=timeout).text.strip()
2121
if not ip:
22-
ip = request.get("https://ip.42.pl/raw", timeout=timeout).text.strip()
22+
ip = request.get('https://ip.42.pl/raw', timeout=timeout).text.strip()
2323
except Exception: # noqa
2424
ip = None
2525

fastapi_ccli/utils/get_path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_project_path(project_path: str) -> str:
99
1010
:return:
1111
"""
12-
path_resolve = project_path if not project_path.startswith("..") else os.path.abspath(project_path)
13-
path = path_resolve if not path_resolve.startswith(".") else os.path.abspath(project_path)
12+
path_resolve = project_path if not project_path.startswith('..') else os.path.abspath(project_path)
13+
path = path_resolve if not path_resolve.startswith('.') else os.path.abspath(project_path)
1414

1515
return path

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ lint = [
4141
]
4242

4343
[tool.ruff]
44+
extend-select = ["I"]
4445
line-length = 120
4546
cache-dir = "./.ruff_cache"
4647

4748
[tool.ruff.isort]
49+
lines-between-types = 1
4850
order-by-type = true
4951

50-
[tool.ruff.flake8-quotes]
51-
inline-quotes = "single"
52-
multiline-quotes = "single"
52+
[tool.ruff.format]
53+
quote-style = "single"
5354

5455
[build-system]
5556
requires = ["pdm-backend"]

0 commit comments

Comments
 (0)