Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pre-commits and pytest configuration #56

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4
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
45 changes: 40 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,50 @@ 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.lint]
ignore-init-module-imports = true # do not remove unused imports in __init__ and warn instead
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.lint.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
samjrholt marked this conversation as resolved.
Show resolved Hide resolved
"ignore:((.|\n)*)`ipykernel.pylab.backend_inline` is deprecated((.|\n)*)", # dependency of ipywidgets
]

[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/*
1 change: 1 addition & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tasks to release the package."""

import os
import shutil

Expand Down
5 changes: 3 additions & 2 deletions ubermagtable/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Manipulation of tabular data."""

import importlib.metadata
import os

import matplotlib.pyplot as plt
import pytest

from .interact import interact
from .table import Table
from .interact import interact as interact
from .table import Table as Table

# Enable default plotting style.
dirname = os.path.abspath(os.path.dirname(__file__))
Expand Down
5 changes: 1 addition & 4 deletions ubermagtable/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,7 @@ def slider(self, x=None, multiplier=None, description=None, **kwargs):
labels = np.around(values / multiplier, decimals=2)
options = list(zip(labels, values))

if x == "t":
units = f" ({ubermagutil.units.rsi_prefixes[multiplier]}s)"
else:
units = ""
units = f" ({ubermagutil.units.rsi_prefixes[multiplier]}s)" if x == "t" else ""
if description is None:
description = f"{x}{units}:"

Expand Down
2 changes: 1 addition & 1 deletion ubermagtable/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_init(self):

def test_fromfile(self):
for odtfile in self.odtfiles:
for rename in [True, False]:
for _rename in [True, False]:
table = ut.Table.fromfile(odtfile)
check_table(table)

Expand Down
2 changes: 1 addition & 1 deletion ubermagtable/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_units():
units = uu.units(odtfile, rename=rename)

assert isinstance(units, dict)
assert all(isinstance(unit, str) for unit in units.keys())
assert all(isinstance(unit, str) for unit in units)
assert all(isinstance(unit, str) for unit in units.values())
assert "J" in units.values() # Energy is always in
assert "" in units.values() # Columns with no units are always in
Expand Down
5 changes: 4 additions & 1 deletion ubermagtable/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
"""Utility tools"""
from .util import columns, data, units

from .util import columns as columns
from .util import data as data
from .util import units as units
4 changes: 2 additions & 2 deletions ubermagtable/util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@


def rename_column(name, cols_dict):
if name in cols_dict.keys():
if name in cols_dict:
return cols_dict[name]

for key in cols_dict.keys():
for key in cols_dict:
if len(key.split("::")) == 2:
start, end = key.split("::")
name_split = name.split(":")
Expand Down
Loading