Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Configure ruff #1893

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
exclude: '^pint/_vendor'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.240'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: ruff
args: ["--fix"]
args: ["--fix", "--show-fixes"]
types_or: [ python, pyi, jupyter ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
Expand Down
9 changes: 7 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
:target: https://pypi.python.org/pypi/pint
:alt: Latest Version

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/python/black
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff-Format

.. image:: https://readthedocs.org/projects/pint/badge/
:target: https://pint.readthedocs.org/
Expand Down
12 changes: 7 additions & 5 deletions pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,9 @@ def get_name(
prefix, unit_name, _ = candidates[0]
if len(candidates) > 1:
logger.warning(
"Parsing {} yield multiple results. "
"Options are: {!r}".format(name_or_alias, candidates)
"Parsing {} yield multiple results. " "Options are: {!r}".format(
name_or_alias, candidates
)
)

if prefix:
Expand Down Expand Up @@ -679,8 +680,9 @@ def get_symbol(
prefix, unit_name, _ = candidates[0]
if len(candidates) > 1:
logger.warning(
"Parsing {} yield multiple results. "
"Options are: {!r}".format(name_or_alias, candidates)
"Parsing {} yield multiple results. " "Options are: {!r}".format(
name_or_alias, candidates
)
)

return self._prefixes[prefix].symbol + self._units[unit_name].symbol
Expand Down Expand Up @@ -1139,7 +1141,7 @@ def _yield_unit_triplets(

@staticmethod
def _dedup_candidates(
candidates: Iterable[tuple[str, str, str]]
candidates: Iterable[tuple[str, str, str]],
) -> tuple[tuple[str, str, str], ...]:
"""Helper of parse_unit_name.

Expand Down
5 changes: 3 additions & 2 deletions pint/facets/plain/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def __init__(self, units: UnitLike) -> None:
self._units = units._units
else:
raise TypeError(
"units must be of type str, Unit or "
"UnitsContainer; not {}.".format(type(units))
"units must be of type str, Unit or " "UnitsContainer; not {}.".format(
type(units)
)
)

def __copy__(self) -> PlainUnit:
Expand Down
4 changes: 1 addition & 3 deletions pint/testsuite/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ def test_prod_numpy_func(self):
helpers.assert_quantity_equal(
np.prod(self.q, axis=axis), [3, 8] * self.ureg.m**2
)
helpers.assert_quantity_equal(
np.prod(self.q, where=where), 12 * self.ureg.m**3
)
helpers.assert_quantity_equal(np.prod(self.q, where=where), 12 * self.ureg.m**3)

with pytest.raises(DimensionalityError):
np.prod(self.q, axis=axis, where=where)
Expand Down
6 changes: 2 additions & 4 deletions pint/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ def column_echelon_form(
ItMatrix,
],
Matrix,
] = (
transpose if transpose_result else _noop
)
] = transpose if transpose_result else _noop

ech_matrix = matrix_apply(
transpose(matrix),
Expand Down Expand Up @@ -310,7 +308,7 @@ def pi_theorem(quantities: dict[str, Any], registry: Optional[UnitRegistry] = No


def solve_dependencies(
dependencies: dict[TH, set[TH]]
dependencies: dict[TH, set[TH]],
) -> Generator[set[TH], None, None]:
"""Solve a dependency graph.

Expand Down
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,56 @@ known-first-party= ["pint"]


[tool.ruff]
extend-select = [
# "F", # pyflakes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how you included all options here, such that one can slowly work towards following all these rules 😄

"W", # pycodestyle-warnings
"E", # pycodestyle-errors
# "C90", # mccabe
# "I", # isort
# "N", # pep8-naming
# "D", # pydocstyle
# "UP", # pyupgrade
"YTT", # flake8-2020
# "ANN", # flake8-annotations
# "S", # flake8-bandit
# "BLE", # flake8-blind-except
# "FBT", # flake8-boolean-trap
# "B", # flake8-bugbear
# "A", # flake8-builtins
# "COM", # flake8-comma
# "C4", # flake8-comprehensions
"T10", # flake8-debugger
# "EM", # flake8-errmsg
"FA", # flake8-future-annotations
# "ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
# "G", # flake8-logging-format
"PIE", # flake8-pie
# "T20", # flake8-print
# "PYI", # flake8-pyi
# "PT", # flake8-pytest-style
"Q", # flake8-quotes
"RSE", # flake8-raise
# "RET", # flake8-return
# "SLF", # flake8-self
# "SIM", # flake8-simplify
# "TID", # flake8-tidy-imports
# "TCH", # flake8-type-checking
# "ARG", # flake8-unused-arguments
# "PTH", # flake8-use-pathlib
# "TD", # flake8-todos
# "ERA", # eradicate
# "PD", # pandas-vet
# "PGH", # pygrep-hooks
# "PL", # pylint
# "TRY", # tryceratops
# "FLY", # flynt
# "NPY", # NumPy
# "PERF", # perflint
# "FURB", # refurb # All are in experimental
# "RUF", # Ruff-specific
]

ignore = [
# whitespace before ':' - doesn't work well with black
# "E203",
Expand Down