Skip to content

Commit

Permalink
Fix precommit compliants
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Apr 2, 2024
1 parent 7267dcf commit 2cdd9bb
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 33 deletions.
115 changes: 97 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,15 @@ addopts = "--cov --cov-report term-missing --cov-report xml --cov-report lcov:lc
line-length = 100
# skip-string-normalization = true
target-version = [
"py37",
"py38",
"py39",
"py310",
"py311",
]

[tool.ruff]
select = ["F",
"E",
"I",
"W",
"UP",
"Q",
# "SIM",
# "PTH",
#"RET",
]
ignore = ["E722"]
line-length = 120
# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
unfixable = []
# Exclude a variety of commonly ignored directories.
exclude = [
"dev*",
"ximage/test*",
".bzr",
".direnv",
".eggs",
Expand All @@ -117,10 +99,107 @@ exclude = [
"_build",
"buck-out",
"build",
"docs",
"dist",
"node_modules",
"venv",
]

line-length = 120
indent-width = 4

[tool.ruff.format]

# Enable reformatting of code snippets in docstrings.
docstring-code-format = true

[tool.ruff.lint]

select = [
# pydocstyle
# "D",
# Pyflakes
"F",
# pycodestyle
"E",
"W",
# isort
"I",
# pyupgrade
"UP",
# flake8-quotes
"Q",
# flake8-bugbear
#"B",
# flake8-return
#"RET",
# flake8-unused-arguments
#"ARG",
# flake8-raise
#"RSE",
# flake8-pytest-style
#"PT",
# flake8-simplify
# "SIM",
# Perflint
#"PERF",
# pandas-vet
#"PD",
# pylint
#"PL",
# flake8-commas
#"COM",
# flake8-slots
#"SLOT",
# flake8-comprehensions
# "C4",
# Ruff custom rules
# "RUF"

#---------------------
#### Future rules ####
# flake8-use-pathlib
# "PTH",
# NumPy-specific rules (for 2.0)
# "NPY",
# refurb
# "FURB", # require preview
]
ignore = [
"E722",
"PT011", # pytest raised error must be checked if match the expected error msg
"PERF203",

# Docstyle Rules
"D404", # Docstring can't start with "This"
"D401", # First sentence must be in imperative mood

# Complexity rules
"PLR0913",
"PLR2004",
"PLR0912",
"PLR0915",
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.lint.per-file-ignores]

# Ignore `E402` (import violations) in all Jupyter Notebooks.
"*.ipynb" = ["E402"]

# Rules to ignore in test files
"test_*.py" = [
"ARG", # avoid problems with fixtures
"D100", "D101","D102", "D103", "D104", "D105", # Missing docstrings
]
"setup.py" = ["D100"]
"*__init__.py" = ["D104"]

[tool.codespell]
ignore-words-list = 'nD'
4 changes: 1 addition & 3 deletions ximage/tests/accessor/test_accessor_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

from ximage.accessor.methods import XImage_Base_Accessor, XImage_DataArray_Accessor
from ximage.labels.labels import label
from ximage.patch.labels_patch import get_patches_from_labels
from ximage.patch.labels_patch import get_patches_isel_dict_from_labels
from ximage.labels.plot_labels import plot_labels

from ximage.patch.labels_patch import get_patches_from_labels, get_patches_isel_dict_from_labels

# Utils functions ##############################################################

Expand Down
10 changes: 5 additions & 5 deletions ximage/tests/labels/test_labels.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import numpy as np
import pytest
import xarray as xr

from pytest import apply_to_all_array_types

from ximage.labels import labels


# Tests for public functions ###################################################


Expand Down Expand Up @@ -305,8 +303,6 @@ def test_get_labels_stats():
]
)

values_area = [5, 1, 3]

# Test result returned in decreasing order
label_indices, values_returned = labels._get_labels_stats(array, label_array)
assert np.array_equal(label_indices, np.array([0, 2, 1]))
Expand Down Expand Up @@ -699,7 +695,11 @@ def test_xr_get_labels():
[1, 1],
]
)
sort_by = lambda array: np.mean(array)

def my_sort_function(array):
return np.mean(array)

sort_by = my_sort_function
sort_decreasing = False
labeled_comprehension_kwargs = {
"out_dtype": np.float16,
Expand Down
2 changes: 1 addition & 1 deletion ximage/tests/labels/test_plot_labels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from matplotlib.image import AxesImage
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
from matplotlib.image import AxesImage

from ximage.labels.plot_labels import plot_labels

Expand Down
3 changes: 1 addition & 2 deletions ximage/tests/patch/test_checks_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from ximage.patch import checks


# Utils functions ##############################################################


Expand Down Expand Up @@ -105,7 +104,7 @@ def test_check_stride():

# Check no partitioning method
partitioning_method = None
assert checks.check_stride(None, dimension_names, shape, partitioning_method) == None
assert checks.check_stride(None, dimension_names, shape, partitioning_method) is None

# Check default stride
partitioning_method = "tiling"
Expand Down
4 changes: 1 addition & 3 deletions ximage/tests/patch/test_labels_patch.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import numpy as np
import pytest
import xarray as xr

from pytest import apply_to_all_array_types, SaneEqualityArray
from pytest import SaneEqualityArray, apply_to_all_array_types

from ximage.patch import labels_patch


# Utils functions ##############################################################


Expand Down
1 change: 0 additions & 1 deletion ximage/tests/patch/test_slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from ximage.patch import slices


# Tests for public functions ###################################################


Expand Down

0 comments on commit 2cdd9bb

Please sign in to comment.