Skip to content

Commit be22d86

Browse files
Use ruff inplace of black, isort, flake8, and autoflake8. (#1321)
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com> Signed-off-by: Kevin Su <pingsutw@apache.org> Co-authored-by: Kevin Su <pingsutw@apache.org>
1 parent 83c7a59 commit be22d86

File tree

34 files changed

+97
-98
lines changed

34 files changed

+97
-98
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
repos:
2-
- repo: https://github.com/PyCQA/flake8
3-
rev: 3.9.2
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.1.6
45
hooks:
5-
- id: flake8
6-
- repo: https://github.com/psf/black
7-
rev: 22.3.0
8-
hooks:
9-
- id: black
10-
- repo: https://github.com/PyCQA/isort
11-
rev: 5.12.0
12-
hooks:
13-
- id: isort
6+
# Run the linter.
7+
- id: ruff
8+
args: [--fix]
9+
# Run the formatter.
10+
- id: ruff-format
1411
- repo: https://github.com/pre-commit/pre-commit-hooks
1512
rev: v4.0.1
1613
hooks:

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ docs-requirements.txt: docs-requirements.in install-piptools
2424
docs-requirements: docs-requirements.txt
2525

2626
.PHONY: fmt
27-
fmt: ## Format code with black and isort
28-
autoflake --remove-all-unused-imports --ignore-init-module-imports --ignore-pass-after-docstring --in-place -r examples
29-
pre-commit run black --all-files || true
30-
pre-commit run isort --all-files || true
27+
fmt: ## Format code with ruff
28+
pre-commit run ruff --all-files || true
29+
pre-commit run ruff-format --all-files || true
3130

3231
.PHONY: update_boilerplate
3332
update_boilerplate:

dev-requirements.in

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
autoflake
22
flytekit
3-
black
43
coverage
5-
flake8
64
pre-commit
7-
flake8-black
8-
flake8-isort
95
codespell
10-
isort
116
mock
127
pytest
138
mypy

dev-requirements.txt

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ azure-storage-blob==12.19.0
3939
# via adlfs
4040
binaryornot==0.4.4
4141
# via cookiecutter
42-
black==24.3.0
43-
# via
44-
# -r dev-requirements.in
45-
# flake8-black
4642
botocore==1.31.17
4743
# via aiobotocore
4844
cachetools==5.3.2
@@ -63,7 +59,6 @@ charset-normalizer==3.3.2
6359
# via requests
6460
click==8.1.7
6561
# via
66-
# black
6762
# cookiecutter
6863
# flytekit
6964
# rich-click
@@ -100,15 +95,6 @@ exceptiongroup==1.2.0
10095
# via pytest
10196
filelock==3.13.1
10297
# via virtualenv
103-
flake8==6.1.0
104-
# via
105-
# -r dev-requirements.in
106-
# flake8-black
107-
# flake8-isort
108-
flake8-black==0.3.6
109-
# via -r dev-requirements.in
110-
flake8-isort==6.1.1
111-
# via -r dev-requirements.in
11298
flyteidl==1.10.6
11399
# via flytekit
114100
flytekit==1.10.2
@@ -118,7 +104,6 @@ frozenlist==1.4.0
118104
# aiohttp
119105
# aiosignal
120106
fsspec==2023.9.2
121-
# via
122107
# adlfs
123108
# flytekit
124109
# gcsfs
@@ -175,10 +160,6 @@ iniconfig==2.0.0
175160
# via pytest
176161
isodate==0.6.1
177162
# via azure-storage-blob
178-
isort==5.12.0
179-
# via
180-
# -r dev-requirements.in
181-
# flake8-isort
182163
jaraco-classes==3.3.0
183164
# via keyring
184165
jeepney==0.8.0
@@ -216,8 +197,6 @@ mashumaro==3.11
216197
# via
217198
# -r dev-requirements.in
218199
# flytekit
219-
mccabe==0.7.0
220-
# via flake8
221200
mdurl==0.1.2
222201
# via markdown-it-py
223202
mock==5.1.0
@@ -239,7 +218,6 @@ mypy==1.7.1
239218
# via -r dev-requirements.in
240219
mypy-extensions==1.0.0
241220
# via
242-
# black
243221
# mypy
244222
# typing-inspect
245223
nodeenv==1.8.0
@@ -255,17 +233,13 @@ oauthlib==3.2.2
255233
# requests-oauthlib
256234
packaging==23.2
257235
# via
258-
# black
259236
# docker
260237
# marshmallow
261238
# pytest
262239
pandas==1.5.3
263240
# via flytekit
264-
pathspec==0.11.2
265-
# via black
266241
platformdirs==4.1.0
267242
# via
268-
# black
269243
# virtualenv
270244
pluggy==1.3.0
271245
# via pytest
@@ -291,14 +265,8 @@ pyasn1==0.5.1
291265
# rsa
292266
pyasn1-modules==0.3.0
293267
# via google-auth
294-
pycodestyle==2.11.1
295-
# via flake8
296268
pycparser==2.21
297269
# via cffi
298-
pyflakes==3.1.0
299-
# via
300-
# autoflake
301-
# flake8
302270
pygments==2.17.2
303271
# via rich
304272
pyjwt[crypto]==2.8.0

docs/contribute.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,15 @@ if the code in itself is updated and requirements.txt is the same.
284284
## Pre-commit hooks
285285

286286
We use [pre-commit](https://pre-commit.com/) to automate linting and code formatting on every commit.
287-
Configured hooks include [black](https://github.com/psf/black), [isort](https://github.com/PyCQA/isort),
288-
[flake8](https://github.com/PyCQA/flake8) and linters to ensure newlines are added to the end of files, and there is
289-
proper spacing in files.
287+
Configured hooks include [ruff](https://github.com/astral-sh/ruff) to ensure newlines are added to the end of files, and there is proper spacing in files.
290288

291289
We run all those hooks in CI, but if you want to run them locally on every commit, run `pre-commit install` after
292290
installing the dev environment requirements. In case you want to disable `pre-commit` hooks locally, run
293291
`pre-commit uninstall`. More info [here](https://pre-commit.com/).
294292

295293
### Formatting
296294

297-
We use [black](https://github.com/psf/black) and [isort](https://github.com/PyCQA/isort) to autoformat code. They
295+
We use [ruff](https://github.com/astral-sh/ruff) to autoformat code. They
298296
are configured as git hooks in `pre-commit`. Run `make fmt` to format your code.
299297

300298
### Spell-checking

examples/dbt_plugin/dbt_plugin/dbt_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
DBT_PROFILES_DIR = "dbt-profiles"
2929
DBT_PROFILE = "jaffle_shop"
3030

31+
3132
# %% [markdown]
3233
# This task ensures that the jaffle_shop database is created and it also contains
3334
# some data before scheduling an execution of this workflow.

examples/development_lifecycle/development_lifecycle/task_cache.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def hash_pandas_dataframe(df: pandas.DataFrame) -> str:
6767

6868
@task
6969
def foo_1( # noqa: F811
70-
a: int, b: str # noqa: F821
70+
a: int,
71+
b: str, # noqa: F821
7172
) -> Annotated[pandas.DataFrame, HashMethod(hash_pandas_dataframe)]: # noqa: F821 # noqa: F821
7273
df = pandas.DataFrame(...) # noqa: F821
7374
...

examples/dolt_plugin/dolt_plugin/dolt_branch_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def generate_confs(a: int) -> typing.Tuple[DoltConfig, DoltConfig, DoltConfig]:
7171
# Return types of `DoltTable` save the `data` to the
7272
# Dolt database given a connection configuration.
7373

74+
7475
# %%
7576
@task
7677
def get_confs(a: int) -> typing.Tuple[DoltConfig, DoltTable, DoltConfig]:

examples/dolt_plugin/dolt_plugin/dolt_quickstart_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# %% [markdown]
3232
# We define a task to create a DataFrame and store the table in Dolt.
3333

34+
3435
# %%
3536
@task
3637
def populate_rabbits(a: int) -> DoltTable:

examples/duckdb_plugin/duckdb_plugin/duckdb_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def params_wf(
153153
[["chainsaw", 500, 10], ["iphone", 300, 2]],
154154
["duck", "goose"],
155155
]
156-
)
156+
),
157157
) -> pd.DataFrame:
158158
return read_df(df=duckdb_params_query(params=params))
159159

examples/exploratory_data_analysis/exploratory_data_analysis/notebook.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
# %% [markdown]
5151
# Since a task need not be defined, we create a `workflow` and return the MAE score.
5252

53+
5354
# %%
5455
@workflow
5556
def notebook_wf(

examples/exploratory_data_analysis/exploratory_data_analysis/notebook_and_task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Hyperparameters(object):
5656
# Next, we define a `cross_validate` function and a `modeling` task to compute the MAE score of the data against
5757
# the Gradient Boosting Regressor.
5858

59+
5960
# %%
6061
def cross_validate(model, nfolds, feats, targets):
6162
score = -1 * (cross_val_score(model, feats, targets, cv=nfolds, scoring="neg_mean_absolute_error"))

examples/exploratory_data_analysis/exploratory_data_analysis/notebooks_as_tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
# %% [markdown]
6161
# We define a `Workflow` to run the notebook tasks.
6262

63+
6364
# %%
6465
@workflow
6566
def notebook_wf(

examples/feast_integration/feast_integration/feature_eng_tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"timestamp",
2626
]
2727

28+
2829
# %% [markdown]
2930
# Use the [SimpleImputer](https://scikit-learn.org/stable/modules/generated/sklearn.impute.SimpleImputer.html) class from the `scikit-learn` library
3031
# to fill in the missing values of the dataset.

examples/flyteinteractive_plugin/flyteinteractive_plugin/vscode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# ## Usage
1313
# ### Add `@vscode` decorator to task function definition
1414

15+
1516
# %%
1617
@task
1718
@vscode

examples/forecasting_sales/forecasting_sales/keras_spark_rossmann_estimator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
# %% [markdown]
9494
# Next, let's initialize a data class to store the hyperparameters that will be used with the model (`epochs`, `learning_rate`, `batch_size`, etc.).
9595

96+
9697
# %%
9798
@dataclass_json
9899
@dataclass
@@ -600,7 +601,6 @@ def test(
600601
test_df: pyspark.sql.DataFrame,
601602
hp: Hyperparameters,
602603
) -> FlyteDirectory:
603-
604604
print("================")
605605
print("Final prediction")
606606
print("================")
@@ -649,7 +649,6 @@ def test(
649649
limits=Resources(mem="1Gi"),
650650
)
651651
def horovod_spark_task(data_dir: FlyteDirectory, hp: Hyperparameters, work_dir: FlyteDirectory) -> FlyteDirectory:
652-
653652
max_sales, vocab, train_df, test_df = data_preparation(data_dir, hp)
654653

655654
# working directory will have the model and predictions as separate files

examples/greatexpectations_plugin/greatexpectations_plugin/task_example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
context_root_dir=CONTEXT_ROOT_DIR,
5555
)
5656

57+
5758
# %% [markdown]
5859
# Next, we define a task that validates the data before returning the shape of the DataFrame.
5960
# %%
@@ -97,6 +98,7 @@ def simple_wf(dataset: str = DATASET_LOCAL) -> int:
9798
context_root_dir=CONTEXT_ROOT_DIR,
9899
)
99100

101+
100102
# %% [markdown]
101103
# Next, we define a task that calls the validation logic.
102104
# %%
@@ -144,6 +146,7 @@ def file_wf(
144146
task_config=SQLite3Config(uri=SQLITE_DATASET),
145147
)
146148

149+
147150
# %% [markdown]
148151
# Next, we define a task that validates the data and returns the columns in it.
149152
# %%

examples/greatexpectations_plugin/greatexpectations_plugin/type_example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#
4848
# The parameters within the `data_connector_query` convey that we're fetching all those files that have "2019" and "01" in the file names.
4949

50+
5051
# %%
5152
@task(limits=Resources(mem="500Mi"))
5253
def simple_task(
@@ -67,7 +68,7 @@ def simple_task(
6768
),
6869
context_root_dir=CONTEXT_ROOT_DIR,
6970
),
70-
]
71+
],
7172
) -> str:
7273
return f"Validation works for {directory}!"
7374

@@ -102,6 +103,7 @@ def simple_wf(directory: str = "my_assets") -> str:
102103
# The first value that's being sent within `GreatExpectationsType` is `CSVFile` (this is a pre-formatted FlyteFile type).
103104
# This means that we want to validate the `FlyteFile` data.
104105

106+
105107
# %%
106108
@task(limits=Resources(mem="500Mi"))
107109
def file_task(dataset: GreatExpectationsType[CSVFile, great_expectations_config]) -> pd.DataFrame:
@@ -137,7 +139,7 @@ def schema_task(
137139
local_file_path="/tmp/test.parquet", # noqa: F722
138140
context_root_dir=CONTEXT_ROOT_DIR,
139141
),
140-
]
142+
],
141143
) -> int:
142144
return dataframe.shape[0]
143145

