From 3504c1cd7116dbea253854989363feecaab2287e Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Wed, 29 Jan 2025 16:40:42 +0800 Subject: [PATCH] lint: migrate formatter from `black` to `ruff format` --- .pre-commit-config.yaml | 5 +---- nvitop-exporter/pyproject.toml | 6 ------ nvitop/api/process.py | 3 +-- nvitop/tui/library/selection.py | 9 ++------- pyproject.toml | 12 +++++++----- setup.py | 2 +- 6 files changed, 12 insertions(+), 25 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5a6a880..3a16e964 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,10 +29,7 @@ repos: hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - - repo: https://github.com/psf/black - rev: 24.10.0 - hooks: - - id: black + - id: ruff-format - repo: https://github.com/asottile/pyupgrade rev: v3.19.1 hooks: diff --git a/nvitop-exporter/pyproject.toml b/nvitop-exporter/pyproject.toml index ed89d8d1..95d257b0 100644 --- a/nvitop-exporter/pyproject.toml +++ b/nvitop-exporter/pyproject.toml @@ -65,11 +65,5 @@ Documentation = "https://nvitop.readthedocs.io" [tool.setuptools.packages.find] include = ["nvitop_exporter", "nvitop_exporter.*"] -[tool.black] -safe = true -line-length = 100 -skip-string-normalization = true -target-version = ["py37"] - [tool.ruff] extend = "../pyproject.toml" diff --git a/nvitop/api/process.py b/nvitop/api/process.py index 06ce91a6..e6397d02 100644 --- a/nvitop/api/process.py +++ b/nvitop/api/process.py @@ -95,8 +95,7 @@ def command_join(cmdline: list[str]) -> str: """Return a shell-escaped string from command line arguments.""" if len(cmdline) == 1 and not ( # May be modified by `setproctitle` - os.path.isfile(cmdline[0]) - and os.path.isabs(cmdline[0]) + os.path.isfile(cmdline[0]) and os.path.isabs(cmdline[0]) ): return cmdline[0] return ' '.join(map(add_quotes, cmdline)) diff --git a/nvitop/tui/library/selection.py b/nvitop/tui/library/selection.py index 9f2af30d..8329b7f7 100644 --- a/nvitop/tui/library/selection.py +++ b/nvitop/tui/library/selection.py @@ -121,13 +121,8 @@ def send_signal(self, sig): def interrupt(self): try: - self.send_signal( - ( - signal.SIGINT - if not host.WINDOWS - else signal.CTRL_C_EVENT # pylint: disable=no-member - ), - ) + # pylint: disable-next=no-member + self.send_signal(signal.SIGINT if not host.WINDOWS else signal.CTRL_C_EVENT) except SystemError: pass diff --git a/pyproject.toml b/pyproject.toml index 743b9acd..37df6186 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,11 +67,6 @@ Documentation = "https://nvitop.readthedocs.io" [tool.setuptools.packages.find] include = ["nvitop", "nvitop.*"] -[tool.black] -line-length = 100 -skip-string-normalization = true -target-version = ["py37"] - [tool.mypy] # Sync with requires-python python_version = "3.8" # appease mypy for syntax errors in numpy stubs @@ -118,6 +113,10 @@ line-length = 100 output-format = "full" src = ["nvitop", "nvitop-exporter/nvitop_exporter"] +[tool.ruff.format] +quote-style = "single" +docstring-code-format = false + [tool.ruff.lint] select = [ "E", "W", # pycodestyle @@ -158,6 +157,9 @@ ignore = [ "W505", # ANN401: dynamically typed expressions (typing.Any) are disallowed "ANN401", + # COM812: missing trailing comma + # covered by `ruff format` + "COM812", # FURB189: use the `UserDict`, `UserList`, and `UserString` instead # internally subclassing `dict`, `list`, and `str` "FURB189", diff --git a/setup.py b/setup.py index b88b75ed..6dd42ce5 100755 --- a/setup.py +++ b/setup.py @@ -72,7 +72,7 @@ def vcs_version(name: str, path: Path | str) -> Generator[ModuleType]: extra_requirements = { 'lint': [ - 'black >= 24.0.0, < 25.0.0a0', + 'ruff', 'pylint[spelling]', 'mypy', 'typing-extensions',