From a8b40bf0b84297b45e81cbc9a1e9688b5e28f1e8 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Wed, 9 Oct 2024 12:46:29 +0200 Subject: [PATCH] Clean up quality checks (#40) * ruff instead of a range of different tools * update python requirement and python versions on GHA * update pre-commit config Closes #5 --- .flake8 | 16 ----------- .github/workflows/test_suite.yml | 15 ++++------ .isort.cfg | 2 -- .pre-commit-config.yaml | 47 +++++++++++--------------------- doc/conf.py | 11 +++++--- examples/derivative.ipynb | 1 - fiddy/derivative.py | 1 + fiddy/extensions/amici/amici.py | 2 +- pyproject.toml | 25 ++++++++++++++++- setup.cfg | 4 +-- tests/test_derivative.py | 6 ++-- tox.ini | 18 ------------ 12 files changed, 59 insertions(+), 89 deletions(-) delete mode 100644 .flake8 delete mode 100644 .isort.cfg diff --git a/.flake8 b/.flake8 deleted file mode 100644 index d34ccb8..0000000 --- a/.flake8 +++ /dev/null @@ -1,16 +0,0 @@ -[flake8] -extend-ignore = - # Don't be crazy if line too long - E501 - # Missing docstring in __init__ - D107 - # black: blank lines after docstring for function/class - D202,D204 - # Missing docstring in public module/class/method/function/package/magic method - D100,D101,D102,D103,D104,D105 -per-file-ignores = - */__init__.py:F401,F403 - tests/*:S101 -exclude = - amici_models - cache_fiddy diff --git a/.github/workflows/test_suite.yml b/.github/workflows/test_suite.yml index adb64fb..8afa4b5 100644 --- a/.github/workflows/test_suite.yml +++ b/.github/workflows/test_suite.yml @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.11'] + python-version: ['3.12'] steps: - name: Check out repository @@ -74,23 +74,18 @@ jobs: - name: Install dependencies run: pip install tox pre-commit -# failing on github, no size environment in tox.ini -# - name: Check repository size -# run: tox -e size - - name: Run quality checks timeout-minutes: 5 - run: tox -e pyroma,flake8 + run: tox -e pyroma -# failing on github -# - name: Run pre-commit hooks -# run: pre-commit run --all-files + - name: Run pre-commit hooks + run: pre-commit run --all-files docs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.11'] + python-version: ['3.12'] steps: - name: Check out repository diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index f238bf7..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[settings] -profile = black diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1730fde..974a8f5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,31 +10,8 @@ # `pre-commit run --all-files` as by default only changed files are checked repos: -- repo: https://github.com/psf/black - rev: 23.1.0 - hooks: - - id: black - description: The uncompromising code formatter -- repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - name: isort (python) - - id: isort - name: isort (cython) - types: [cython] - - id: isort - name: isort (pyi) - types: [pyi] -- repo: https://github.com/nbQA-dev/nbQA - rev: 1.6.3 - hooks: - - id: nbqa-black - - id: nbqa-pyupgrade - args: [--py36-plus] - - id: nbqa-isort - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: check-yaml description: Check yaml files for parseable syntax @@ -54,11 +31,19 @@ repos: description: Replace or check mixed line endings - id: trailing-whitespace description: Trim trailing whitespaces -- repo: local +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.6.9 hooks: - - id: style - name: Check style - description: Check style - entry: tox -e project,flake8 -- - language: python - types: [python] + # Run the linter. + - id: ruff + args: + - --fix + - --config + - pyproject.toml + + # Run the formatter. + - id: ruff-format + args: + - --config + - pyproject.toml diff --git a/doc/conf.py b/doc/conf.py index 0f5cb71..a06bba4 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,7 +1,6 @@ import os import sys - -import mock +from unittest import mock # Configuration file for the Sphinx documentation builder. # @@ -61,8 +60,12 @@ autodoc_mock_imports = [ - "amici", "amici.amici", "amici.petab", "amici.petab.simulations", - "amici.petab.parameter_mapping", "amici.petab.conditions" + "amici", + "amici.amici", + "amici.petab", + "amici.petab.simulations", + "amici.petab.parameter_mapping", + "amici.petab.conditions", ] for mod_name in autodoc_mock_imports: sys.modules[mod_name] = mock.MagicMock() diff --git a/examples/derivative.ipynb b/examples/derivative.ipynb index d28686f..3ba790b 100644 --- a/examples/derivative.ipynb +++ b/examples/derivative.ipynb @@ -30,7 +30,6 @@ ], "source": [ "import numpy as np\n", - "import pandas as pd\n", "from scipy.optimize import rosen, rosen_der\n", "\n", "from fiddy import MethodId, get_derivative\n", diff --git a/fiddy/derivative.py b/fiddy/derivative.py index 4b03406..65508ac 100644 --- a/fiddy/derivative.py +++ b/fiddy/derivative.py @@ -45,6 +45,7 @@ class Derivative: success: Whether the derivative was successfully computed. """ + hide_columns = [ "pending_computers", "computers", diff --git a/fiddy/extensions/amici/amici.py b/fiddy/extensions/amici/amici.py index aeb2e31..0ff6192 100644 --- a/fiddy/extensions/amici/amici.py +++ b/fiddy/extensions/amici/amici.py @@ -6,9 +6,9 @@ import amici.petab.simulations import numpy as np import petab.v1 as petab +from amici.petab.conditions import create_edatas from amici.petab.parameter_mapping import create_parameter_mapping from amici.petab.simulations import LLH, SLLH -from amici.petab.conditions import create_edatas from petab.v1.C import LIN, LOG, LOG10 from ...constants import Type diff --git a/pyproject.toml b/pyproject.toml index 67941fb..50771b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,5 +5,28 @@ requires = [ ] build-backend = "setuptools.build_meta" -[tool.black] +[tool.ruff] line-length = 79 +lint.select = [ + "F", # Pyflakes + "I", # isort + # "D", # pydocstyle (PEP 257) FIXME enable later + "S", # flake8-bandit + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "T20", # flake8-print + "W", # pycodestyle Warnings + "E", # pycodestyle Errors + "UP", # pyupgrade + # "ANN", # flakes-annotations +] +lint.ignore = [ + "S101", # Use of assert detected + # FIXME + "E501", # Line too long + "T201", # print statement + "F403", # star import + "F401", # unused import +] +[tool.ruff.lint.pydocstyle] +convention = "pep257" diff --git a/setup.cfg b/setup.cfg index b1d928b..94827e2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,9 +27,9 @@ classifiers = License :: OSI Approved :: BSD License Operating System :: OS Independent Programming Language :: Python + Programming Language :: Python :: 3.12 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.9 keywords = finite difference gradient check @@ -40,7 +40,7 @@ install_requires = numpy pandas -python_requires = >=3.9 +python_requires = >=3.10 include_package_data = True # Where is my code diff --git a/tests/test_derivative.py b/tests/test_derivative.py index e5ab637..37bc9a4 100644 --- a/tests/test_derivative.py +++ b/tests/test_derivative.py @@ -142,9 +142,9 @@ def test_get_derivative_relative(): ) # cardinal direction, simplifies to this, but usually need dot product g_a = (f_a - f_0) / size - g_r = (f_r - f_0) / ( - point * direction * size - ).sum() # cardinal direction, simplifies to this, but usually need dot product + g_r = ( + (f_r - f_0) / (point * direction * size).sum() + ) # cardinal direction, simplifies to this, but usually need dot product # Fiddy finite difference derivatives kwargs = { diff --git a/tox.ini b/tox.ini index 8c008c9..0ac4bad 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,6 @@ envlist = clean pyroma - flake8 doc # Base-environment @@ -40,23 +39,6 @@ commands = description = Check the package friendliness -[testenv:flake8] -skip_install = true -deps = - flake8 >= 6.0.0 - flake8-bandit >= 4.1.1 - flake8-bugbear >= 23.3.23 - flake8-colors >= 0.1.9 - flake8-comprehensions >= 3.12.0 - flake8-print >= 5.0.0 - flake8-black >= 0.3.6 - flake8-isort >= 6.0.0 - flake8-docstrings >= 1.7.0 -commands = - flake8 fiddy tests -description = - Run flake8 with various plugins. - [testenv:doc] extras = doc