examples/hive_plugin/hive_plugin/hive.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def no_io_wf():
6767
# There is a helper task that will automatically do the wrapping above. Please be patient as we fill out these docs.
6868
# :::
6969

70+
7071
# %%
7172
@workflow
7273
def with_output_wf() -> FlyteSchema:

examples/house_price_prediction/house_price_prediction/house_price_predictor.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#
6969
# We define a function to compute the price of a house based on multiple factors (`number of bedrooms`, `number of bathrooms`, `area`, `garage space`, and `year built`).
7070

71+
7172
# %%
7273
def gen_price(house) -> int:
7374
_base_price = int(house["SQUARE_FEET"] * 150)
@@ -125,7 +126,6 @@ def gen_houses(num_houses) -> pd.DataFrame:
125126
def split_data(
126127
df: pd.DataFrame, seed: int, split: typing.List[float]
127128
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
128-
129129
seed = seed
130130
val_size = split[1] # 0.3
131131
test_size = split[2] # 0.1
@@ -182,6 +182,7 @@ def split_data(
182182
# %% [markdown]
183183
# We define a task to call the aforementioned functions.
184184

185+
185186
# %%
186187
@task(cache=True, cache_version="0.1", limits=Resources(mem="600Mi"))
187188
def generate_and_split_data(number_of_houses: int, seed: int) -> dataset:
@@ -196,7 +197,6 @@ def generate_and_split_data(number_of_houses: int, seed: int) -> dataset:
196197
# %%
197198
@task(cache_version="1.0", cache=True, limits=Resources(mem="600Mi"))
198199
def fit(loc: str, train: pd.DataFrame, val: pd.DataFrame) -> JoblibSerializedFile:
199-
200200
# fetch the features and target columns from the train dataset
201201
x = train[train.columns[1:]]
202202
y = train[train.columns[0]]
@@ -227,7 +227,6 @@ def predict(
227227
test: pd.DataFrame,
228228
model_ser: JoblibSerializedFile,
229229
) -> typing.List[float]:
230-
231230
# load the model
232231
model = joblib.load(model_ser)
233232

@@ -246,7 +245,6 @@ def predict(
246245
# %%
247246
@workflow
248247
def house_price_predictor_trainer(seed: int = 7, number_of_houses: int = NUM_HOUSES_PER_LOCATION) -> typing.List[float]:
249-
250248
# generate the data and split it into train test, and validation data
251249
split_data_vals = generate_and_split_data(number_of_houses=number_of_houses, seed=seed)
252250

0 commit comments

Comments
 (0)