From ed22a0b1376046c9b1ecd07d65886bf4c524fd18 Mon Sep 17 00:00:00 2001 From: Corentin Cadiou Date: Tue, 9 Apr 2024 09:55:43 +0200 Subject: [PATCH] Modernise pre-commit config --- .pre-commit-config.yaml | 17 ++--------------- labellines/core.py | 16 ++++++++++------ pyproject.toml | 11 +++++------ 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6b98a92..bad9f73 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,21 +8,6 @@ repos: hooks: - id: trailing-whitespace - id: end-of-file-fixer -- repo: https://github.com/psf/black - rev: 24.3.0 - hooks: - - id: black - language_version: python3 -- repo: https://github.com/asottile/blacken-docs - rev: 1.16.0 - hooks: - - id: blacken-docs - additional_dependencies: [black==22.1.0] -- repo: https://github.com/PyCQA/isort - rev: '5.13.2' - hooks: - - id: isort - name: isort (python) - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.9.0 hooks: @@ -31,3 +16,5 @@ repos: rev: v0.3.5 hooks: - id: ruff + args: ["--fix", "--show-fixes"] + - id: ruff-format diff --git a/labellines/core.py b/labellines/core.py index b76c605..fe16435 100644 --- a/labellines/core.py +++ b/labellines/core.py @@ -224,17 +224,18 @@ def labelLines( # Move xlabel if it is outside valid range xdata, _ = normalize_xydata(line) - if not (min(xdata) <= xv <= max(xdata)): + xmin, xmax = min(xdata), max(xdata) + if not (xmin <= xv <= xmax): warnings.warn( ( "The value at position {} in `xvals` is outside the range of its " - "associated line (xmin={}, xmax={}, xval={}). Clipping it " - "into the allowed range." - ).format(i, min(xdata), max(xdata), xv), + f"associated line ({xmin=}, {xmax=}, xval={xv}). " + "Clipping it into the allowed range." + ), UserWarning, stacklevel=1, ) - new_xv = min(xdata) + (max(xdata) - min(xdata)) * 0.9 + new_xv = xmin + (xmax - xmin) * 0.9 xvals[i] = new_xv # type: ignore # Convert float values back to datetime in case of datetime axis @@ -250,7 +251,10 @@ def labelLines( except TypeError: pass for line, x, yoffset, label in zip( - lab_lines, xvals, yoffsets, labels # type: ignore + lab_lines, + xvals, # type: ignore + yoffsets, # type: ignore + labels, ): txts.append( labelLine( diff --git a/pyproject.toml b/pyproject.toml index 754720d..99703cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,16 +14,15 @@ filterwarnings = [ "error", ] -[tool.ruff] -# Enable Pyflakes `E` and `F` codes by default. -select = ["E", "C", "F", "U", "B", "A", "YTT", "S", "N"] +[tool.ruff.lint] ignore = ["N802", "N806", "C901", "UP007"] -target-version = 'py38' +select = ["E", "C", "F", "UP", "B", "A", "YTT", "S", "N"] -[tool.ruff.per-file-ignores] + +[tool.ruff.lint.per-file-ignores] "**/test*.py" = ["S101"] -[tool.ruff.isort] +[tool.ruff.lint.isort] combine-as-imports = true known-first-party = ["labellines"] known-third-party = [