Skip to content

Commit

Permalink
Adopt ruff format (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Oct 29, 2023
1 parent f2123c3 commit 29e3007
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 26 deletions.
12 changes: 4 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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]"]
5 changes: 4 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
13 changes: 11 additions & 2 deletions nbformat/v2/nbbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion nbformat/v3/nbbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion nbformat/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 11 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
]

Expand Down Expand Up @@ -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",
]
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/v4/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ 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(
os.path.join(
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

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(
Expand Down

0 comments on commit 29e3007

Please sign in to comment.