Skip to content

Commit

Permalink
Modernise pre-commit config
Browse files Browse the repository at this point in the history
  • Loading branch information
cphyc committed Apr 9, 2024
1 parent 5297988 commit ed22a0b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
17 changes: 2 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -31,3 +16,5 @@ repos:
rev: v0.3.5
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format
16 changes: 10 additions & 6 deletions labellines/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit ed22a0b

Please sign in to comment.