Skip to content

Commit

Permalink
Update pre-commits and pytest configuration
Browse files Browse the repository at this point in the history
- pre-commit: use ruff and ruff formatting to replace black, isort, flake8
- pre-commit: remove hard-coded Python version
- tests: convert all warnings to errors
  • Loading branch information
lang-m committed Apr 29, 2024
1 parent dc14535 commit 38bed50
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 58 deletions.
36 changes: 11 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
default_language_version:
python: python3.8
exclude: 'dev'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-merge-conflict # checks for files that contain merge conflict strings
- id: check-toml # checks toml files for parseable syntax
- id: debug-statements # checks for debugger imports and py37+ `breakpoint()` calls in python source
# - id: trailing-whitespace # needs more checks
# args: [--markdown-linebreak-ext=md]
# exclude: 'ubermagtable/tests/test_sample/.*'

- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
hooks:
- id: isort

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
hooks:
- id: nbqa-isort # isort inside Jupyter notebooks

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: [flake8-rst-docstrings] #, flake8-docstrings]

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black-jupyter
# Run the linter.
- id: ruff
types_or: [python, pyi, jupyter]
args: [--fix, --exit-non-zero-on-fix]
# Run the formatter.
- id: ruff-format
types_or: [python, pyi, jupyter]

# - repo: https://github.com/codespell-project/codespell
# rev: v2.1.0
Expand Down
46 changes: 41 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,51 @@ repository = "https://github.com/ubermag/ubermagtable"



[tool.black]
experimental-string-processing = true

[tool.coverage.run]
omit = ["ubermagtable/tests/*"]

[tool.isort]
profile = "black"
skip_gitignore = true # ignores files listed in .gitignore
[tool.ruff]
ignore-init-module-imports = true # do not remove unused imports in __init__ and warn instead

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"E", # pycodestyle
"F", # Pyflakes
"I", # isort
"SIM", # flake8-simplify
"UP", # pyupgrade
]
ignore = [
# conflict with other rules
"D203", # one-blank-line-before-class (conflicts with D204)
"D212", # multi-line-summary-first-line (conflicts with D213)
# conflict with formatter
"D206", # indent-with-spaces
"D300", # triple-single-quotes
"E111", # indentation-with-invalid-multiple
"E114", # indentation-with-invalid-multiple-comment
"E117", # over-indented
# conflict with Python 3.6 compatibility
"UP022", # replace-stdout-stderr
]

[tool.ruff.lint.isort]
known-local-folder = ["ubermagtable"]

[tool.ruff.per-file-ignores]
"*.ipynb" = [
"B018", # "Found useless expression. Either assign it to a variable or remove it."; false positives when using implicit __repr__ in the notebook
"E501", # line too long
"F811", # 'redefined-while-unused'; many false positives in notebooks because ipywidgets decorated functions are not recognised
]

[tool.pytest.ini_options]
filterwarnings = [
"error",
"ignore:((.|\n)*)Sentinel is not a public part of the traitlets API((.|\n)*)", # dependency of k3d
]

[tool.setuptools.packages.find]
include = ["ubermagtable*"]
Expand Down
28 changes: 0 additions & 28 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,30 +1,2 @@
[flake8]
exclude =
.git,
__pycache__,
build,
dev,
dist,
setup.py
# black has a longer default line length
max-line-length = 88
# D107: missing docstring in __init__
# E203: withespace before ':', required for black
# RST210: Inline strong start-string without end-string. # complains about "**kwargs" in docstrings
extend-ignore = D107,RST210,E203
per-file-ignores =
# imported but unused
__init__.py: F401
# ignore missing docstrings in tests
test_*.py: D100,D101,D102,D103
docstring-convention: numpy
# flake8-rst-docstrings:
rst-roles =
py:class,
py:func,
rst-directives =
seealso,
plot,

[codespell]
skip = .*,build/*,dev/*,dist/*

0 comments on commit 38bed50

Please sign in to comment.