Skip to content

[PLT-1506] Added Ruff linting to SDK #1822

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

Merged
merged 18 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 2 additions & 2 deletions .github/workflows/lbox-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: LBox Develop

on:
push:
branches: [develop]
branches: [develop, v6]
pull_request:
branches: [develop]
branches: [develop, v6]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-package-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Labelbox Python SDK Staging (Develop)

on:
push:
branches: [develop]
branches: [develop, v6]
pull_request:
branches: [develop]
branches: [develop, v6]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
7 changes: 6 additions & 1 deletion libs/labelbox/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ dev-dependencies = [
[tool.ruff]
line-length = 80

[tool.ruff.lint]
ignore = ["F", "E722"]
Copy link
Collaborator Author

@Gabefire Gabefire Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have PyFlake and a bareexcept rule ignored here. Later we should look at not ignoring these rules and possiblly include more then just the defaults.

exclude = ["**/__init__.py"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be excluded for future rules (no unused imports)


[tool.rye.scripts]
unit = "pytest tests/unit"
# https://github.com/Labelbox/labelbox-python/blob/7c84fdffbc14fd1f69d2a6abdcc0087dc557fa4e/Makefile
Expand All @@ -89,9 +93,10 @@ unit = "pytest tests/unit"
# LABELBOX_TEST_BASE_URL="http://host.docker.internal:8080" \
integration = { cmd = "pytest tests/integration" }
data = { cmd = "pytest tests/data" }
rye-lint = "rye lint"
rye-fmt-check = "rye fmt --check"
mypy-lint = "mypy src --pretty --show-error-codes --non-interactive --install-types"
lint = { chain = ["mypy-lint", "rye-fmt-check"] }
lint = { chain = ["rye-fmt-check", "mypy-lint", "rye-lint"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need mypy here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I think so Mypy is a type checker

test = { chain = ["lint", "unit", "integration"] }

[tool.hatch.metadata]
Expand Down
6 changes: 3 additions & 3 deletions libs/labelbox/src/labelbox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def _get_all(self, db_object_type, where, filter_deleted=True):
An iterable of `db_object_type` instances.
"""
if filter_deleted:
not_deleted = db_object_type.deleted == False
not_deleted = db_object_type.deleted is False
where = not_deleted if where is None else where & not_deleted
query_str, params = query.get_all(db_object_type, where)

Expand Down Expand Up @@ -2297,11 +2297,11 @@ def delete_feature_schema_from_ontology(

if response.status_code == requests.codes.ok:
response_json = response.json()
if response_json["archived"] == True:
if response_json["archived"] is True:
logger.info(
"Feature schema was archived from the ontology because it had associated labels."
)
elif response_json["deleted"] == True:
elif response_json["deleted"] is True:
logger.info(
"Feature schema was successfully removed from the ontology"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def validate_args(self, values):
uid = self.uid
global_key = self.global_key
if (
uid == file_path == im_bytes == url == global_key == None
uid == file_path == im_bytes == url == global_key is None
and arr is None
):
raise ValueError(
Expand All @@ -191,7 +191,9 @@ def validate_args(self, values):
return self

def __repr__(self) -> str:
symbol_or_none = lambda data: "..." if data is not None else None
def symbol_or_none(data):
return "..." if data is not None else None

return (
f"{self.__class__.__name__}(im_bytes={symbol_or_none(self.im_bytes)},"
f"file_path={self.file_path},"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def validate_date(self, values):
url = self.url
uid = self.uid
global_key = self.global_key
if uid == file_path == text == url == global_key == None:
if uid == file_path == text == url == global_key is None:
raise ValueError(
"One of `file_path`, `text`, `uid`, `global_key` or `url` required."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def validate_data(self):
uid = self.uid
global_key = self.global_key

if uid == file_path == frames == url == global_key == None:
if uid == file_path == frames == url == global_key is None:
raise ValueError(
"One of `file_path`, `frames`, `uid`, `global_key` or `url` required."
)
Expand Down
2 changes: 1 addition & 1 deletion libs/labelbox/src/labelbox/data/annotation_types/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class MaskFrame(_CamelCaseMixin, BaseModel):
def validate_args(self, values):
im_bytes = self.im_bytes
instance_uri = self.instance_uri
if im_bytes == instance_uri == None:
if im_bytes == instance_uri is None:
raise ValueError("One of `instance_uri`, `im_bytes` required.")
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def classification_confusion_matrix(

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

if type(prediction) != type(ground_truth):
if type(prediction) is not type(ground_truth):
raise TypeError(
"Classification features must be the same type to compute agreement. "
f"Found `{type(prediction)}` and `{type(ground_truth)}`"
Expand Down
2 changes: 1 addition & 1 deletion libs/labelbox/src/labelbox/data/metrics/iou/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def classification_miou(

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

if type(prediction) != type(ground_truth):
if type(prediction) is not type(ground_truth):
raise TypeError(
"Classification features must be the same type to compute agreement. "
f"Found `{type(prediction)}` and `{type(ground_truth)}`"
Expand Down
1 change: 0 additions & 1 deletion libs/labelbox/src/labelbox/data/serialization/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .ndjson import NDJsonConverter
from .coco import COCOConverter

This file was deleted.

78 changes: 0 additions & 78 deletions libs/labelbox/src/labelbox/data/serialization/coco/annotation.py

This file was deleted.

17 changes: 0 additions & 17 deletions libs/labelbox/src/labelbox/data/serialization/coco/categories.py

This file was deleted.

Loading
Loading