Skip to content

Commit 7f1557b

Browse files
authored
feat: Lint with ruff (#4043)
* feat: Lin with ruff Signed-off-by: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com> * fea: replace black with ruff format options Signed-off-by: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com> * fea: files reformatted due to ruff deviations from black Signed-off-by: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com> * fix: restored mypy in lint-python target Signed-off-by: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com> * fix: fixed formatting error Signed-off-by: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com> * adding ruff format --check Signed-off-by: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com> * Formatting updated files Signed-off-by: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com> * Adding section separator Signed-off-by: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com> --------- Signed-off-by: Daniele Martinoli <86618610+dmartinol@users.noreply.github.com>
1 parent 584e9b1 commit 7f1557b

File tree

65 files changed

+162
-290
lines changed

Some content is hidden

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

65 files changed

+162
-290
lines changed

Makefile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,13 @@ test-python-universal:
294294
python -m pytest -n 8 --integration sdk/python/tests
295295

296296
format-python:
297-
# Sort
298-
cd ${ROOT_DIR}/sdk/python; python -m isort feast/ tests/
299-
300-
# Format
301-
cd ${ROOT_DIR}/sdk/python; python -m black --target-version py38 feast tests
297+
cd ${ROOT_DIR}/sdk/python; python -m ruff check --fix feast/ tests/
298+
cd ${ROOT_DIR}/sdk/python; python -m ruff format feast/ tests/
302299

303300
lint-python:
304301
cd ${ROOT_DIR}/sdk/python; python -m mypy feast
305-
cd ${ROOT_DIR}/sdk/python; python -m isort feast/ tests/ --check-only
306-
cd ${ROOT_DIR}/sdk/python; python -m flake8 feast/ tests/
307-
cd ${ROOT_DIR}/sdk/python; python -m black --check feast tests
308-
302+
cd ${ROOT_DIR}/sdk/python; python -m ruff check feast/ tests/
303+
cd ${ROOT_DIR}/sdk/python; python -m ruff format --check feast/ tests
309304
# Java
310305

311306
install-java-ci-dependencies:

docs/project/development-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ docker build -t docker-whale -f ./sdk/python/feast/infra/feature_servers/multicl
168168
Feast Python SDK / CLI codebase:
169169
- Conforms to [Black code style](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html)
170170
- Has type annotations as enforced by `mypy`
171-
- Has imports sorted by `isort`
172-
- Is lintable by `flake8`
171+
- Has imports sorted by `ruff` (see [isort (I) rules](https://docs.astral.sh/ruff/rules/#isort-i))
172+
- Is lintable by `ruff`
173173

174174
To ensure your Python code conforms to Feast Python code standards:
175175
- Autoformat your code to conform to the code style:

pyproject.toml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,25 @@ build-backend = "setuptools.build_meta"
55
[tool.setuptools_scm]
66
# Including this section is comparable to supplying use_scm_version=True in setup.py.
77

8-
[tool.black]
8+
[tool.ruff]
99
line-length = 88
10-
target-version = ['py39']
11-
include = '\.pyi?$'
12-
exclude = '''
13-
(
14-
/(
15-
\.eggs # exclude a few common directories in the
16-
| \.git # root of the project
17-
| \.hg
18-
| \.mypy_cache
19-
| \.tox
20-
| \.venv
21-
| _build
22-
| buck-out
23-
| build
24-
| dist
25-
| pb2.py
26-
| \.pyi
27-
| protos
28-
| sdk/python/feast/embedded_go/lib
29-
)/
30-
)
31-
'''
10+
target-version = "py39"
11+
include = ["*.py", "*.pyi"]
12+
13+
[tool.ruff.format]
14+
# exclude a few common directories in the root of the project
15+
exclude = [
16+
".eggs",
17+
".git",
18+
".hg",
19+
".mypy_cache",
20+
".tox",
21+
".venv",
22+
"_build",
23+
"buck-out",
24+
"build",
25+
"dist",
26+
"pb2.py",
27+
".pyi",
28+
"protos",
29+
"sdk/python/feast/embedded_go/lib"]

sdk/python/feast/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from importlib.metadata import PackageNotFoundError
33
from importlib.metadata import version as _version
44
except ModuleNotFoundError:
5-
from importlib_metadata import PackageNotFoundError, version as _version # type: ignore
5+
from importlib_metadata import PackageNotFoundError # type: ignore
6+
from importlib_metadata import version as _version
67

78
from feast.infra.offline_stores.bigquery_source import BigQuerySource
89
from feast.infra.offline_stores.contrib.athena_offline_store.athena_source import (

sdk/python/feast/data_source.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ def from_proto(data_source: DataSourceProto):
576576
)
577577

578578
def to_proto(self) -> DataSourceProto:
579-
580579
schema_pb = []
581580

582581
if isinstance(self.schema, Dict):

sdk/python/feast/diff/registry_diff.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ def extract_objects_for_keep_delete_update_add(
216216
objs_to_update = {}
217217
objs_to_add = {}
218218

219-
registry_object_type_to_objects: Dict[
220-
FeastObjectType, List[Any]
221-
] = FeastObjectType.get_objects_from_registry(registry, current_project)
222-
registry_object_type_to_repo_contents: Dict[
223-
FeastObjectType, List[Any]
224-
] = FeastObjectType.get_objects_from_repo_contents(desired_repo_contents)
219+
registry_object_type_to_objects: Dict[FeastObjectType, List[Any]] = (
220+
FeastObjectType.get_objects_from_registry(registry, current_project)
221+
)
222+
registry_object_type_to_repo_contents: Dict[FeastObjectType, List[Any]] = (
223+
FeastObjectType.get_objects_from_repo_contents(desired_repo_contents)
224+
)
225225

226226
for object_type in FEAST_OBJECT_TYPES:
227227
(

sdk/python/feast/dqm/profilers/profiler.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ def validate(self, dataset: pd.DataFrame) -> "ValidationReport":
1515
...
1616

1717
@abc.abstractmethod
18-
def to_proto(self):
19-
...
18+
def to_proto(self): ...
2019

2120
@classmethod
2221
@abc.abstractmethod
23-
def from_proto(cls, proto) -> "Profile":
24-
...
22+
def from_proto(cls, proto) -> "Profile": ...
2523

2624

2725
class Profiler:
@@ -34,13 +32,11 @@ def analyze_dataset(self, dataset: pd.DataFrame) -> Profile:
3432
...
3533

3634
@abc.abstractmethod
37-
def to_proto(self):
38-
...
35+
def to_proto(self): ...
3936

4037
@classmethod
4138
@abc.abstractmethod
42-
def from_proto(cls, proto) -> "Profiler":
43-
...
39+
def from_proto(cls, proto) -> "Profiler": ...
4440

4541

4642
class ValidationReport:

sdk/python/feast/embedded_go/online_features_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def get_online_features(
6565
request_data: Dict[str, Union[List[Any], Value_pb2.RepeatedValue]],
6666
full_feature_names: bool = False,
6767
):
68-
6968
if feature_service:
7069
join_keys_types = self._service.GetEntityTypesMapByFeatureService(
7170
feature_service.name

sdk/python/feast/feature_logging.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ def get_schema(self, registry: "BaseRegistry") -> pa.Schema:
8686
fields[join_key] = FEAST_TYPE_TO_ARROW_TYPE[entity_column.dtype]
8787

8888
for feature in projection.features:
89-
fields[
90-
f"{projection.name_to_use()}__{feature.name}"
91-
] = FEAST_TYPE_TO_ARROW_TYPE[feature.dtype]
92-
fields[
93-
f"{projection.name_to_use()}__{feature.name}__timestamp"
94-
] = PA_TIMESTAMP_TYPE
95-
fields[
96-
f"{projection.name_to_use()}__{feature.name}__status"
97-
] = pa.int32()
89+
fields[f"{projection.name_to_use()}__{feature.name}"] = (
90+
FEAST_TYPE_TO_ARROW_TYPE[feature.dtype]
91+
)
92+
fields[f"{projection.name_to_use()}__{feature.name}__timestamp"] = (
93+
PA_TIMESTAMP_TYPE
94+
)
95+
fields[f"{projection.name_to_use()}__{feature.name}__status"] = (
96+
pa.int32()
97+
)
9898

9999
# system columns
100100
fields[LOG_TIMESTAMP_FIELD] = pa.timestamp("us", tz=UTC)

sdk/python/feast/feature_store.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,8 @@ def apply(
818818
views_to_update = [
819819
ob
820820
for ob in objects
821-
if (
821+
if
822+
(
822823
# BFVs are not handled separately from FVs right now.
823824
(isinstance(ob, FeatureView) or isinstance(ob, BatchFeatureView))
824825
and not isinstance(ob, StreamFeatureView)
@@ -950,7 +951,9 @@ def apply(
950951
validation_references.name, project=self.project, commit=False
951952
)
952953

953-
tables_to_delete: List[FeatureView] = views_to_delete + sfvs_to_delete if not partial else [] # type: ignore
954+
tables_to_delete: List[FeatureView] = (
955+
views_to_delete + sfvs_to_delete if not partial else [] # type: ignore
956+
)
954957
tables_to_keep: List[FeatureView] = views_to_update + sfvs_to_update # type: ignore
955958

956959
self._get_provider().update_infra(
@@ -1575,7 +1578,10 @@ def _get_online_features(
15751578

15761579
num_rows = _validate_entity_values(entity_proto_values)
15771580
_validate_feature_refs(_feature_refs, full_feature_names)
1578-
(grouped_refs, grouped_odfv_refs,) = _group_feature_refs(
1581+
(
1582+
grouped_refs,
1583+
grouped_odfv_refs,
1584+
) = _group_feature_refs(
15791585
_feature_refs,
15801586
requested_feature_views,
15811587
requested_on_demand_feature_views,
@@ -1728,9 +1734,9 @@ def _get_entity_maps(
17281734
)
17291735
entity_name_to_join_key_map[entity_name] = join_key
17301736
for entity_column in feature_view.entity_columns:
1731-
entity_type_map[
1732-
entity_column.name
1733-
] = entity_column.dtype.to_value_type()
1737+
entity_type_map[entity_column.name] = (
1738+
entity_column.dtype.to_value_type()
1739+
)
17341740

17351741
return (
17361742
entity_name_to_join_key_map,
@@ -2005,11 +2011,11 @@ def _augment_response_with_on_demand_transforms(
20052011
if odfv.mode == "python":
20062012
if initial_response_dict is None:
20072013
initial_response_dict = initial_response.to_dict()
2008-
transformed_features_dict: Dict[
2009-
str, List[Any]
2010-
] = odfv.get_transformed_features(
2011-
initial_response_dict,
2012-
full_feature_names,
2014+
transformed_features_dict: Dict[str, List[Any]] = (
2015+
odfv.get_transformed_features(
2016+
initial_response_dict,
2017+
full_feature_names,
2018+
)
20132019
)
20142020
elif odfv.mode in {"pandas", "substrait"}:
20152021
if initial_response_df is None:

0 commit comments

Comments
 (0)