Skip to content

Commit

Permalink
Switch from black/isort/... to ruff (#99)
Browse files Browse the repository at this point in the history
Replace black/isort/... by ruff. Run `pre-commit run --all-files`.

Some additional rules should be enabled, but that will require additional effort.


---------

Co-authored-by: Dilan Pathirana <[email protected]>
  • Loading branch information
dweindl and dilpath authored Nov 12, 2024
1 parent ec9a5a6 commit 44a555a
Show file tree
Hide file tree
Showing 35 changed files with 866 additions and 944 deletions.
9 changes: 0 additions & 9 deletions .flake8

This file was deleted.

41 changes: 17 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,8 @@
# `pre-commit run --all-files` as by default only changed files are checked

repos:
- repo: https://github.com/psf/black
rev: 23.10.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.7.0
hooks:
- id: nbqa-black
- id: nbqa-pyupgrade
args: [--py36-plus]
- id: nbqa-isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: check-yaml
description: Check yaml files for parseable syntax
Expand All @@ -44,3 +21,19 @@ repos:
description: Fix empty lines at ends of files
- id: detect-private-key
description: Detects the presence of private keys
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.9
hooks:
# Run the linter.
- id: ruff
args:
- --fix
- --config
- pyproject.toml

# Run the formatter.
- id: ruff-format
args:
- --config
- pyproject.toml
18 changes: 11 additions & 7 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
from __future__ import annotations

import inspect

import sphinx

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'PEtab Select'
copyright = '2023, The PEtab Select developers'
author = 'The PEtab Select developers'
project = "PEtab Select"
copyright = "2024, The PEtab Select developers"
author = "The PEtab Select developers"


# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand All @@ -29,8 +33,8 @@
"sphinx_autodoc_typehints",
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


intersphinx_mapping = {
Expand All @@ -53,7 +57,7 @@
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"
# html_static_path = ['_static']
html_logo = "logo/logo-wide.svg"

Expand All @@ -73,5 +77,5 @@ def autodoc_skip_member(app, what, name, obj, skip, options):
return None


def setup(app: "sphinx.application.Sphinx"):
def setup(app: sphinx.application.Sphinx):
app.connect("autodoc-skip-member", autodoc_skip_member, priority=0)
15 changes: 3 additions & 12 deletions doc/examples/example_cli_famos.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
"from pathlib import Path\n",
"\n",
"from example_cli_famos_helpers import (\n",
" expected_criterion_values,\n",
" parse_summary_to_progress_list,\n",
" petab_select_problem_yaml,\n",
")\n",
"\n",
"output_path = Path().resolve() / \"output_famos\"\n",
Expand All @@ -50,16 +48,9 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import petab\n",
"from petab_select import Method\n",
"\n",
"import petab_select\n",
"from petab_select import ESTIMATE, FamosCandidateSpace, Method, Model\n",
"from petab_select.constants import Criterion\n",
"from petab_select.model import default_compare\n",
"\n",
"state = str(output_path / 'state.dill')\n",
"state = str(output_path / \"state.dill\")\n",
"\n",
"# Each iteration of model selection is described as a 2-tuple here.\n",
"# First value is the model selection method.\n",
Expand Down Expand Up @@ -231,7 +222,7 @@
"metadata": {},
"outputs": [],
"source": [
"progress_list = parse_summary_to_progress_list(output_path / 'summary.tsv')"
"progress_list = parse_summary_to_progress_list(output_path / \"summary.tsv\")"
]
},
{
Expand Down
6 changes: 2 additions & 4 deletions doc/examples/example_cli_famos_calibration_tool.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import sys

import pandas as pd
from example_cli_famos_helpers import calibrate

import petab_select
from petab_select import ESTIMATE, Criterion, Model

models_yaml = sys.argv[1]
calibrated_models_yaml = sys.argv[2]
Expand All @@ -24,6 +22,6 @@
(predecessor_model_hash,) = predecessor_model_hashes
else:
print(
'The models of this iteration somehow have different predecessor models.\n'
+ '\n'.join(predecessor_model_hashes)
"The models of this iteration somehow have different predecessor models.\n"
+ "\n".join(predecessor_model_hashes)
)
7 changes: 3 additions & 4 deletions doc/examples/example_cli_famos_helpers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from pathlib import Path
from typing import List, Tuple

import pandas as pd
from more_itertools import one

import petab_select
from petab_select import ESTIMATE, MODEL_HASH, Criterion, Method, Model
from petab_select import MODEL_HASH, Criterion, Method, Model

input_path = (
Path(__file__).resolve().parent.parent.parent
Expand Down Expand Up @@ -43,9 +42,9 @@ def calibrate(

def parse_summary_to_progress_list(
summary_tsv: str,
) -> List[Tuple[Method, set]]:
) -> list[tuple[Method, set]]:
"""Get progress information from the summary file."""
df_raw = pd.read_csv(summary_tsv, sep='\t')
df_raw = pd.read_csv(summary_tsv, sep="\t")
df = df_raw.loc[~pd.isnull(df_raw["predecessor change"])]

parameter_list = list(
Expand Down
18 changes: 9 additions & 9 deletions doc/examples/workflow_cli.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
}
],
"source": [
"with open(output_path / 'uncalibrated_models_1.yaml') as f:\n",
"with open(output_path / \"uncalibrated_models_1.yaml\") as f:\n",
" print(f.read())"
]
},
Expand Down Expand Up @@ -261,7 +261,7 @@
}
],
"source": [
"with open('model_selection/calibrated_models_1.yaml') as f:\n",
"with open(\"model_selection/calibrated_models_1.yaml\") as f:\n",
" print(f.read())"
]
},
Expand Down Expand Up @@ -362,7 +362,7 @@
}
],
"source": [
"with open(output_path / 'uncalibrated_models_2.yaml') as f:\n",
"with open(output_path / \"uncalibrated_models_2.yaml\") as f:\n",
" print(f.read())"
]
},
Expand Down Expand Up @@ -441,7 +441,7 @@
}
],
"source": [
"with open('model_selection/calibrated_M1_4.yaml') as f:\n",
"with open(\"model_selection/calibrated_M1_4.yaml\") as f:\n",
" print(f.read())"
]
},
Expand Down Expand Up @@ -501,7 +501,7 @@
}
],
"source": [
"with open(output_path / 'uncalibrated_models_3.yaml') as f:\n",
"with open(output_path / \"uncalibrated_models_3.yaml\") as f:\n",
" print(f.read())"
]
},
Expand Down Expand Up @@ -566,7 +566,7 @@
}
],
"source": [
"with open('model_selection/calibrated_M1_7.yaml') as f:\n",
"with open(\"model_selection/calibrated_M1_7.yaml\") as f:\n",
" print(f.read())"
]
},
Expand Down Expand Up @@ -605,7 +605,7 @@
}
],
"source": [
"with open(output_path / 'uncalibrated_models_4.yaml') as f:\n",
"with open(output_path / \"uncalibrated_models_4.yaml\") as f:\n",
" print(f.read())"
]
},
Expand Down Expand Up @@ -699,7 +699,7 @@
}
],
"source": [
"with open(output_path / 'uncalibrated_models_5.yaml') as f:\n",
"with open(output_path / \"uncalibrated_models_5.yaml\") as f:\n",
" print(f.read())"
]
},
Expand Down Expand Up @@ -765,7 +765,7 @@
}
],
"source": [
"with open(output_path / 'best_model.yaml') as f:\n",
"with open(output_path / \"best_model.yaml\") as f:\n",
" print(f.read())"
]
},
Expand Down
33 changes: 16 additions & 17 deletions doc/examples/workflow_python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,30 @@
],
"source": [
"import petab_select\n",
"from petab_select import ForwardCandidateSpace, Model\n",
"from petab_select import Model\n",
"from petab_select.constants import (\n",
" CANDIDATE_SPACE,\n",
" MODELS,\n",
" TERMINATE,\n",
" UNCALIBRATED_MODELS,\n",
")\n",
"\n",
"BOLD_TEXT = '\\033[1m'\n",
"NORMAL_TEXT = '\\033[0m'\n",
"BOLD_TEXT = \"\\033[1m\"\n",
"NORMAL_TEXT = \"\\033[0m\"\n",
"\n",
"# Load the PEtab Select problem.\n",
"select_problem = petab_select.Problem.from_yaml(\n",
" 'model_selection/petab_select_problem.yaml'\n",
" \"model_selection/petab_select_problem.yaml\"\n",
")\n",
"# Fake criterion values as a surrogate for a model calibration tool.\n",
"fake_criterion = {\n",
" 'M1_0': 200,\n",
" 'M1_1': 150,\n",
" 'M1_2': 140,\n",
" 'M1_3': 130,\n",
" 'M1_4': -40,\n",
" 'M1_5': -70,\n",
" 'M1_6': -110,\n",
" 'M1_7': 50,\n",
" \"M1_0\": 200,\n",
" \"M1_1\": 150,\n",
" \"M1_2\": 140,\n",
" \"M1_3\": 130,\n",
" \"M1_4\": -40,\n",
" \"M1_5\": -70,\n",
" \"M1_6\": -110,\n",
" \"M1_7\": 50,\n",
"}\n",
"\n",
"\n",
Expand Down Expand Up @@ -327,7 +326,7 @@
"\n",
"for candidate_model in iteration_results[MODELS].values():\n",
" if candidate_model.get_hash() == local_best_model.get_hash():\n",
" print(BOLD_TEXT + 'BEST MODEL OF CURRENT ITERATION' + NORMAL_TEXT)\n",
" print(BOLD_TEXT + \"BEST MODEL OF CURRENT ITERATION\" + NORMAL_TEXT)\n",
" print_model(candidate_model)"
]
},
Expand Down Expand Up @@ -377,7 +376,7 @@
"\n",
"for candidate_model in iteration_results[MODELS].values():\n",
" if candidate_model.get_hash() == local_best_model.get_hash():\n",
" print(BOLD_TEXT + 'BEST MODEL OF CURRENT ITERATION' + NORMAL_TEXT)\n",
" print(BOLD_TEXT + \"BEST MODEL OF CURRENT ITERATION\" + NORMAL_TEXT)\n",
" print_model(candidate_model)"
]
},
Expand Down Expand Up @@ -420,7 +419,7 @@
"\n",
"for candidate_model in iteration_results[MODELS].values():\n",
" if candidate_model.get_hash() == local_best_model.get_hash():\n",
" print(BOLD_TEXT + 'BEST MODEL OF CURRENT ITERATION' + NORMAL_TEXT)\n",
" print(BOLD_TEXT + \"BEST MODEL OF CURRENT ITERATION\" + NORMAL_TEXT)\n",
" print_model(candidate_model)"
]
},
Expand Down Expand Up @@ -467,7 +466,7 @@
}
],
"source": [
"print(f'Number of candidate models: {len(iteration_results[MODELS])}.')"
"print(f\"Number of candidate models: {len(iteration_results[MODELS])}.\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion petab_select/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
__all__ = [
x
for x in dir(sys.modules[__name__])
if not x.startswith('_') and x != 'sys'
if not x.startswith("_") and x != "sys"
]
Loading

0 comments on commit 44a555a

Please sign in to comment.