Skip to content

Commit 4250004

Browse files
authored
[PLT-1495] Migrated sdk to use Ruff for formattor (#1806)
1 parent 0e9f43f commit 4250004

File tree

266 files changed

+16490
-12688
lines changed

Some content is hidden

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

266 files changed

+16490
-12688
lines changed

.github/workflows/python-package-develop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,4 @@ jobs:
177177
linux/arm64
178178
179179
tags: |
180-
${{ env.CONTAINER_IMAGE }}:${{ github.sha }}
180+
${{ env.CONTAINER_IMAGE }}:${{ github.sha }}

libs/labelbox/pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@ build-backend = "hatchling.build"
6464
[tool.rye]
6565
managed = true
6666
dev-dependencies = [
67-
"yapf>=0.40.2",
6867
"mypy>=1.9.0",
6968
"types-pillow>=10.2.0.20240311",
7069
"types-python-dateutil>=2.9.0.20240316",
7170
"types-requests>=2.31.0.20240311",
7271
"types-tqdm>=4.66.0.20240106",
7372
]
7473

74+
[tool.ruff]
75+
line-length = 80
76+
7577
[tool.rye.scripts]
7678
unit = "pytest tests/unit"
7779
# https://github.com/Labelbox/labelbox-python/blob/7c84fdffbc14fd1f69d2a6abdcc0087dc557fa4e/Makefile
@@ -87,9 +89,9 @@ unit = "pytest tests/unit"
8789
# LABELBOX_TEST_BASE_URL="http://host.docker.internal:8080" \
8890
integration = { cmd = "pytest tests/integration" }
8991
data = { cmd = "pytest tests/data" }
90-
yapf-lint = "yapf tests src -i --verbose --recursive --parallel --style \"google\""
92+
rye-fmt-check = "rye fmt --check"
9193
mypy-lint = "mypy src --pretty --show-error-codes --non-interactive --install-types"
92-
lint = { chain = ["yapf-lint", "mypy-lint"] }
94+
lint = { chain = ["mypy-lint", "rye-fmt-check"] }
9395
test = { chain = ["lint", "unit", "integration"] }
9496

9597
[tool.hatch.metadata]

libs/labelbox/src/labelbox/__init__.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
from labelbox.schema.model import Model
88
from labelbox.schema.model_config import ModelConfig
99
from labelbox.schema.bulk_import_request import BulkImportRequest
10-
from labelbox.schema.annotation_import import MALPredictionImport, MEAPredictionImport, LabelImport, MEAToMALPredictionImport
10+
from labelbox.schema.annotation_import import (
11+
MALPredictionImport,
12+
MEAPredictionImport,
13+
LabelImport,
14+
MEAToMALPredictionImport,
15+
)
1116
from labelbox.schema.dataset import Dataset
1217
from labelbox.schema.data_row import DataRow
1318
from labelbox.schema.catalog import Catalog
@@ -18,16 +23,39 @@
1823
from labelbox.schema.user import User
1924
from labelbox.schema.organization import Organization
2025
from labelbox.schema.task import Task
21-
from labelbox.schema.export_task import StreamType, ExportTask, JsonConverter, JsonConverterOutput, FileConverter, FileConverterOutput, BufferedJsonConverterOutput
22-
from labelbox.schema.labeling_frontend import LabelingFrontend, LabelingFrontendOptions
26+
from labelbox.schema.export_task import (
27+
StreamType,
28+
ExportTask,
29+
JsonConverter,
30+
JsonConverterOutput,
31+
FileConverter,
32+
FileConverterOutput,
33+
BufferedJsonConverterOutput,
34+
)
35+
from labelbox.schema.labeling_frontend import (
36+
LabelingFrontend,
37+
LabelingFrontendOptions,
38+
)
2339
from labelbox.schema.asset_attachment import AssetAttachment
2440
from labelbox.schema.webhook import Webhook
25-
from labelbox.schema.ontology import Ontology, OntologyBuilder, Classification, Option, Tool, FeatureSchema
41+
from labelbox.schema.ontology import (
42+
Ontology,
43+
OntologyBuilder,
44+
Classification,
45+
Option,
46+
Tool,
47+
FeatureSchema,
48+
)
2649
from labelbox.schema.ontology import PromptResponseClassification
2750
from labelbox.schema.ontology import ResponseOption
2851
from labelbox.schema.role import Role, ProjectRole
2952
from labelbox.schema.invite import Invite, InviteLimit
30-
from labelbox.schema.data_row_metadata import DataRowMetadataOntology, DataRowMetadataField, DataRowMetadata, DeleteDataRowMetadata
53+
from labelbox.schema.data_row_metadata import (
54+
DataRowMetadataOntology,
55+
DataRowMetadataField,
56+
DataRowMetadata,
57+
DeleteDataRowMetadata,
58+
)
3159
from labelbox.schema.model_run import ModelRun, DataSplit
3260
from labelbox.schema.benchmark import Benchmark
3361
from labelbox.schema.iam_integration import IAMIntegration
@@ -42,7 +70,10 @@
4270
from labelbox.schema.identifiables import UniqueIds, GlobalKeys, DataRowIds
4371
from labelbox.schema.identifiable import UniqueId, GlobalKey
4472
from labelbox.schema.ontology_kind import OntologyKind
45-
from labelbox.schema.project_overview import ProjectOverview, ProjectOverviewDetailed
73+
from labelbox.schema.project_overview import (
74+
ProjectOverview,
75+
ProjectOverviewDetailed,
76+
)
4677
from labelbox.schema.labeling_service import LabelingService
4778
from labelbox.schema.labeling_service_dashboard import LabelingServiceDashboard
4879
from labelbox.schema.labeling_service_status import LabelingServiceStatus

libs/labelbox/src/labelbox/adv_client.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
class AdvClient:
15-
1615
def __init__(self, endpoint: str, api_key: str):
1716
self.endpoint = endpoint
1817
self.api_key = api_key
@@ -32,47 +31,52 @@ def get_embeddings(self) -> List[Dict[str, Any]]:
3231
return self._request("GET", "/adv/v1/embeddings").get("results", [])
3332

3433
def import_vectors_from_file(self, id: str, file_path: str, callback=None):
35-
self._send_ndjson(f"/adv/v1/embeddings/{id}/_import_ndjson", file_path,
36-
callback)
34+
self._send_ndjson(
35+
f"/adv/v1/embeddings/{id}/_import_ndjson", file_path, callback
36+
)
3737

3838
def get_imported_vector_count(self, id: str) -> int:
3939
data = self._request("GET", f"/adv/v1/embeddings/{id}/vectors/_count")
4040
return data.get("count", 0)
4141

4242
def _create_session(self) -> Session:
4343
session = requests.session()
44-
session.headers.update({
45-
"Authorization": f"Bearer {self.api_key}",
46-
"Content-Type": "application/json"
47-
})
44+
session.headers.update(
45+
{
46+
"Authorization": f"Bearer {self.api_key}",
47+
"Content-Type": "application/json",
48+
}
49+
)
4850
return session
4951

50-
def _request(self,
51-
method: str,
52-
path: str,
53-
data: Optional[Dict[str, Any]] = None,
54-
headers: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
52+
def _request(
53+
self,
54+
method: str,
55+
path: str,
56+
data: Optional[Dict[str, Any]] = None,
57+
headers: Optional[Dict[str, Any]] = None,
58+
) -> Dict[str, Any]:
5559
url = f"{self.endpoint}{path}"
5660
requests_data = None
5761
if data:
5862
requests_data = json.dumps(data)
59-
response = self.session.request(method,
60-
url,
61-
data=requests_data,
62-
headers=headers)
63+
response = self.session.request(
64+
method, url, data=requests_data, headers=headers
65+
)
6366
if response.status_code != requests.codes.ok:
64-
message = response.json().get('message')
67+
message = response.json().get("message")
6568
if message:
6669
raise LabelboxError(message)
6770
else:
6871
response.raise_for_status()
6972
return response.json()
7073

71-
def _send_ndjson(self,
72-
path: str,
73-
file_path: str,
74-
callback: Optional[Callable[[Dict[str, Any]],
75-
None]] = None):
74+
def _send_ndjson(
75+
self,
76+
path: str,
77+
file_path: str,
78+
callback: Optional[Callable[[Dict[str, Any]], None]] = None,
79+
):
7680
"""
7781
Sends an NDJson file in chunks.
7882
@@ -87,7 +91,7 @@ def upload_chunk(_buffer, _count):
8791
_headers = {
8892
"Content-Type": "application/x-ndjson",
8993
"X-Content-Lines": str(_count),
90-
"Content-Length": str(buffer.tell())
94+
"Content-Length": str(buffer.tell()),
9195
}
9296
rsp = self._send_bytes(f"{self.endpoint}{path}", _buffer, _headers)
9397
rsp.raise_for_status()
@@ -96,7 +100,7 @@ def upload_chunk(_buffer, _count):
96100

97101
buffer = io.BytesIO()
98102
count = 0
99-
with open(file_path, 'rb') as fp:
103+
with open(file_path, "rb") as fp:
100104
for line in fp:
101105
buffer.write(line)
102106
count += 1
@@ -107,10 +111,12 @@ def upload_chunk(_buffer, _count):
107111
if count:
108112
upload_chunk(buffer, count)
109113

110-
def _send_bytes(self,
111-
url: str,
112-
buffer: io.BytesIO,
113-
headers: Optional[Dict[str, Any]] = None) -> Response:
114+
def _send_bytes(
115+
self,
116+
url: str,
117+
buffer: io.BytesIO,
118+
headers: Optional[Dict[str, Any]] = None,
119+
) -> Response:
114120
buffer.seek(0)
115121
return self.session.put(url, headers=headers, data=buffer)
116122

0 commit comments

Comments
 (0)