From 38bed5095c8ebdd8b2eaf59d08321c96c01ed1e9 Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Mon, 29 Apr 2024 21:53:06 +0200 Subject: [PATCH 1/7] Update pre-commits and pytest configuration - 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 --- .pre-commit-config.yaml | 36 ++++++++++---------------------- pyproject.toml | 46 ++++++++++++++++++++++++++++++++++++----- setup.cfg | 28 ------------------------- 3 files changed, 52 insertions(+), 58 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fcea1de..f0b0fe3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 6f58622..6ffc88c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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*"] diff --git a/setup.cfg b/setup.cfg index 9613901..a73006a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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/* From 267878dd28d5cc4f5d347790b9f236580a9a9910 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 19:54:02 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tasks.py | 1 + ubermagtable/__init__.py | 1 + ubermagtable/util/__init__.py | 1 + 3 files changed, 3 insertions(+) diff --git a/tasks.py b/tasks.py index afd366e..0bd11ff 100644 --- a/tasks.py +++ b/tasks.py @@ -1,4 +1,5 @@ """Tasks to release the package.""" + import os import shutil diff --git a/ubermagtable/__init__.py b/ubermagtable/__init__.py index 4137a81..3af2a1f 100644 --- a/ubermagtable/__init__.py +++ b/ubermagtable/__init__.py @@ -1,4 +1,5 @@ """Manipulation of tabular data.""" + import importlib.metadata import os diff --git a/ubermagtable/util/__init__.py b/ubermagtable/util/__init__.py index 79f451e..d5760c7 100644 --- a/ubermagtable/util/__init__.py +++ b/ubermagtable/util/__init__.py @@ -1,2 +1,3 @@ """Utility tools""" + from .util import columns, data, units From f9c213e278467738c97c57b3bcb78f9b09ed2103 Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Mon, 20 May 2024 09:35:04 +0200 Subject: [PATCH 3/7] Update ruff settings --- .pre-commit-config.yaml | 2 +- pyproject.toml | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f0b0fe3..34799a4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: debug-statements # checks for debugger imports and py37+ `breakpoint()` calls in python source - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.2 + rev: v0.4.4 hooks: # Run the linter. - id: ruff diff --git a/pyproject.toml b/pyproject.toml index 6ffc88c..3e50854 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,10 +64,8 @@ repository = "https://github.com/ubermag/ubermagtable" [tool.coverage.run] omit = ["ubermagtable/tests/*"] -[tool.ruff] -ignore-init-module-imports = true # do not remove unused imports in __init__ and warn instead - [tool.ruff.lint] +ignore-init-module-imports = true # do not remove unused imports in __init__ and warn instead select = [ "B", # flake8-bugbear "E", # pycodestyle @@ -93,7 +91,7 @@ ignore = [ [tool.ruff.lint.isort] known-local-folder = ["ubermagtable"] -[tool.ruff.per-file-ignores] +[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 From a87dd700992e1e64f24c5caf1cb3fd104215ae5b Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Mon, 20 May 2024 14:11:10 +0200 Subject: [PATCH 4/7] ruff fixes --- ubermagtable/table.py | 5 +---- ubermagtable/tests/test_table.py | 2 +- ubermagtable/tests/test_util.py | 2 +- ubermagtable/util/util.py | 4 ++-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/ubermagtable/table.py b/ubermagtable/table.py index a1995e3..ef0aa87 100644 --- a/ubermagtable/table.py +++ b/ubermagtable/table.py @@ -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}:" diff --git a/ubermagtable/tests/test_table.py b/ubermagtable/tests/test_table.py index 86c59b9..199d7ad 100644 --- a/ubermagtable/tests/test_table.py +++ b/ubermagtable/tests/test_table.py @@ -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) diff --git a/ubermagtable/tests/test_util.py b/ubermagtable/tests/test_util.py index 0d45ebe..a4d8789 100644 --- a/ubermagtable/tests/test_util.py +++ b/ubermagtable/tests/test_util.py @@ -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 diff --git a/ubermagtable/util/util.py b/ubermagtable/util/util.py index 4a9cff4..002ef41 100644 --- a/ubermagtable/util/util.py +++ b/ubermagtable/util/util.py @@ -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(":") From a6c42967f45808d1cd6607a26ba981bd19264103 Mon Sep 17 00:00:00 2001 From: Sam Holt <48217392+samjrholt@users.noreply.github.com> Date: Tue, 4 Jun 2024 09:01:18 +0000 Subject: [PATCH 5/7] using a redundant alias --- ubermagtable/__init__.py | 4 ++-- ubermagtable/util/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ubermagtable/__init__.py b/ubermagtable/__init__.py index 3af2a1f..0bdd6b0 100644 --- a/ubermagtable/__init__.py +++ b/ubermagtable/__init__.py @@ -6,8 +6,8 @@ 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__)) diff --git a/ubermagtable/util/__init__.py b/ubermagtable/util/__init__.py index d5760c7..a8f761a 100644 --- a/ubermagtable/util/__init__.py +++ b/ubermagtable/util/__init__.py @@ -1,3 +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 \ No newline at end of file From 291ba08ca983fa3eda448a3e4a66d45613a73bb2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 09:01:38 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ubermagtable/util/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubermagtable/util/__init__.py b/ubermagtable/util/__init__.py index a8f761a..9076e8f 100644 --- a/ubermagtable/util/__init__.py +++ b/ubermagtable/util/__init__.py @@ -2,4 +2,4 @@ from .util import columns as columns from .util import data as data -from .util import units as units \ No newline at end of file +from .util import units as units From 351462b232c7eaffd635d9bada76a684b6576539 Mon Sep 17 00:00:00 2001 From: Sam Holt Date: Tue, 4 Jun 2024 13:03:23 +0200 Subject: [PATCH 7/7] ignore ipywidgets warning --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 3e50854..a462e32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,6 +102,7 @@ known-local-folder = ["ubermagtable"] filterwarnings = [ "error", "ignore:((.|\n)*)Sentinel is not a public part of the traitlets API((.|\n)*)", # dependency of k3d + "ignore:((.|\n)*)`ipykernel.pylab.backend_inline` is deprecated((.|\n)*)", # dependency of ipywidgets ] [tool.setuptools.packages.find]