From 29e300719c2986e7e928a1cfb53a52a4fe9bc4f1 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 12:53:56 -0500 Subject: [PATCH] Adopt ruff format (#383) --- .pre-commit-config.yaml | 12 ++++-------- docs/conf.py | 5 ++++- nbformat/v2/nbbase.py | 13 +++++++++++-- nbformat/v3/nbbase.py | 7 ++++++- nbformat/validator.py | 2 +- pyproject.toml | 21 +++++++++++---------- tests/v4/test_json.py | 6 +++--- 7 files changed, 40 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7bd364d3..54233bbb 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 @@ -42,11 +42,6 @@ repos: - id: blacken-docs additional_dependencies: [black==23.7.0] - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.9.1 - hooks: - - id: black - - repo: https://github.com/codespell-project/codespell rev: "v2.2.6" hooks: @@ -61,13 +56,14 @@ repos: - id: rst-inline-touching-normal - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.292 + rev: v0.1.3 hooks: - id: ruff args: ["--fix", "--show-fixes"] + - id: ruff-format - repo: https://github.com/scientific-python/cookie - rev: "2023.09.21" + rev: "2023.10.27" hooks: - id: sp-repo-review additional_dependencies: ["repo-review[cli]"] diff --git a/docs/conf.py b/docs/conf.py index de491401..977bf598 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -132,7 +132,10 @@ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -# html_theme_options = {} +html_theme_options = { + # prefer browser defaults over custom JS keyboard event handlers + "navigation_with_keys": False, +} # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] diff --git a/nbformat/v2/nbbase.py b/nbformat/v2/nbbase.py index 1ea3316b..8d06acfb 100644 --- a/nbformat/v2/nbbase.py +++ b/nbformat/v2/nbbase.py @@ -100,7 +100,11 @@ def new_output( # noqa def new_code_cell( - input=None, prompt_number=None, outputs=None, language="python", collapsed=False # noqa + input=None, # noqa: A002 + prompt_number=None, + outputs=None, + language="python", + collapsed=False, ): """Create a new code cell with input and output""" cell = NotebookNode() @@ -160,7 +164,12 @@ def new_notebook(metadata=None, worksheets=None): def new_metadata( - name=None, authors=None, license=None, created=None, modified=None, gistid=None # noqa + name=None, + authors=None, + license=None, # noqa: A002 + created=None, + modified=None, + gistid=None, ): """Create a new metadata node.""" metadata = NotebookNode() diff --git a/nbformat/v3/nbbase.py b/nbformat/v3/nbbase.py index 43c43c77..a6c034c4 100644 --- a/nbformat/v3/nbbase.py +++ b/nbformat/v3/nbbase.py @@ -217,7 +217,12 @@ def new_notebook(name=None, metadata=None, worksheets=None): def new_metadata( - name=None, authors=None, license=None, created=None, modified=None, gistid=None # noqa + name=None, + authors=None, + license=None, # noqa: A002 + created=None, + modified=None, + gistid=None, ): """Create a new metadata node.""" metadata = NotebookNode() diff --git a/nbformat/validator.py b/nbformat/validator.py index 928b96c8..861fb592 100644 --- a/nbformat/validator.py +++ b/nbformat/validator.py @@ -111,7 +111,7 @@ def _get_schema_json(v, version=None, version_minor=None): else: msg = "Cannot find appropriate nbformat schema file." raise AttributeError(msg) - with open(schema_path, encoding='utf-8') as f: + with open(schema_path, encoding="utf-8") as f: schema_json = json.load(f) return schema_json diff --git a/pyproject.toml b/pyproject.toml index c9909f39..28e19383 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,17 +90,17 @@ dependencies = ["mypy~=1.6", "jupyter_core>=5.4", "traitlets>=5.11.1"] test = "mypy --install-types --non-interactive {args}" [tool.hatch.envs.lint] -dependencies = ["black[jupyter]==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}" ] @@ -146,17 +146,18 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] disable_error_code = ["no-untyped-def", "no-untyped-call"] warn_unreachable = true -[tool.black] -line-length = 100 -skip-string-normalization = true -target-version = ["py38"] -extend-exclude = "^/tests.*ipynb$" + [tool.ruff] target-version = "py38" line-length = 100 + +[tool.ruff.format] +exclude = ["^/tests.*ipynb$"] + +[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", ] @@ -179,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/v4/test_json.py b/tests/v4/test_json.py index 5434b3b0..064afc1e 100644 --- a/tests/v4/test_json.py +++ b/tests/v4/test_json.py @@ -109,7 +109,7 @@ def test_latest_schema_matches(self): def test_base_version_matches_latest(self): """Test to ensure latest version file matches latest version""" with open( - os.path.join(BASE_PATH, "nbformat.v4.schema.json"), encoding='utf-8' + os.path.join(BASE_PATH, "nbformat.v4.schema.json"), encoding="utf-8" ) as schema_file: latest_schema = json.load(schema_file) with open( @@ -117,7 +117,7 @@ def test_base_version_matches_latest(self): BASE_PATH, f"nbformat.v{nbformat}.{nbformat_minor}.schema.json", ), - encoding='utf-8', + encoding="utf-8", ) as schema_file: # noqa ver_schema = json.load(schema_file) assert latest_schema == ver_schema @@ -125,7 +125,7 @@ def test_base_version_matches_latest(self): def test_latest_matches_nbformat(self): """Test to ensure that the nbformat version matches the description of the latest schema""" with open( - os.path.join(BASE_PATH, "nbformat.v4.schema.json"), encoding='utf-8' + os.path.join(BASE_PATH, "nbformat.v4.schema.json"), encoding="utf-8" ) as schema_file: schema = json.load(schema_file) assert schema["description"] == "Jupyter Notebook v{major}.{minor} JSON schema.".format(