Skip to content

Replace Black, isort and flake8 with Ruff check and formatter #1931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@
"vscode": {
"settings": {
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.pylintEnabled": false,
"python.testing.pytestEnabled": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"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"
]
}
},
Expand Down
12 changes: 6 additions & 6 deletions autokeras/auto_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -307,7 +307,7 @@ def fit(
validation_data=validation_data,
validation_split=validation_split,
verbose=verbose,
**kwargs
**kwargs,
)

return history
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions autokeras/blocks/heads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion autokeras/blocks/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion autokeras/blocks/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion autokeras/engine/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions autokeras/engine/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def search(
callbacks=None,
validation_split=0,
verbose=1,
**fit_kwargs
**fit_kwargs,
):
"""Search for the best HyperParameters.

Expand Down Expand Up @@ -203,7 +203,7 @@ def search(
epochs=epochs,
callbacks=new_callbacks,
verbose=verbose,
**fit_kwargs
**fit_kwargs,
)

# Train the best model use validation data.
Expand Down
16 changes: 8 additions & 8 deletions autokeras/tasks/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -105,7 +105,7 @@ def __init__(
overwrite=overwrite,
seed=seed,
max_model_size=max_model_size,
**kwargs
**kwargs,
)

def fit(
Expand All @@ -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.

Expand Down Expand Up @@ -172,7 +172,7 @@ def fit(
callbacks=callbacks,
validation_split=validation_split,
validation_data=validation_data,
**kwargs
**kwargs,
)
return history

Expand Down Expand Up @@ -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
Expand All @@ -238,7 +238,7 @@ def __init__(
overwrite=overwrite,
seed=seed,
max_model_size=max_model_size,
**kwargs
**kwargs,
)

def fit(
Expand All @@ -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.

Expand Down Expand Up @@ -306,6 +306,6 @@ def fit(
callbacks=callbacks,
validation_split=validation_split,
validation_data=validation_data,
**kwargs
**kwargs,
)
return history
16 changes: 8 additions & 8 deletions autokeras/tasks/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -100,7 +100,7 @@ def __init__(
overwrite=overwrite,
seed=seed,
max_model_size=max_model_size,
**kwargs
**kwargs,
)

def fit(
Expand All @@ -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.

Expand Down Expand Up @@ -167,7 +167,7 @@ def fit(
callbacks=callbacks,
validation_split=validation_split,
validation_data=validation_data,
**kwargs
**kwargs,
)
return history

Expand Down Expand Up @@ -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
Expand All @@ -233,7 +233,7 @@ def __init__(
overwrite=overwrite,
seed=seed,
max_model_size=max_model_size,
**kwargs
**kwargs,
)

def fit(
Expand All @@ -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.

Expand Down Expand Up @@ -300,6 +300,6 @@ def fit(
callbacks=callbacks,
validation_split=validation_split,
validation_data=validation_data,
**kwargs
**kwargs,
)
return history
2 changes: 1 addition & 1 deletion autokeras/tuners/greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions docker/pre-commit.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 4 additions & 4 deletions docker/pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
3 changes: 2 additions & 1 deletion docs/ipynb/text_regression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion docs/py/text_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions docs/tutobooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
Loading