Skip to content

Commit b5fd958

Browse files
authored
[PLT-1506] Added Ruff linting to SDK (#1822)
1 parent 923d43c commit b5fd958

File tree

20 files changed

+52
-45
lines changed

20 files changed

+52
-45
lines changed

libs/labelbox/pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ dev-dependencies = [
7474
[tool.ruff]
7575
line-length = 80
7676

77+
[tool.ruff.lint]
78+
ignore = ["F", "E722"]
79+
exclude = ["**/__init__.py"]
80+
7781
[tool.rye.scripts]
7882
unit = "pytest tests/unit"
7983
# https://github.com/Labelbox/labelbox-python/blob/7c84fdffbc14fd1f69d2a6abdcc0087dc557fa4e/Makefile
@@ -89,9 +93,10 @@ unit = "pytest tests/unit"
8993
# LABELBOX_TEST_BASE_URL="http://host.docker.internal:8080" \
9094
integration = { cmd = "pytest tests/integration" }
9195
data = { cmd = "pytest tests/data" }
96+
rye-lint = "rye lint"
9297
rye-fmt-check = "rye fmt --check"
9398
mypy-lint = "mypy src --pretty --show-error-codes --non-interactive --install-types"
94-
lint = { chain = ["mypy-lint", "rye-fmt-check"] }
99+
lint = { chain = ["rye-fmt-check", "mypy-lint", "rye-lint"] }
95100
test = { chain = ["lint", "unit", "integration"] }
96101

97102
[tool.hatch.metadata]

libs/labelbox/src/labelbox/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def _get_all(self, db_object_type, where, filter_deleted=True):
626626
An iterable of `db_object_type` instances.
627627
"""
628628
if filter_deleted:
629-
not_deleted = db_object_type.deleted == False
629+
not_deleted = db_object_type.deleted == False # noqa: E712 <Gabefire> Needed for bit operator to combine comparisons
630630
where = not_deleted if where is None else where & not_deleted
631631
query_str, params = query.get_all(db_object_type, where)
632632

@@ -2297,11 +2297,11 @@ def delete_feature_schema_from_ontology(
22972297

22982298
if response.status_code == requests.codes.ok:
22992299
response_json = response.json()
2300-
if response_json["archived"] == True:
2300+
if response_json["archived"] is True:
23012301
logger.info(
23022302
"Feature schema was archived from the ontology because it had associated labels."
23032303
)
2304-
elif response_json["deleted"] == True:
2304+
elif response_json["deleted"] is True:
23052305
logger.info(
23062306
"Feature schema was successfully removed from the ontology"
23072307
)

libs/labelbox/src/labelbox/data/annotation_types/data/raster.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def validate_args(self, values):
172172
uid = self.uid
173173
global_key = self.global_key
174174
if (
175-
uid == file_path == im_bytes == url == global_key == None
175+
uid == file_path == im_bytes == url == global_key is None
176176
and arr is None
177177
):
178178
raise ValueError(
@@ -191,7 +191,9 @@ def validate_args(self, values):
191191
return self
192192

193193
def __repr__(self) -> str:
194-
symbol_or_none = lambda data: "..." if data is not None else None
194+
def symbol_or_none(data):
195+
return "..." if data is not None else None
196+
195197
return (
196198
f"{self.__class__.__name__}(im_bytes={symbol_or_none(self.im_bytes)},"
197199
f"file_path={self.file_path},"

libs/labelbox/src/labelbox/data/annotation_types/data/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def validate_date(self, values):
101101
url = self.url
102102
uid = self.uid
103103
global_key = self.global_key
104-
if uid == file_path == text == url == global_key == None:
104+
if uid == file_path == text == url == global_key is None:
105105
raise ValueError(
106106
"One of `file_path`, `text`, `uid`, `global_key` or `url` required."
107107
)

libs/labelbox/src/labelbox/data/annotation_types/data/video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def validate_data(self):
159159
uid = self.uid
160160
global_key = self.global_key
161161

162-
if uid == file_path == frames == url == global_key == None:
162+
if uid == file_path == frames == url == global_key is None:
163163
raise ValueError(
164164
"One of `file_path`, `frames`, `uid`, `global_key` or `url` required."
165165
)

libs/labelbox/src/labelbox/data/annotation_types/video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class MaskFrame(_CamelCaseMixin, BaseModel):
125125
def validate_args(self, values):
126126
im_bytes = self.im_bytes
127127
instance_uri = self.instance_uri
128-
if im_bytes == instance_uri == None:
128+
if im_bytes == instance_uri is None:
129129
raise ValueError("One of `instance_uri`, `im_bytes` required.")
130130
return self
131131

libs/labelbox/src/labelbox/data/metrics/confusion_matrix/calculation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def classification_confusion_matrix(
130130

131131
prediction, ground_truth = predictions[0], ground_truths[0]
132132

133-
if type(prediction) != type(ground_truth):
133+
if type(prediction) is not type(ground_truth):
134134
raise TypeError(
135135
"Classification features must be the same type to compute agreement. "
136136
f"Found `{type(prediction)}` and `{type(ground_truth)}`"

libs/labelbox/src/labelbox/data/metrics/iou/calculation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def classification_miou(
209209

210210
prediction, ground_truth = predictions[0], ground_truths[0]
211211

212-
if type(prediction) != type(ground_truth):
212+
if type(prediction) is not type(ground_truth):
213213
raise TypeError(
214214
"Classification features must be the same type to compute agreement. "
215215
f"Found `{type(prediction)}` and `{type(ground_truth)}`"

libs/labelbox/src/labelbox/orm/db_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _to_many(self, where=None, order_by=None):
177177
)
178178

179179
if rel.filter_deleted:
180-
not_deleted = rel.destination_type.deleted == False
180+
not_deleted = rel.destination_type.deleted == False # noqa: E712 <Gabefire> Needed for bit operator to combine comparisons
181181
where = not_deleted if where is None else where & not_deleted
182182

183183
query_string, params = query.relationship(

libs/labelbox/src/labelbox/schema/data_row_metadata.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -803,13 +803,13 @@ def _convert_metadata_field(metadata_field):
803803
if isinstance(metadata_field, DataRowMetadataField):
804804
return metadata_field
805805
elif isinstance(metadata_field, dict):
806-
if not "value" in metadata_field:
806+
if "value" not in metadata_field:
807807
raise ValueError(
808808
f"Custom metadata field '{metadata_field}' must have a 'value' key"
809809
)
810810
if (
811-
not "schema_id" in metadata_field
812-
and not "name" in metadata_field
811+
"schema_id" not in metadata_field
812+
and "name" not in metadata_field
813813
):
814814
raise ValueError(
815815
f"Custom metadata field '{metadata_field}' must have either 'schema_id' or 'name' key"
@@ -954,9 +954,8 @@ def _validate_custom_schema_by_name(
954954

955955

956956
def _batch_items(iterable: List[Any], size: int) -> Generator[Any, None, None]:
957-
l = len(iterable)
958-
for ndx in range(0, l, size):
959-
yield iterable[ndx : min(ndx + size, l)]
957+
for ndx in range(0, len(iterable), size):
958+
yield iterable[ndx : min(ndx + size, len(iterable))]
960959

961960

962961
def _batch_operations(

0 commit comments

Comments
 (0)