Skip to content

Commit

Permalink
Maintenance: Adopt Ruff Formatter and Pyupgrade (#136)
Browse files Browse the repository at this point in the history
* add numpy 2.0 integration and bump ruff version

* replace black with ruff formatter

* update changelog

* update changelog
  • Loading branch information
RHammond2 authored Feb 8, 2024
1 parent e3c18b3 commit 540d3bb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
23 changes: 12 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ repos:
name: isort
stages: [commit]

- repo: https://github.com/psf/black
rev: 23.12.0
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: black
name: black
- id: pyupgrade
args: [--py39-plus]
stages: [commit]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
types_or: [python, pyi, jupyter]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.7.1' # Use the sha / tag you want to point at
hooks:
Expand All @@ -38,13 +46,6 @@ repos:
- id: pretty-format-json
args: [--autofix]


- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: ruff
args: [--fix]

# - repo: local
# hooks:
# - id: pytest
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased (TBD)

- Replace the `black` formatter with `ruff`.
- Adopt `pyupgrade` to ensure modern Python language usage.
- Add the NumPy 2.0 integration tool to Ruf.

## v0.9.2 (13 November 2023)

### General
Expand Down
41 changes: 16 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ changelog = "https://github.com/WISDEM/WOMBAT/blob/main/CHANGELOG.md"
[project.optional-dependencies]
dev = [
"pre-commit>=2.20",
"black>=22.1",
"isort>=5.10",
"pytest>=7",
"pytest-cov>=4",
"mypy==0.991",
"ruff==0.0.246",
"ruff>=0.2",
"pyupgrade",
]
docs = [
"jupyter-book>=0.15",
Expand Down Expand Up @@ -164,36 +164,27 @@ length_sort = true
lines_after_imports = 2
line_length = 88


[tool.black]
target-version=["py39", "py310"]
line-length=88

include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''
[tool.numpydoc_validation]
checks = [
"all",
"ES01",
"SA01",
"EX01",
]
exclude = ["*__pycache__"]

[tool.ruff]
src = ["wombat", "tests"]
line-length = 88
target-version = "py39"
ignore-init-module-imports = true
fix = true

[tool.ruff.lint]
# See https://github.com/charliermarsh/ruff#supported-rules
# for rules included and matching to prefix.
# TODO: "FBT", "B", "PIE, "T20", "SIM", "PTH", "PD", "I", "PL"
select = ["F", "E", "W", "C4", "D", "UP"]
ignore-init-module-imports = true
select = ["F", "E", "W", "C4", "D", "UP", "NPY201"]

# D205: not using summary lines and descriptions, just descriptions
# D401: don't believe enough in imperative mode to make all the changes currently
Expand Down Expand Up @@ -229,7 +220,7 @@ exclude = [
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"setup.py" = ["D104"]
"library/__init__.py" = ["D104"]
"library/code_comparison/__init__.py" = ["D104"]
Expand Down Expand Up @@ -281,5 +272,5 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
"wombat/windfarm/__init__.py" = ["F401"]
"wombat/windfarm/system/__init__.py" = ["F401"]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "numpy"
8 changes: 6 additions & 2 deletions wombat/core/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ def check_start_stop_dates(


def valid_hour(
instance: Any, attribute: Attribute, value: int # pylint: disable=W0613
instance: Any,
attribute: Attribute,
value: int, # pylint: disable=W0613
) -> None:
"""Validate that the input is a valid time or null value (-1).
Expand All @@ -275,7 +277,9 @@ def valid_hour(


def valid_reduction(
instance, attribute: Attribute, value: int | float # pylint: disable=W0613
instance,
attribute: Attribute,
value: int | float, # pylint: disable=W0613
) -> None:
"""Check to see if the reduction factor is between 0 and 1, inclusive.
Expand Down
3 changes: 2 additions & 1 deletion wombat/windfarm/windfarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def _create_wind_farm_map(self) -> None:
downstream=graph.nodes[s_id]["connection"],
)
self.wind_farm_map = WindFarmMap(
substation_map=wind_map, export_cables=export # type: ignore
substation_map=wind_map,
export_cables=export, # type: ignore
)

def finish_setup(self) -> None:
Expand Down

0 comments on commit 540d3bb

Please sign in to comment.