Skip to content

Commit d45d387

Browse files
authored
ci: replace Pylint, Black and Unimport with Ruff (#216)
## Summary by Sourcery Replace Pylint, Black, and Unimport with Ruff for code linting, formatting, and import sorting Enhancements: - Consolidate multiple code quality tools into a single, performant tool - Simplify project configuration by reducing the number of linting and formatting tools CI: - Replace multiple linting and formatting tools with Ruff, a fast and comprehensive Python linter and formatter
1 parent 984fc15 commit d45d387

File tree

115 files changed

+3514
-3344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+3514
-3344
lines changed

.pre-commit-config.yaml

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
repos:
22

3-
- repo: https://github.com/astral-sh/uv-pre-commit
4-
rev: 0.6.9
3+
- repo: https://gitlab.com/vojko.pribudic.foss/pre-commit-update
4+
rev: v0.6.1
55
hooks:
6-
# Update the uv lockfile
7-
- id: uv-lock
8-
# Install all packages
9-
- id: uv-sync
10-
args: [--locked, --all-packages]
6+
- id: pre-commit-update
7+
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v5.0.0
10+
hooks:
11+
- id: check-added-large-files
12+
- id: check-json
13+
- id: check-toml
14+
- id: check-xml
15+
- id: check-yaml
16+
- id: end-of-file-fixer
17+
- id: no-commit-to-branch
18+
args: [--branch, main]
19+
- id: pretty-format-json
20+
args: [--autofix, --indent, '2']
21+
- id: trailing-whitespace
22+
23+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
24+
rev: v2.14.0
25+
hooks:
26+
- id: pretty-format-yaml
27+
args: [--autofix, --indent, '2']
28+
- id: pretty-format-toml
29+
args: [--autofix, --indent, '4', --no-sort]
1130

1231
- repo: https://github.com/compilerla/conventional-pre-commit
1332
rev: v2.1.1
@@ -40,19 +59,4 @@ repos:
4059
- id: isort
4160
name: isort (pyi)
4261
types: [pyi]
43-
args: [--check]
44-
45-
- repo: https://github.com/pre-commit/pre-commit-hooks
46-
rev: v4.4.0
47-
hooks:
48-
- id: double-quote-string-fixer
49-
- id: end-of-file-fixer
50-
- id: requirements-txt-fixer
51-
- id: trailing-whitespace
52-
- id: check-ast
53-
54-
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
55-
rev: v2.5.0
56-
hooks:
57-
- id: pretty-format-yaml
58-
args: [--autofix, --indent, '2']
62+
args: [--check]

Makefile

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
.PROJECT = boiling_learning
22
.TESTS_FOLDER = tests
33

4-
.UNIMPORT = $(shell uv run unimport --remove --gitignore --ignore-init --include-star-import $(.PROJECT) $(.TESTS_FOLDER))
5-
.BLACK = $(shell uv run black $(.PROJECT) $(.TESTS_FOLDER))
6-
.ISORT = $(shell uv run isort $(.PROJECT) $(.TESTS_FOLDER))
7-
.FORMAT = $(foreach command,.UNIMPORT .BLACK .ISORT,$(call $(command)))
8-
9-
.READD = $(shell git update-index --again)
10-
.CHECK = $(shell pre-commit run)
11-
124
.PHONY: coverage
135
coverage:
146
@uv run coverage run --source=$(.PROJECT)/ -m pytest $(.TESTS_FOLDER)
@@ -18,29 +10,22 @@ coverage:
1810
test:
1911
@uv run pytest --doctest-modules $(.PROJECT) $(.TESTS_FOLDER) -vv
2012

21-
.PHONY: check
22-
check:
23-
@$(call $(.CHECK))
13+
.PHONY: format
14+
format:
15+
@uv run --group format ruff format $(.PROJECT) $(.TESTS_FOLDER)
16+
17+
.PHONY: lint
18+
lint:
19+
@uv run --group lint ruff check --fix $(.PROJECT) $(.TESTS_FOLDER)
2420

2521
.PHONY: typecheck
2622
typecheck:
2723
@uv run mypy $(.PROJECT)
2824

29-
.PHONY: format
30-
format:
31-
@$(call $(.FORMAT))
32-
3325
.PHONY: vulture
3426
vulture:
3527
@uv run vulture --ignore-decorators @*.dispatch*,@*.instance* --ignore-names __*[!_][!_] $(.PROJECT) main.py
3628

37-
.PHONY: autofix
38-
autofix:
39-
@-$(call $(.FORMAT))
40-
@$(call $(.READD))
41-
@-$(call $(.CHECK))
42-
@$(call $(.READD))
43-
4429
.PHONY: release
4530
release:
4631
# for v1.0.0 and after, the following line should be used to bump the project version:
@@ -53,7 +38,3 @@ release:
5338
uv run cz bump --increment $(shell uv run cz bump --dry-run | grep -q "MAJOR" && echo "MINOR" || echo "PATCH")
5439
git push
5540
git push --tags
56-
57-
.PHONY: run
58-
run:
59-
uv run python main.py

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ Boiling Learning
33
</h1>
44

55
[![uv-managed](https://img.shields.io/badge/managed-261230?label=uv&logo=uv&labelColor=gray)](https://github.com/astral-sh/uv)
6+
[![Code style: Ruff](https://img.shields.io/badge/Ruff-checked-261230.svg?logo=ruff)](https://docs.astral.sh/ruff/)
7+
[![Sourcery](https://img.shields.io/badge/Sourcery-enabled-brightgreen)](https://sourcery.ai)
68

79
[![Github Actions](https://github.com/commitizen-tools/commitizen/workflows/Python%20package/badge.svg?style=flat-square)](https://github.com/ruancomelli/boiling-learning/actions)
8-
[![Sourcery](https://img.shields.io/badge/Sourcery-enabled-brightgreen)](https://sourcery.ai)
9-
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
10-
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
1110
[![SemVer](https://img.shields.io/badge/semver-2.0.0-green)](https://semver.org/spec/v2.0.0.html)
1211
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
1312
[![Author: ruancomelli](https://img.shields.io/badge/ruancomelli-blue?style=flat&label=author)](https://github.com/ruancomelli)

boiling_learning/__main__.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,41 @@
3737
)
3838

3939
app = typer.Typer()
40-
app.add_typer(animate.app, name='animate')
41-
app.add_typer(architectures.app, name='architectures')
42-
app.add_typer(automl.app, name='automl')
43-
app.add_typer(automl_cross_surface.app, name='automl-cross-surface')
44-
app.add_typer(automl_learning_curve.app, name='automl-learning-curve')
45-
app.add_typer(automl_strategies.app, name='automl-strategies')
46-
app.add_typer(automl_transfer_learning_curve.app, name='automl-transfer-learning-curve')
47-
app.add_typer(boiling_curve.app, name='boiling-curve')
48-
app.add_typer(consecutive_frames.app, name='consecutive-frames')
49-
app.add_typer(cross_surface.app, name='cross-surface')
50-
app.add_typer(data_augmentation.app, name='data-augmentation')
51-
app.add_typer(data_augmentation_automl.app, name='data-augmentation-automl')
52-
app.add_typer(data_split.app, name='data-split')
53-
app.add_typer(dataset_sizes.app, name='dataset-sizes')
54-
app.add_typer(diameter_effects.app, name='diameter-effects')
55-
app.add_typer(downscaling_preprocessing.app, name='downscaling-preprocessing')
56-
app.add_typer(downscaling_training.app, name='downscaling-training')
57-
app.add_typer(example_frames.app, name='example-frames')
58-
app.add_typer(example_frames_matrix.app, name='example-frames-matrix')
59-
app.add_typer(heat_flux_levels.app, name='heat-flux-levels')
60-
app.add_typer(image_brightness.app, name='image-brightness')
61-
app.add_typer(image_normalization.app, name='image-normalization')
62-
app.add_typer(image_standardization.app, name='image-standardization')
63-
app.add_typer(inclination_effects.app, name='inclination-effects')
64-
app.add_typer(learning_curve.app, name='learning-curve')
65-
app.add_typer(preprocessing.app, name='preprocessing')
66-
app.add_typer(single_surface.app, name='single-surface')
67-
app.add_typer(transfer_learning_curve.app, name='transfer-learning-curve')
68-
app.add_typer(uncertainties.app, name='uncertainties')
69-
app.add_typer(validate.app, name='validate')
70-
app.add_typer(visualization_window.app, name='visualization-window')
71-
app.add_typer(visualization_window_multi_surface.app, name='visualization-window-multi-surface')
40+
app.add_typer(animate.app, name="animate")
41+
app.add_typer(architectures.app, name="architectures")
42+
app.add_typer(automl.app, name="automl")
43+
app.add_typer(automl_cross_surface.app, name="automl-cross-surface")
44+
app.add_typer(automl_learning_curve.app, name="automl-learning-curve")
45+
app.add_typer(automl_strategies.app, name="automl-strategies")
46+
app.add_typer(automl_transfer_learning_curve.app, name="automl-transfer-learning-curve")
47+
app.add_typer(boiling_curve.app, name="boiling-curve")
48+
app.add_typer(consecutive_frames.app, name="consecutive-frames")
49+
app.add_typer(cross_surface.app, name="cross-surface")
50+
app.add_typer(data_augmentation.app, name="data-augmentation")
51+
app.add_typer(data_augmentation_automl.app, name="data-augmentation-automl")
52+
app.add_typer(data_split.app, name="data-split")
53+
app.add_typer(dataset_sizes.app, name="dataset-sizes")
54+
app.add_typer(diameter_effects.app, name="diameter-effects")
55+
app.add_typer(downscaling_preprocessing.app, name="downscaling-preprocessing")
56+
app.add_typer(downscaling_training.app, name="downscaling-training")
57+
app.add_typer(example_frames.app, name="example-frames")
58+
app.add_typer(example_frames_matrix.app, name="example-frames-matrix")
59+
app.add_typer(heat_flux_levels.app, name="heat-flux-levels")
60+
app.add_typer(image_brightness.app, name="image-brightness")
61+
app.add_typer(image_normalization.app, name="image-normalization")
62+
app.add_typer(image_standardization.app, name="image-standardization")
63+
app.add_typer(inclination_effects.app, name="inclination-effects")
64+
app.add_typer(learning_curve.app, name="learning-curve")
65+
app.add_typer(preprocessing.app, name="preprocessing")
66+
app.add_typer(single_surface.app, name="single-surface")
67+
app.add_typer(transfer_learning_curve.app, name="transfer-learning-curve")
68+
app.add_typer(uncertainties.app, name="uncertainties")
69+
app.add_typer(validate.app, name="validate")
70+
app.add_typer(visualization_window.app, name="visualization-window")
71+
app.add_typer(
72+
visualization_window_multi_surface.app, name="visualization-window-multi-surface"
73+
)
7274

7375

74-
if __name__ == '__main__':
76+
if __name__ == "__main__":
7577
app()

boiling_learning/app/automl/autofit_dataset.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
from boiling_learning.app.automl.evaluation import cached_best_model_evaluator
77
from boiling_learning.app.automl.tuning import autofit
8-
from boiling_learning.app.datasets.preprocessed.boiling1d import baseline_boiling_dataset
8+
from boiling_learning.app.datasets.preprocessed.boiling1d import (
9+
baseline_boiling_dataset,
10+
)
911
from boiling_learning.app.paths import analyses_path
1012
from boiling_learning.app.training.common import get_baseline_compile_params
1113
from boiling_learning.automl.hypermodels import ConvImageRegressor, HyperModel
@@ -22,7 +24,7 @@ def autofit_dataset(
2224
*,
2325
strategy: LazyDescribed[tf.distribute.Strategy],
2426
target: str,
25-
experiment: Literal['boiling1d', 'condensation'],
27+
experiment: Literal["boiling1d", "condensation"],
2628
normalize_images: bool = True,
2729
max_model_size: int | None = None,
2830
goal: float | None = None,
@@ -31,15 +33,15 @@ def autofit_dataset(
3133
compile_params = get_baseline_compile_params(strategy=strategy)
3234

3335
hypermodel = ConvImageRegressor(
34-
loss=compile_params['loss'],
35-
metrics=compile_params['metrics'],
36+
loss=compile_params["loss"],
37+
metrics=compile_params["metrics"],
3638
tuner=tuner_class,
3739
directory=_get_autofit_to_dataset_allocator(experiment).allocate(
3840
ConvImageRegressor,
3941
datasets,
4042
tuner=tuner_class,
41-
loss=compile_params['loss'],
42-
metrics=compile_params['metrics'],
43+
loss=compile_params["loss"],
44+
metrics=compile_params["metrics"],
4345
normalize_images=normalize_images,
4446
max_model_size=max_model_size,
4547
goal=goal,
@@ -57,11 +59,11 @@ def autofit_dataset(
5759
LazyDescribed.from_constructor(tf.keras.callbacks.TerminateOnNaN),
5860
LazyDescribed.from_constructor(
5961
tf.keras.callbacks.EarlyStopping,
60-
monitor='val_loss',
62+
monitor="val_loss",
6163
min_delta=0,
6264
patience=10,
6365
baseline=None,
64-
mode='auto',
66+
mode="auto",
6567
restore_best_weights=True,
6668
verbose=1,
6769
),
@@ -86,7 +88,7 @@ def best_model_for_dataset(
8688
*,
8789
strategy: LazyDescribed[tf.distribute.Strategy],
8890
target: str,
89-
experiment: Literal['boiling1d', 'condensation'],
91+
experiment: Literal["boiling1d", "condensation"],
9092
normalize_images: bool = True,
9193
max_model_size: int | None = None,
9294
goal: float | None = None,
@@ -103,7 +105,7 @@ def best_model_for_dataset(
103105
tuner_class=tuner_class,
104106
)
105107
best_model_evaluator = cached_best_model_evaluator(
106-
experiment='boiling1d',
108+
experiment="boiling1d",
107109
strategy=strategy,
108110
)
109111
return best_model_evaluator(
@@ -128,7 +130,7 @@ def best_baseline_boiling1d_model(
128130
datasets,
129131
strategy=strategy,
130132
target=target,
131-
experiment='boiling1d',
133+
experiment="boiling1d",
132134
normalize_images=normalize_images,
133135
max_model_size=max_model_size,
134136
goal=goal,
@@ -138,7 +140,9 @@ def best_baseline_boiling1d_model(
138140

139141
@cache
140142
def _get_autofit_to_dataset_allocator(
141-
experiment: Literal['boiling1d', 'condensation'],
143+
experiment: Literal["boiling1d", "condensation"],
142144
/,
143145
) -> JSONAllocator:
144-
return JSONAllocator(analyses_path() / 'autofit' / 'autofit-to-dataset' / experiment)
146+
return JSONAllocator(
147+
analyses_path() / "autofit" / "autofit-to-dataset" / experiment
148+
)

boiling_learning/app/automl/evaluation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
@functools.cache
1818
def cached_best_model_evaluator(
1919
*,
20-
experiment: Literal['boiling1d', 'condensation'],
20+
experiment: Literal["boiling1d", "condensation"],
2121
strategy: LazyDescribed[tf.distribute.Strategy],
2222
):
2323
model_evaluator = cached_model_evaluator(experiment)
2424

2525
@cache(
26-
JSONAllocator(shared_cache_path() / 'best-model-evaluations' / experiment),
26+
JSONAllocator(shared_cache_path() / "best-model-evaluations" / experiment),
2727
loader=load_with_strategy(strategy),
2828
)
2929
def hypermodel_evaluator(
@@ -32,7 +32,7 @@ def hypermodel_evaluator(
3232
*,
3333
measure_uncertainty: bool = True,
3434
gt10: bool = True,
35-
metric_name: str = 'loss',
35+
metric_name: str = "loss",
3636
) -> LazyDescribed[ModelArchitecture]:
3737
return min(
3838
map(LazyDescribed.from_describable, hypermodel.iter_best_models()),

boiling_learning/app/automl/tuning.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
from boiling_learning.app.datasets.bridging import to_tensorflow_triplet
77
from boiling_learning.automl.hypermodels import HyperModel
8-
from boiling_learning.automl.tuning import TuneModelParams, TuneModelReturn, fit_hypermodel
8+
from boiling_learning.automl.tuning import (
9+
TuneModelParams,
10+
TuneModelReturn,
11+
fit_hypermodel,
12+
)
913
from boiling_learning.image_datasets import ImageDatasetTriplet
1014
from boiling_learning.lazy import LazyDescribed
1115
from boiling_learning.model.callbacks import MemoryCleanUp
@@ -17,7 +21,7 @@ def autofit(
1721
datasets: LazyDescribed[ImageDatasetTriplet],
1822
params: TuneModelParams,
1923
target: str,
20-
experiment: Literal['boiling1d', 'condensation'],
24+
experiment: Literal["boiling1d", "condensation"],
2125
strategy: LazyDescribed[tf.distribute.Strategy],
2226
) -> TuneModelReturn:
2327
datasets_tf = to_tensorflow_triplet(

boiling_learning/app/constants.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88

99
@cache
1010
def masters_path() -> Path:
11-
return resolve(os.environ['MASTERS_PATH'])
11+
return resolve(os.environ["MASTERS_PATH"])
1212

1313

1414
@cache
1515
def figures_path() -> Path:
16-
return resolve(os.environ['FIGURES_PATH'])
16+
return resolve(os.environ["FIGURES_PATH"])
1717

1818

1919
@cache
2020
def high_speed_cache_path() -> Path:
21-
'''A path to a high speed cache.
21+
"""Get the path to a high speed cache.
2222
2323
Store in this path data that has to be written/read frequently, such as machine learning
2424
training data.
25-
'''
26-
return resolve(os.environ['HIGH_SPEED_CACHE_PATH'])
25+
"""
26+
return resolve(os.environ["HIGH_SPEED_CACHE_PATH"])
2727

2828

2929
BOILING_BASELINE_BATCH_SIZE = round_to_multiple(200, base=8)
3030
BASELINE_BOILING_MSE_DIRECT = 13 # W / cm**2
3131
BASELINE_BOILING_MSE_INDIRECT = 33 # W / cm**2
3232

33-
DEFAULT_CONDENSATION_MASS_RATE_TARGET = 'mass_rate'
33+
DEFAULT_CONDENSATION_MASS_RATE_TARGET = "mass_rate"

0 commit comments

Comments
 (0)