Skip to content

Commit

Permalink
✨ add ruff config
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Aug 1, 2023
1 parent ed4f878 commit d6797d8
Show file tree
Hide file tree
Showing 9 changed files with 486 additions and 502 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Ruff Lint

on:
push:
branches:
- master
pull_request:

jobs:
ruff:
name: Ruff Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run Ruff Lint
uses: chartboost/ruff-action@v1
4 changes: 2 additions & 2 deletions nb_cli/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def _set_global_use_venv(ctx: click.Context, param: click.Option, value: bool):
@click.pass_context
@run_async
async def cli(ctx: click.Context):
# postpone scripts discovery, only when needed (invoked)
# see {ref}`CLIMainGroup.get_command <nb_cli.cli.customize.CLIMainGroup.get_command>`
# Postpone scripts discovery, only when needed (invoked). See
# {ref}`CLIMainGroup.get_command <nb_cli.cli.customize.CLIMainGroup.get_command>`

if ctx.invoked_subcommand is not None:
return
Expand Down
3 changes: 2 additions & 1 deletion nb_cli/cli/commands/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ async def create(
click.secho(_("Done!"), fg="green")
click.secho(
_(
"Add following packages to your project using dependency manager like poetry or pdm:"
"Add following packages to your project "
"using dependency manager like poetry or pdm:"
),
fg="green",
)
Expand Down
10 changes: 5 additions & 5 deletions nb_cli/cli/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ def __init__(self, *args, **kwargs) -> None:

class ClickAliasedGroup(click.Group):
def __init__(self, *args, **kwargs):
super(ClickAliasedGroup, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._commands: Dict[str, List[str]] = {}
self._aliases: Dict[str, str] = {}

def command(self, *args, **kwargs):
cls = kwargs.pop("cls", ClickAliasedCommand)
return super(ClickAliasedGroup, self).command(*args, cls=cls, **kwargs)
return super().command(*args, cls=cls, **kwargs)

def group(self, *args, **kwargs):
aliases: Optional[List[str]] = kwargs.pop("aliases", None)
decorator = super(ClickAliasedGroup, self).group(*args, **kwargs)
decorator = super().group(*args, **kwargs)
if not aliases:
return decorator

Expand All @@ -54,11 +54,11 @@ def add_command(self, cmd: click.Command, name: Optional[str] = None) -> None:
aliases: Optional[List[str]] = getattr(cmd, "_aliases", None)
if aliases and isinstance(cmd, ClickAliasedCommand) and cmd.name:
self.add_aliases(cmd.name, aliases)
return super(ClickAliasedGroup, self).add_command(cmd, name=name)
return super().add_command(cmd, name=name)

def get_command(self, ctx: click.Context, cmd_name: str):
cmd_name = self.resolve_alias(cmd_name)
if command := super(ClickAliasedGroup, self).get_command(ctx, cmd_name):
if command := super().get_command(ctx, cmd_name):
return command

def list_commands(self, ctx: click.Context) -> List[str]:
Expand Down
3 changes: 2 additions & 1 deletion nb_cli/handlers/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ async def _get_env_python() -> str:

for python in python_to_try:
proc = await create_process_shell(
f'{python} -W ignore -c "import sys, json; print(json.dumps(sys.executable))"',
f"{python} -W ignore -c "
'"import sys, json; print(json.dumps(sys.executable))"',
stdout=asyncio.subprocess.PIPE,
)
stdout, stderr = await proc.communicate()
Expand Down
1 change: 0 additions & 1 deletion nb_cli/handlers/reloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def handle_exit(self, sig, frame):
self.should_exit.set()

def _display_path(self, path: Path) -> str:
print(self.cwd, path)
try:
return f'"{path.relative_to(self.cwd)}"'
except ValueError:
Expand Down
4 changes: 2 additions & 2 deletions nb_cli/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def _get_win_locale_with_ctypes() -> Optional[str]:
import ctypes
import ctypes # noqa: F811

kernel32 = ctypes.windll.kernel32
lcid: int = kernel32.GetUserDefaultUILanguage()
Expand All @@ -28,7 +28,7 @@ def _get_win_locale_from_registry() -> Optional[str]:

if WINDOWS:
try:
import ctypes
import ctypes # noqa: F401

_get_win_locale = _get_win_locale_with_ctypes
except ImportError:
Expand Down
892 changes: 430 additions & 462 deletions pdm.lock

Large diffs are not rendered by default.

54 changes: 26 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name = "nb-cli"
version = "1.2.2"
description = "CLI for nonebot2"
authors = [
{ name = "yanyongyu", email = "[email protected]" }
]
authors = [{ name = "yanyongyu", email = "[email protected]" }]
license = { text = "MIT" }
readme = "README.md"
keywords = ["bot", "qq", "nonebot", "bot", "qq", "nonebot"]
Expand All @@ -14,7 +12,7 @@ classifiers = [
"Framework :: Robot Framework :: Library",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3"
"Programming Language :: Python :: 3",
]

requires-python = ">=3.8, <4.0"
Expand All @@ -41,30 +39,40 @@ homepage = "https://cli.nonebot.dev/"
repository = "https://github.com/nonebot/nb-cli"

[tool.pdm.dev-dependencies]
i18n = [
"babel ~=2.11"
]
i18n = ["babel ~=2.11"]
dev = [
"isort ~=5.10",
"black >=22.3.0",
"nonemoji ~=0.1",
"pre-commit ~=3.1",
"importlib-metadata"
]
docs = [
"nb-autodoc >=1.0.0a5"
"importlib-metadata",
"ruff>=0.0.281,<0.1.0",
]
docs = ["nb-autodoc >=1.0.0a5"]

[tool.pdm.scripts]
autodoc = { shell = "rm -rf ./website/docs/api/* && nb-autodoc nb_cli -s nb_cli.template && cp -r ./build/nb_cli/* ./website/docs/api/" }
extract = "pybabel extract -o messages.pot --project nb-cli --version 1.0.0 nb_cli/"
_init = "pybabel init -D nb-cli -i messages.pot -d nb_cli/locale/ -l {args}"
init = { composite = ["extract", "_init {args}"] }
_update = "pybabel update -D nb-cli -i messages.pot -d nb_cli/locale/"
update = { composite = ["extract", "_update"] }
compile = "pybabel compile -D nb-cli -d nb_cli/locale/"

[project.scripts]
nb = "nb_cli.__main__:main"

[tool.pdm.build]
setup-script = "build.py"
run-setuptools = false

[tool.pyright]
pythonPlatform = "All"
reportPrivateImportUsage = false
reportShadowedImports = false
executionEnvironments = [
{ root = "./website", pythonVersion = "3.10" },
{ root = "./", pythonVersion = "3.8" }
{ root = "./", pythonVersion = "3.8" },
]

[tool.black]
Expand All @@ -82,23 +90,13 @@ force_sort_within_sections = true
extra_standard_library = ["typing_extensions"]
extend_skip = ["nb_cli/template/"]

[tool.pycln]
path = "."
all = false

[tool.pdm.scripts]
autodoc = { shell = "rm -rf ./website/docs/api/* && nb-autodoc nb_cli -s nb_cli.template && cp -r ./build/nb_cli/* ./website/docs/api/"}
extract = "pybabel extract -o messages.pot --project nb-cli --version 1.0.0 nb_cli/"
_init = "pybabel init -D nb-cli -i messages.pot -d nb_cli/locale/ -l {args}"
init = { composite = ["extract", "_init {args}"] }
_update = "pybabel update -D nb-cli -i messages.pot -d nb_cli/locale/"
update = { composite = ["extract", "_update"] }
compile = "pybabel compile -D nb-cli -d nb_cli/locale/"

[tool.ruff]
select = ["E", "W", "F", "UP", "C", "T", "PT", "Q"]
ignore = ["E402", "C901", "UP037"]
extend-exclude = ["nb_cli/template/"]

[tool.pdm.build]
setup-script = "build.py"
run-setuptools = false
line-length = 88
target-version = "py38"

[build-system]
requires = ["pdm-pep517>=1.0.0", "babel~=2.11"]
Expand Down

0 comments on commit d6797d8

Please sign in to comment.