diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 521ff54f85..c611e18154 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,15 +16,21 @@ repos: args: [--allow-multiple-documents] - id: end-of-file-fixer - id: trailing-whitespace -- repo: https://github.com/psf/black - rev: 23.7.0 +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.1.11 hooks: - - id: black-jupyter - # It is recommended to specify the latest version of Python - # supported by your project here, or alternatively use - # pre-commit's default_language_version, see - # https://pre-commit.com/#top_level-default_language_version - language_version: python3.11 - args: ["--line-length", "79"] + # Run the linter. + - id: ruff + args: + - --fix + - --config + - python/sdist/pyproject.toml + + # Run the formatter. + - id: ruff-format + args: + - --config + - python/sdist/pyproject.toml exclude: '^(ThirdParty|models)/' diff --git a/documentation/conf.py b/documentation/conf.py index 6576601208..c880530e00 100644 --- a/documentation/conf.py +++ b/documentation/conf.py @@ -5,7 +5,6 @@ # This file does only contain a selection of the most common options. For a # full list see the documentation: # http://www.sphinx-doc.org/en/stable/config - import os import re import subprocess @@ -18,6 +17,7 @@ import exhale_multiproject_monkeypatch import mock import pandas as pd +import sphinx import sympy as sp from exhale import configs as exhale_configs from sphinx.transforms.post_transforms import ReferencesResolver diff --git a/python/sdist/amici/__init__.py b/python/sdist/amici/__init__.py index 4ee6f05637..b06ea6d0f3 100644 --- a/python/sdist/amici/__init__.py +++ b/python/sdist/amici/__init__.py @@ -107,18 +107,21 @@ def _imported_from_setup() -> bool: # from .swig_wrappers hdf5_enabled = "readSolverSettingsFromHDF5" in dir() # These modules require the swig interface and other dependencies - from .numpy import ExpDataView, ReturnDataView + from .numpy import ExpDataView, ReturnDataView # noqa: F401 from .pandas import * from .swig_wrappers import * # These modules don't require the swig interface from typing import Protocol, runtime_checkable - from .de_export import DEExporter, DEModel - from .sbml_import import SbmlImporter, assignmentRules2observables + from .de_export import DEExporter, DEModel # noqa: F401 + from .sbml_import import ( # noqa: F401 + SbmlImporter, + assignmentRules2observables, + ) @runtime_checkable - class ModelModule(Protocol): + class ModelModule(Protocol): # noqa: F811 """Type of AMICI-generated model modules. To enable static type checking.""" diff --git a/python/sdist/amici/__init__.template.py b/python/sdist/amici/__init__.template.py index c37ac0f962..477cc727ec 100644 --- a/python/sdist/amici/__init__.template.py +++ b/python/sdist/amici/__init__.template.py @@ -15,7 +15,7 @@ "version currently installed." ) -from .TPL_MODELNAME import * -from .TPL_MODELNAME import getModel as get_model +from .TPL_MODELNAME import * # noqa: F403, F401 +from .TPL_MODELNAME import getModel as get_model # noqa: F401 __version__ = "TPL_PACKAGE_VERSION" diff --git a/python/sdist/amici/gradient_check.py b/python/sdist/amici/gradient_check.py index 27e2d671d3..d71983b266 100644 --- a/python/sdist/amici/gradient_check.py +++ b/python/sdist/amici/gradient_check.py @@ -331,7 +331,7 @@ def _check_results( """ result = rdata[field] - if type(result) is float: + if type(result) is float: # noqa E721 result = np.array(result) _check_close( diff --git a/python/sdist/amici/petab/util.py b/python/sdist/amici/petab/util.py index d30c1a6e9b..6d34fabfdf 100644 --- a/python/sdist/amici/petab/util.py +++ b/python/sdist/amici/petab/util.py @@ -1,6 +1,6 @@ """Various helper functions for working with PEtab problems.""" import re -from typing import Dict, Tuple, Union +from typing import TYPE_CHECKING, Dict, Tuple, Union import libsbml import pandas as pd @@ -9,6 +9,9 @@ from petab.mapping import resolve_mapping from petab.models import MODEL_TYPE_PYSB, MODEL_TYPE_SBML +if TYPE_CHECKING: + pysb = None + def get_states_in_condition_table( petab_problem: petab.Problem, diff --git a/python/sdist/pyproject.toml b/python/sdist/pyproject.toml index 011064fbdb..91b8484af6 100644 --- a/python/sdist/pyproject.toml +++ b/python/sdist/pyproject.toml @@ -15,3 +15,8 @@ build-backend = "setuptools.build_meta" [tool.black] line-length = 79 + +[tool.ruff] +line-length = 79 +ignore = ["E402", "F403", "F405", "E741"] +extend-include = ["*.ipynb"] diff --git a/python/tests/test_pysb.py b/python/tests/test_pysb.py index 52ca3a320f..2911b05fc9 100644 --- a/python/tests/test_pysb.py +++ b/python/tests/test_pysb.py @@ -1,4 +1,5 @@ """PYSB model tests""" +# flake8: noqa: F821 import importlib import logging diff --git a/tests/conftest.py b/tests/conftest.py index 9e90400518..7d98a09abb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,10 +3,13 @@ import re import sys from pathlib import Path -from typing import List, Set, Tuple +from typing import TYPE_CHECKING, List, Set, Tuple import pytest +if TYPE_CHECKING: + from _pytest.reports import TestReport + # stores passed SBML semantic test suite IDs passed_ids = []