From 0438e7525ef859042d9eeba215c5fc19ebd967c1 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 09:54:11 -0500 Subject: [PATCH] Use ruff format (#370) --- .pre-commit-config.yaml | 20 ++++++++----------- jupyter_core/application.py | 2 +- jupyter_core/paths.py | 2 +- pyproject.toml | 17 +++++++--------- .../ipython_nbconvert_config.py | 6 +++--- tests/test_command.py | 4 ++-- tests/test_migrate.py | 2 +- 7 files changed, 23 insertions(+), 30 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fa47c7e2..180a6c28 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-case-conflict - id: check-ast @@ -21,7 +21,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.26.3 + rev: 0.27.0 hooks: - id: check-github-workflows @@ -33,7 +33,7 @@ repos: [mdformat-gfm, mdformat-frontmatter, mdformat-footnote] - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.0.2" + rev: "v3.0.3" hooks: - id: prettier types_or: [yaml, html, json] @@ -44,16 +44,11 @@ repos: - id: blacken-docs additional_dependencies: [black==23.7.0] - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.7.0 - hooks: - - id: black - - repo: https://github.com/codespell-project/codespell - rev: "v2.2.5" + rev: "v2.2.6" hooks: - id: codespell - args: ["-L", "sur,nd"] + args: ["-L", "re-use"] - repo: https://github.com/pre-commit/pygrep-hooks rev: "v1.10.0" @@ -63,13 +58,14 @@ repos: - id: rst-inline-touching-normal - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.287 + rev: v0.1.3 hooks: - id: ruff args: ["--fix", "--show-fixes"] + - id: ruff-format - repo: https://github.com/scientific-python/cookie - rev: "2023.08.23" + rev: "2023.10.27" hooks: - id: sp-repo-review additional_dependencies: ["repo-review[cli]"] diff --git a/jupyter_core/application.py b/jupyter_core/application.py index 1f7467fa..4231f11d 100644 --- a/jupyter_core/application.py +++ b/jupyter_core/application.py @@ -165,7 +165,7 @@ def migrate_config(self) -> None: """Migrate config/data from IPython 3""" try: # let's see if we can open the marker file # for reading and updating (writing) - f_marker = open(os.path.join(self.config_dir, "migrated"), 'r+') # noqa + f_marker = open(os.path.join(self.config_dir, "migrated"), "r+") # noqa except PermissionError: # not readable and/or writable return # so let's give up migration in such an environment except FileNotFoundError: # cannot find the marker file diff --git a/jupyter_core/paths.py b/jupyter_core/paths.py index 74c21dce..749a3802 100644 --- a/jupyter_core/paths.py +++ b/jupyter_core/paths.py @@ -83,7 +83,7 @@ def _do_i_own(path: str) -> bool: except Exception: # noqa pass - if hasattr(os, 'geteuid'): + if hasattr(os, "geteuid"): try: st = p.stat() return st.st_uid == os.geteuid() diff --git a/pyproject.toml b/pyproject.toml index bf2f9cc3..89515274 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,17 +94,17 @@ dependencies = ["mypy~=1.6.0", "traitlets>=5.11.2"] test = "mypy --install-types --non-interactive {args}" [tool.hatch.envs.lint] -dependencies = ["black==23.3.0", "mdformat>0.7", "ruff==0.0.281"] +dependencies = ["mdformat>0.7", "ruff==0.1.3"] detached = true [tool.hatch.envs.lint.scripts] style = [ "ruff {args:.}", - "black --check --diff {args:.}", + "ruff format {args:.}", "mdformat --check {args:*.md}" ] fmt = [ - "black {args:.}", "ruff --fix {args:.}", + "ruff format {args:.}", "mdformat {args:*.md}" ] @@ -153,16 +153,13 @@ exclude_lines = [ "@(abc\\.)?abstractmethod", ] -[tool.black] -line-length = 100 -skip-string-normalization = true -target-version = ["py38"] - [tool.ruff] target-version = "py38" line-length = 100 + +[tool.ruff.lint] select = [ - "A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "ISC", "N", + "A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "N", "PLC", "PLE", "PLR", "PLW", "Q", "RUF", "S", "SIM", "T", "TID", "UP", "W", "YTT", ] @@ -183,7 +180,7 @@ unfixable = [ "RUF100", ] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] # B011 Do not call assert False since python -O removes these calls # F841 local variable 'foo' is assigned to but never used # C408 Unnecessary `dict` call diff --git a/tests/dotipython_empty/profile_default/ipython_nbconvert_config.py b/tests/dotipython_empty/profile_default/ipython_nbconvert_config.py index ad3c8e37..d72411a8 100644 --- a/tests/dotipython_empty/profile_default/ipython_nbconvert_config.py +++ b/tests/dotipython_empty/profile_default/ipython_nbconvert_config.py @@ -183,9 +183,9 @@ # ------------------------------------------------------------------------------ # Exports to a Latex template. Inherit from this class if your template is -# LaTeX based and you need custom tranformers/filters. Inherit from it if you -# are writing your own HTML template and need custom tranformers/filters. If -# you don't need custom tranformers/filters, just change the 'template_file' +# LaTeX based and you need custom transformers/filters. Inherit from it if you +# are writing your own HTML template and need custom transformers/filters. If +# you don't need custom transformers/filters, just change the 'template_file' # config option. Place your template in the special "/latex" subfolder of the # "../templates" folder. diff --git a/tests/test_command.py b/tests/test_command.py index 73d938c3..a0833c13 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -64,9 +64,9 @@ def write_executable(path, source): try: import importlib.resources - if not hasattr(importlib.resources, 'files'): + if not hasattr(importlib.resources, "files"): raise ImportError - wp = importlib.resources.files('setuptools').joinpath('cli-32.exe') + wp = importlib.resources.files("setuptools").joinpath("cli-32.exe") w = wp.read_bytes() except (ImportError, FileNotFoundError, SystemError): pytest.skip( diff --git a/tests/test_migrate.py b/tests/test_migrate.py index 8d645275..7d21ce9b 100644 --- a/tests/test_migrate.py +++ b/tests/test_migrate.py @@ -54,7 +54,7 @@ def env(request): def fin(): """Cleanup test env""" env_patch.stop() - shutil.rmtree(td, ignore_errors=os.name == 'nt') + shutil.rmtree(td, ignore_errors=os.name == "nt") request.addfinalizer(fin)