diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8d6e652f8..bccbf1a70 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,6 @@ "vscode": { "settings": { "python.linting.enabled": true, - "python.linting.flake8Enabled": true, "python.linting.pylintEnabled": false, "python.testing.pytestEnabled": true, "editor.formatOnSave": true, @@ -13,17 +12,15 @@ "source.organizeImports": true }, "[python]": { - "editor.defaultFormatter": "ms-python.black-formatter" + "editor.defaultFormatter": "charliermarsh.ruff" }, "editor.rulers": [ 80 ] }, "extensions": [ - "ms-python.python", - "ms-python.isort", - "ms-python.flake8", - "ms-python.black-formatter" + "charliermarsh.ruff", + "ms-python.python" ] } }, diff --git a/autokeras/auto_model.py b/autokeras/auto_model.py index ed7ebbe46..79d2eccb8 100644 --- a/autokeras/auto_model.py +++ b/autokeras/auto_model.py @@ -130,7 +130,7 @@ def __init__( overwrite: bool = False, seed: Optional[int] = None, max_model_size: Optional[int] = None, - **kwargs + **kwargs, ): self.inputs = tree.flatten(inputs) self.outputs = tree.flatten(outputs) @@ -152,7 +152,7 @@ def __init__( seed=self.seed, project_name=project_name, max_model_size=max_model_size, - **kwargs + **kwargs, ) self.overwrite = overwrite self._heads = [output_node.in_blocks[0] for output_node in self.outputs] @@ -225,7 +225,7 @@ def fit( validation_split=0.2, validation_data=None, verbose=1, - **kwargs + **kwargs, ): """Search for the best model and hyperparameters for the AutoModel. @@ -307,7 +307,7 @@ def fit( validation_data=validation_data, validation_split=validation_split, verbose=verbose, - **kwargs + **kwargs, ) return history @@ -475,7 +475,7 @@ def predict(self, x, batch_size=32, verbose=1, **kwargs): batch_size=batch_size, x=dataset, verbose=verbose, - **kwargs + **kwargs, ) return pipeline.postprocess(y) @@ -515,7 +515,7 @@ def evaluate(self, x, y=None, batch_size=32, verbose=1, **kwargs): batch_size=batch_size, x=dataset, verbose=verbose, - **kwargs + **kwargs, ) def export_model(self): diff --git a/autokeras/blocks/heads.py b/autokeras/blocks/heads.py index d1ce8b55e..12cb2c0b5 100644 --- a/autokeras/blocks/heads.py +++ b/autokeras/blocks/heads.py @@ -64,7 +64,7 @@ def __init__( loss: Optional[types.LossType] = None, metrics: Optional[types.MetricsType] = None, dropout: Optional[float] = None, - **kwargs + **kwargs, ): self.num_classes = num_classes self.multi_label = multi_label @@ -217,7 +217,7 @@ def __init__( loss: types.LossType = "mean_squared_error", metrics: Optional[types.MetricsType] = None, dropout: Optional[float] = None, - **kwargs + **kwargs, ): if metrics is None: metrics = ["mean_squared_error"] diff --git a/autokeras/blocks/preprocessing.py b/autokeras/blocks/preprocessing.py index 2e43b4d88..896a74ea1 100644 --- a/autokeras/blocks/preprocessing.py +++ b/autokeras/blocks/preprocessing.py @@ -100,7 +100,7 @@ def __init__( contrast_factor: Optional[ Union[float, Tuple[float, float], hyperparameters.Choice] ] = None, - **kwargs + **kwargs, ): super().__init__(**kwargs) self.translation_factor = utils.get_hyperparameter( diff --git a/autokeras/blocks/wrapper.py b/autokeras/blocks/wrapper.py index e6d1faf3b..38371d4e3 100644 --- a/autokeras/blocks/wrapper.py +++ b/autokeras/blocks/wrapper.py @@ -51,7 +51,7 @@ def __init__( block_type: Optional[str] = None, normalize: Optional[bool] = None, augment: Optional[bool] = None, - **kwargs + **kwargs, ): super().__init__(**kwargs) self.block_type = block_type diff --git a/autokeras/engine/head.py b/autokeras/engine/head.py index 01cefd1a9..60c82a816 100644 --- a/autokeras/engine/head.py +++ b/autokeras/engine/head.py @@ -65,7 +65,7 @@ def __init__( self, loss: Optional[types.LossType] = None, metrics: Optional[types.MetricsType] = None, - **kwargs + **kwargs, ): super().__init__(**kwargs) self.loss = loss diff --git a/autokeras/engine/tuner.py b/autokeras/engine/tuner.py index 37bbb6e26..28e520494 100644 --- a/autokeras/engine/tuner.py +++ b/autokeras/engine/tuner.py @@ -150,7 +150,7 @@ def search( callbacks=None, validation_split=0, verbose=1, - **fit_kwargs + **fit_kwargs, ): """Search for the best HyperParameters. @@ -203,7 +203,7 @@ def search( epochs=epochs, callbacks=new_callbacks, verbose=verbose, - **fit_kwargs + **fit_kwargs, ) # Train the best model use validation data. diff --git a/autokeras/tasks/image.py b/autokeras/tasks/image.py index 73a2e5986..224214142 100644 --- a/autokeras/tasks/image.py +++ b/autokeras/tasks/image.py @@ -86,7 +86,7 @@ def __init__( overwrite: bool = False, seed: Optional[int] = None, max_model_size: Optional[int] = None, - **kwargs + **kwargs, ): if tuner is None: tuner = task_specific.ImageClassifierTuner @@ -105,7 +105,7 @@ def __init__( overwrite=overwrite, seed=seed, max_model_size=max_model_size, - **kwargs + **kwargs, ) def fit( @@ -118,7 +118,7 @@ def fit( validation_data: Union[ tf.data.Dataset, Tuple[types.DatasetType, types.DatasetType], None ] = None, - **kwargs + **kwargs, ): """Search for the best model and hyperparameters for the AutoModel. @@ -172,7 +172,7 @@ def fit( callbacks=callbacks, validation_split=validation_split, validation_data=validation_data, - **kwargs + **kwargs, ) return history @@ -222,7 +222,7 @@ def __init__( overwrite: bool = False, seed: Optional[int] = None, max_model_size: Optional[int] = None, - **kwargs + **kwargs, ): if tuner is None: tuner = greedy.Greedy @@ -238,7 +238,7 @@ def __init__( overwrite=overwrite, seed=seed, max_model_size=max_model_size, - **kwargs + **kwargs, ) def fit( @@ -251,7 +251,7 @@ def fit( validation_data: Union[ types.DatasetType, Tuple[types.DatasetType], None ] = None, - **kwargs + **kwargs, ): """Search for the best model and hyperparameters for the AutoModel. @@ -306,6 +306,6 @@ def fit( callbacks=callbacks, validation_split=validation_split, validation_data=validation_data, - **kwargs + **kwargs, ) return history diff --git a/autokeras/tasks/text.py b/autokeras/tasks/text.py index 7ba62842c..ddc068481 100644 --- a/autokeras/tasks/text.py +++ b/autokeras/tasks/text.py @@ -81,7 +81,7 @@ def __init__( overwrite: bool = False, seed: Optional[int] = None, max_model_size: Optional[int] = None, - **kwargs + **kwargs, ): if tuner is None: tuner = task_specific.TextClassifierTuner @@ -100,7 +100,7 @@ def __init__( overwrite=overwrite, seed=seed, max_model_size=max_model_size, - **kwargs + **kwargs, ) def fit( @@ -111,7 +111,7 @@ def fit( callbacks=None, validation_split=0.2, validation_data=None, - **kwargs + **kwargs, ): """Search for the best model and hyperparameters for the AutoModel. @@ -167,7 +167,7 @@ def fit( callbacks=callbacks, validation_split=validation_split, validation_data=validation_data, - **kwargs + **kwargs, ) return history @@ -217,7 +217,7 @@ def __init__( overwrite: bool = False, seed: Optional[int] = None, max_model_size: Optional[int] = None, - **kwargs + **kwargs, ): if tuner is None: tuner = greedy.Greedy @@ -233,7 +233,7 @@ def __init__( overwrite=overwrite, seed=seed, max_model_size=max_model_size, - **kwargs + **kwargs, ) def fit( @@ -244,7 +244,7 @@ def fit( callbacks=None, validation_split=0.2, validation_data=None, - **kwargs + **kwargs, ): """Search for the best model and hyperparameters for the AutoModel. @@ -300,6 +300,6 @@ def fit( callbacks=callbacks, validation_split=validation_split, validation_data=validation_data, - **kwargs + **kwargs, ) return history diff --git a/autokeras/tuners/greedy.py b/autokeras/tuners/greedy.py index 8d892fedb..ba1e7be9f 100644 --- a/autokeras/tuners/greedy.py +++ b/autokeras/tuners/greedy.py @@ -216,7 +216,7 @@ def __init__( hyperparameters: Optional[keras_tuner.HyperParameters] = None, tune_new_entries: bool = True, allow_new_entries: bool = True, - **kwargs + **kwargs, ): self.seed = seed oracle = GreedyOracle( diff --git a/docker/pre-commit.Dockerfile b/docker/pre-commit.Dockerfile index d4370f5af..fae13ebc3 100644 --- a/docker/pre-commit.Dockerfile +++ b/docker/pre-commit.Dockerfile @@ -1,6 +1,6 @@ -FROM python:3.7 +FROM python:3.8 -RUN pip install flake8 black isort +RUN pip install ruff WORKDIR /autokeras CMD ["python", "docker/pre_commit.py"] diff --git a/docker/pre_commit.py b/docker/pre_commit.py index 8cb1566a2..fabc9e7c2 100644 --- a/docker/pre_commit.py +++ b/docker/pre_commit.py @@ -6,7 +6,7 @@ def check_bash_call(string): check_call(["bash", "-c", string]) -def _run_format_and_flake8(): +def _run_lint_and_format(): files_changed = False try: @@ -25,13 +25,13 @@ def _run_format_and_flake8(): exit(1) -def run_format_and_flake8(): +def run_lint_and_format(): try: - _run_format_and_flake8() + _run_lint_and_format() except CalledProcessError as error: print("Pre-commit returned exit code", error.returncode) exit(error.returncode) if __name__ == "__main__": - run_format_and_flake8() + run_lint_and_format() diff --git a/docs/ipynb/text_regression.ipynb b/docs/ipynb/text_regression.ipynb index b01696359..a200f4f77 100644 --- a/docs/ipynb/text_regression.ipynb +++ b/docs/ipynb/text_regression.ipynb @@ -101,7 +101,8 @@ "source": [ "# Initialize the text regressor.\n", "reg = ak.TextRegressor(\n", - " overwrite=True, max_trials=1 # It tries 10 different models.\n", + " overwrite=True,\n", + " max_trials=1, # It tries 10 different models.\n", ")\n", "# Feed the text regressor with training data.\n", "reg.fit(x_train, y_train, epochs=1, batch_size=2)\n", diff --git a/docs/py/text_regression.py b/docs/py/text_regression.py index 59d10583f..482f6ac2f 100644 --- a/docs/py/text_regression.py +++ b/docs/py/text_regression.py @@ -58,7 +58,8 @@ # Initialize the text regressor. reg = ak.TextRegressor( - overwrite=True, max_trials=1 # It tries 10 different models. + overwrite=True, + max_trials=1, # It tries 10 different models. ) # Feed the text regressor with training data. reg.fit(x_train, y_train, epochs=1, batch_size=2) diff --git a/docs/tutobooks.py b/docs/tutobooks.py index 76226a1fe..136c4d923 100644 --- a/docs/tutobooks.py +++ b/docs/tutobooks.py @@ -239,10 +239,7 @@ def nb_to_md(nb_path, md_path, img_dir, working_dir=None): os.system( # "jupyter nbconvert --to markdown --execute --debug " - "jupyter nbconvert --to markdown " - + nb_fname - + " --output " - + target_md + "jupyter nbconvert --to markdown " + nb_fname + " --output " + target_md # + " --ExecutePreprocessor.timeout=" # + str(TIMEOUT) ) diff --git a/pyproject.toml b/pyproject.toml index d9a47831f..8108d945b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,9 +56,38 @@ version = {attr = "autokeras.__init__.__version__"} [tool.setuptools.packages.find] include = ["autokeras", "autokeras.*"] -[tool.black] +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "@abstract", + "raise NotImplementedError", +] +omit = [ + "*test*", + "autokeras/prototype/*", +] + +[tool.pytest.ini_options] +addopts = "-v -p no:warnings --durations=10" +log_cli_level = "INFO" +norecursedirs = "build" # Do not run tests in the build folder + +[tool.ruff] line-length = 80 -target-version = [] + +[tool.ruff.lint] +select = [ + "E", # pycodestyle error + "F", # Pyflakes + "I", # isort +] + +[tool.ruff.lint.per-file-ignores] +"**/__init__.py" = ["F401"] # imported but unused + +[tool.ruff.lint.isort] +force-single-line = true +known-first-party = ["autokeras"] [tool.isort] profile = "black" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 2343c6c92..000000000 --- a/setup.cfg +++ /dev/null @@ -1,24 +0,0 @@ -[tool:pytest] -addopts=-v - -p no:warnings - --durations=10 - --log-cli-level=CRITICAL - -# Do not run tests in the build folder -norecursedirs= build - -[coverage:report] -exclude_lines = - pragma: no cover - @abstract - raise NotImplementedError -omit = - *test* - autokeras/prototype/* - -[flake8] - -# imported but unused in __init__.py, that's ok. -per-file-ignores = **/__init__.py:F401 -ignore = E203, W503 -max-line-length = 80 diff --git a/shell/format.sh b/shell/format.sh index 9596c156f..9fd4f4eff 100755 --- a/shell/format.sh +++ b/shell/format.sh @@ -1,5 +1,9 @@ -isort . -black . +#!/bin/bash +set -Euo pipefail + +ruff check --fix . + +ruff format . for i in $(find autokeras benchmark -name '*.py') do @@ -9,5 +13,3 @@ do cat shell/copyright.txt $i >$i.new && mv $i.new $i fi done - -flake8 . diff --git a/shell/lint.sh b/shell/lint.sh index ae5d5a301..d4dbf28fc 100755 --- a/shell/lint.sh +++ b/shell/lint.sh @@ -1,16 +1,14 @@ -isort -c . +#!/bin/bash +set -Euo pipefail + +ruff check . if ! [ $? -eq 0 ] then echo "Please run \"sh shell/format.sh\" to format the code." exit 1 fi -flake8 . -if ! [ $? -eq 0 ] -then - echo "Please fix the code style issue." - exit 1 -fi -black --check . + +ruff format --check . if ! [ $? -eq 0 ] then echo "Please run \"sh shell/format.sh\" to format the code."