Skip to content

Commit 7214529

Browse files
committed
✨ add developer tools choices in 'simple' template
1 parent 96a5d89 commit 7214529

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ docs_build/_build
99
website/docs/api/**/*.md
1010
website/static/packages/*.whl
1111
!nb_cli/template/project/*/{{cookiecutter.computed.project_slug}}/.env*
12+
!nb_cli/template/project/simple/{{cookiecutter.computed.project_slug}}/.vscode
1213

1314
# Created by https://www.toptal.com/developers/gitignore/api/node,macos,linux,python,windows,jetbrains,visualstudiocode
1415
# Edit at https://www.toptal.com/developers/gitignore?templates=node,macos,linux,python,windows,jetbrains,visualstudiocode

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ repos:
3131
- id: prettier
3232
types_or: [javascript, jsx, ts, tsx, markdown, yaml, json]
3333
stages: [pre-commit]
34+
exclude: ^nb_cli/template/project/.*\.json$
3435

3536
- repo: https://github.com/nonebot/nonemoji
3637
rev: v0.1.4

nb_cli/cli/commands/project.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ def project_name_validator(name: str) -> bool:
7575
)
7676

7777

78+
def project_devtools_validator(devtools: tuple[Choice[str], ...]) -> bool:
79+
expanded = {ch.data for ch in devtools}
80+
return bool({"pyright", "basedpyright"} - expanded)
81+
82+
7883
async def prompt_common_context(context: ProjectContext) -> ProjectContext:
7984
click.secho(_("Loading adapters..."))
8085
all_adapters = await list_adapters()
@@ -203,6 +208,23 @@ async def prompt_simple_context(context: ProjectContext) -> ProjectContext:
203208
style=CLI_DEFAULT_STYLE
204209
)
205210
).data
211+
context.variables["devtools"] = [
212+
ch.data
213+
for ch in await CheckboxPrompt(
214+
_("Which developer tool(s) would you like to use?"),
215+
[
216+
Choice(_("Pylance (Recommended)"), "pyright"),
217+
Choice(_("Ruff"), "ruff"),
218+
Choice(_("MyPy"), "mypy"),
219+
Choice(_("BasedPyright (Advanced user)"), "basedpyright"),
220+
],
221+
[0, 1],
222+
validator=project_devtools_validator,
223+
error_message=_(
224+
"Cannot choose 'Pylance' and 'BasedPyright' at the same time."
225+
),
226+
).prompt_async(style=CLI_DEFAULT_STYLE)
227+
]
206228

207229
return context
208230

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"recommendations": [
3+
{%- set extensions = ['"tamasfe.even-better-toml"'] -%}
4+
{% if "pyright" in cookiecutter.nonebot.devtools -%}
5+
{% set _ = extensions.append('"ms-python.python"') %}
6+
{%- endif -%}
7+
{% if "mypy" in cookiecutter.nonebot.devtools -%}
8+
{% set _ = extensions.append('"ms-python.mypy-type-checker"') %}
9+
{%- endif -%}
10+
{% if "basedpyright" in cookiecutter.nonebot.devtools -%}
11+
{% set _ = extensions.append('"detachhead.basedpyright"') %}
12+
{%- endif -%}
13+
{% if "ruff" in cookiecutter.nonebot.devtools -%}
14+
{% set _ = extensions.append('"charliermarsh.ruff"') %}
15+
{%- endif %}
16+
{{ extensions|join(",\n")|indent(4) }}
17+
]
18+
}

nb_cli/template/project/simple/{{cookiecutter.computed.project_slug}}/pyproject.toml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,60 @@ builtin_plugins = []
4444

4545
[tool.nonebot.plugins]
4646
"@local" = []
47+
{% if "ruff" in cookiecutter.nonebot.devtools -%}
48+
49+
[tool.ruff]
50+
line-length = 88
51+
target-version = "py39"
52+
53+
[tool.ruff.format]
54+
line-ending = "lf"
55+
56+
[tool.ruff.lint]
57+
# For more rules, see https://docs.astral.sh/ruff/rules/.
58+
select = [
59+
"F", # Pyflakes
60+
"W", # pycodestyle warnings
61+
"E", # pycodestyle errors
62+
"I", # isort
63+
"UP", # pyupgrade
64+
"ANN", # flake8-annotations
65+
"ASYNC", # flake8-async
66+
"C4", # flake8-comprehensions
67+
"T10", # flake8-debugger
68+
"T20", # flake8-print
69+
"PYI", # flake8-pyi
70+
"Q", # flake8-quotes
71+
"TID", # flake8-tidy-imports
72+
"RUF", # Ruff-specific rules
73+
]
74+
ignore = [
75+
"E402", # module-import-not-at-top-of-file
76+
"UP037", # quoted-annotation
77+
"RUF001", # ambiguous-unicode-character-string
78+
"RUF002", # ambiguous-unicode-character-docstring
79+
"RUF003", # ambiguous-unicode-character-comment
80+
"ANN202", # missing-return-type-private-function
81+
"ANN401", # any-type
82+
]
83+
84+
[tool.ruff.lint.pyupgrade]
85+
keep-runtime-typing = true
86+
{% endif -%}
87+
{% if "pyright" in cookiecutter.nonebot.devtools or "basedpyright" in cookiecutter.nonebot.devtools %}
88+
{% if "pyright" in cookiecutter.nonebot.devtools -%}
89+
[tool.pyright]
90+
# For Pylance/Pyright configurations, see https://microsoft.github.io/pyright/#/configuration.
91+
{%- else -%}
92+
[tool.basedpyright]
93+
# For BasedPyright configurations, see https://docs.basedpyright.com/latest/configuration/config-files/.
94+
{%- endif %}
95+
pythonVersion = "3.9"
96+
pythonPlatform = "All"
97+
typeCheckingMode = "standard"
98+
{%- endif %}
99+
{% if "mypy" in cookiecutter.nonebot.devtools %}
100+
[tool.mypy]
101+
# For MyPy configurations, see https://mypy.readthedocs.io/en/latest/config_file.html.
102+
python_version = "3.9"
103+
{% endif -%}

0 commit comments

Comments
 (0)