diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4a3f4aa9..75bfa6297 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/README.rst b/README.rst index 89f19f474..3c16a4541 100644 --- a/README.rst +++ b/README.rst @@ -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/ diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py index 39a058e58..9b315a0a9 100644 --- a/pint/facets/plain/registry.py +++ b/pint/facets/plain/registry.py @@ -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: @@ -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 @@ -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. diff --git a/pint/facets/plain/unit.py b/pint/facets/plain/unit.py index 4c5c04ac3..301418cb9 100644 --- a/pint/facets/plain/unit.py +++ b/pint/facets/plain/unit.py @@ -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: diff --git a/pint/testsuite/test_numpy.py b/pint/testsuite/test_numpy.py index 83308b2f7..c2e1d75c5 100644 --- a/pint/testsuite/test_numpy.py +++ b/pint/testsuite/test_numpy.py @@ -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) diff --git a/pint/util.py b/pint/util.py index 1f7defc50..4d718ed2f 100644 --- a/pint/util.py +++ b/pint/util.py @@ -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), @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 4b6b7312d..db1d2b0de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,6 +87,56 @@ known-first-party= ["pint"] [tool.ruff] +extend-select = [ +# "F", # pyflakes + "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",