Skip to content

Commit 6a1a778

Browse files
committed
lint
1 parent f7eedc0 commit 6a1a778

12 files changed

+331
-234
lines changed

libs/labelbox/src/labelbox/alignerr/alignerr_project.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55

66
from labelbox.alignerr.schema.project_rate import ProjectRateV2
77
from labelbox.alignerr.schema.project_domain import ProjectDomain
8-
from labelbox.alignerr.schema.enchanced_resource_tags import EnhancedResourceTag, ResourceTagType
9-
from labelbox.alignerr.schema.project_boost_workforce import ProjectBoostWorkforce
8+
from labelbox.alignerr.schema.enchanced_resource_tags import (
9+
EnhancedResourceTag,
10+
ResourceTagType,
11+
)
12+
from labelbox.alignerr.schema.project_boost_workforce import (
13+
ProjectBoostWorkforce,
14+
)
1015
from labelbox.pagination import PaginatedCollection
1116

1217
logger = logging.getLogger(__name__)
@@ -73,17 +78,19 @@ def set_tags(self, tag_names: list[str], tag_type: ResourceTagType):
7378
tag_ids = []
7479
for tag_name in tag_names:
7580
# Search for the tag by text to get its ID
76-
found_tags = EnhancedResourceTag.search_by_text(self.client, search_text=tag_name, tag_type=tag_type)
81+
found_tags = EnhancedResourceTag.search_by_text(
82+
self.client, search_text=tag_name, tag_type=tag_type
83+
)
7784
if found_tags:
7885
tag_ids.append(found_tags[0].id)
79-
86+
8087
# Use the existing project resource tag functionality with IDs
8188
self.project.update_project_resource_tags(tag_ids)
8289
return self
8390

8491
def get_tags(self) -> list[EnhancedResourceTag]:
8592
"""Get enhanced resource tags associated with this project.
86-
93+
8794
Returns:
8895
List of EnhancedResourceTag instances
8996
"""
@@ -94,7 +101,9 @@ def get_tags(self) -> list[EnhancedResourceTag]:
94101
# Search for the corresponding EnhancedResourceTag by text (try different types)
95102
found_tags = []
96103
for tag_type in [ResourceTagType.Default, ResourceTagType.Billing]:
97-
found_tags = EnhancedResourceTag.search_by_text(self.client, search_text=tag.text, tag_type=tag_type)
104+
found_tags = EnhancedResourceTag.search_by_text(
105+
self.client, search_text=tag.text, tag_type=tag_type
106+
)
98107
if found_tags:
99108
break
100109
if found_tags:
@@ -103,28 +112,28 @@ def get_tags(self) -> list[EnhancedResourceTag]:
103112

104113
def add_tag(self, tag: EnhancedResourceTag):
105114
"""Add a single enhanced resource tag to the project.
106-
115+
107116
Args:
108117
tag: EnhancedResourceTag instance to add
109-
118+
110119
Returns:
111120
Self for method chaining
112121
"""
113122
current_tags = self.get_tags()
114123
current_tag_names = [t.text for t in current_tags]
115-
124+
116125
if tag.text not in current_tag_names:
117126
current_tag_names.append(tag.text)
118127
self.set_tags(current_tag_names)
119-
128+
120129
return self
121130

122131
def remove_tag(self, tag: EnhancedResourceTag):
123132
"""Remove a single enhanced resource tag from the project.
124-
133+
125134
Args:
126135
tag: EnhancedResourceTag instance to remove
127-
136+
128137
Returns:
129138
Self for method chaining
130139
"""
@@ -135,13 +144,12 @@ def remove_tag(self, tag: EnhancedResourceTag):
135144

136145
def get_project_owner(self) -> Optional[ProjectBoostWorkforce]:
137146
"""Get the ProjectBoostWorkforce for this project.
138-
147+
139148
Returns:
140149
ProjectBoostWorkforce instance or None if not found
141150
"""
142151
return ProjectBoostWorkforce.get_by_project_id(
143-
client=self.client,
144-
project_id=self.project.uid
152+
client=self.client, project_id=self.project.uid
145153
)
146154

147155

libs/labelbox/src/labelbox/alignerr/alignerr_project_builder.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
from labelbox.alignerr.schema.project_rate import BillingMode
77
from labelbox.alignerr.schema.project_rate import ProjectRateInput
88
from labelbox.alignerr.schema.project_domain import ProjectDomain
9-
from labelbox.alignerr.schema.enchanced_resource_tags import EnhancedResourceTag, ResourceTagType
10-
from labelbox.alignerr.schema.project_boost_workforce import ProjectBoostWorkforce
9+
from labelbox.alignerr.schema.enchanced_resource_tags import (
10+
EnhancedResourceTag,
11+
ResourceTagType,
12+
)
13+
from labelbox.alignerr.schema.project_boost_workforce import (
14+
ProjectBoostWorkforce,
15+
)
1116
from labelbox.schema.media_type import MediaType
1217

1318
logger = logging.getLogger(__name__)
1419

1520

1621
class ValidationType(Enum):
1722
"""Enum for validation types that can be selectively skipped."""
23+
1824
ALIGNERR_RATE = "AlignerrRate"
1925
CUSTOMER_RATE = "CustomerRate"
2026
PROJECT_OWNER = "ProjectOwner"
@@ -123,11 +129,11 @@ def set_domains(self, domains: list[str]):
123129

124130
def set_tags(self, tag_texts: list[str], tag_type: ResourceTagType):
125131
"""Set enhanced resource tags for the project.
126-
132+
127133
Args:
128134
tag_texts: List of tag text values to search for and attach
129135
tag_type: Type filter for searching tags
130-
136+
131137
Returns:
132138
Self for method chaining
133139
"""
@@ -136,7 +142,7 @@ def set_tags(self, tag_texts: list[str], tag_type: ResourceTagType):
136142
existing_tags = EnhancedResourceTag.search_by_text(
137143
self.client, search_text=tag_text, tag_type=tag_type
138144
)
139-
145+
140146
if existing_tags:
141147
# Use the first matching tag
142148
self._enhanced_resource_tags.append(existing_tags[0])
@@ -146,25 +152,26 @@ def set_tags(self, tag_texts: list[str], tag_type: ResourceTagType):
146152
self.client,
147153
text=tag_text,
148154
color="#007bff", # Default blue color
149-
tag_type=tag_type
155+
tag_type=tag_type,
150156
)
151157
self._enhanced_resource_tags.append(new_tag)
152158
return self
153159

154160
def set_project_owner(self, project_owner_email: str):
155161
"""Set the project owner for the ProjectBoostWorkforce.
156-
162+
157163
Args:
158164
project_owner_email: Email of the user to set as project owner
159-
165+
160166
Returns:
161167
Self for method chaining
162168
"""
163169
self._project_owner_email = project_owner_email
164170
return self
165171

166-
167-
def create(self, skip_validation: Union[bool, List[ValidationType]] = False):
172+
def create(
173+
self, skip_validation: Union[bool, List[ValidationType]] = False
174+
):
168175
if not skip_validation:
169176
self._validate()
170177
elif isinstance(skip_validation, list):
@@ -220,7 +227,7 @@ def _create_resource_tags(self, alignerr_project: "AlignerrProject"):
220227
if tag_type not in tags_by_type:
221228
tags_by_type[tag_type] = []
222229
tags_by_type[tag_type].append(tag.text)
223-
230+
224231
# Set tags for each type
225232
for tag_type_str, tag_names in tags_by_type.items():
226233
# Convert string back to enum
@@ -230,17 +237,19 @@ def _create_resource_tags(self, alignerr_project: "AlignerrProject"):
230237
def _create_project_owner(self, alignerr_project: "AlignerrProject"):
231238
if self._project_owner_email:
232239
logger.info(f"Setting project owner: {self._project_owner_email}")
233-
240+
234241
# Find user by email in the organization
235242
user_id = self._find_user_by_email(self._project_owner_email)
236243
if not user_id:
237244
current_org = self.client.get_organization()
238-
raise ValueError(f"User with email {self._project_owner_email} not found in organization {current_org.uid}")
239-
245+
raise ValueError(
246+
f"User with email {self._project_owner_email} not found in organization {current_org.uid}"
247+
)
248+
240249
ProjectBoostWorkforce.set_project_owner(
241250
client=self.client,
242251
project_id=alignerr_project.project.uid,
243-
project_owner_user_id=user_id
252+
project_owner_user_id=user_id,
244253
)
245254

246255
def _validate_alignerr_rates(self):
@@ -273,16 +282,16 @@ def _validate(self):
273282

274283
def _validate_selective(self, skip_validations: List[ValidationType]):
275284
"""Run validations selectively, skipping those in the provided list.
276-
285+
277286
Args:
278287
skip_validations: List of ValidationType enums to skip
279288
"""
280289
if ValidationType.ALIGNERR_RATE not in skip_validations:
281290
self._validate_alignerr_rates()
282-
291+
283292
if ValidationType.CUSTOMER_RATE not in skip_validations:
284293
self._validate_customer_rate()
285-
294+
286295
if ValidationType.PROJECT_OWNER not in skip_validations:
287296
self._validate_project_owner()
288297

@@ -292,31 +301,33 @@ def _get_role_name_to_id(self) -> dict[str, str]:
292301

293302
def _find_user_by_email(self, email: str) -> Optional[str]:
294303
"""Find user ID by email in the organization.
295-
304+
296305
Args:
297306
email: Email address to search for
298-
307+
299308
Returns:
300309
User ID if found, None otherwise
301310
"""
302311
try:
303312
# Import here to avoid circular imports
304313
from labelbox.schema.user import User
305-
314+
306315
# Get the current organization
307316
current_org = self.client.get_organization()
308-
317+
309318
# Use client.get_users with where clause to find user by email
310319
users = self.client.get_users(where=User.email == email)
311-
320+
312321
# Get the first matching user and verify they belong to the same organization
313322
user = next(users, None)
314323
if user and user.organization().uid == current_org.uid:
315324
return user.uid
316325
else:
317-
logger.warning(f"User with email {email} not found in organization {current_org.uid}")
326+
logger.warning(
327+
f"User with email {email} not found in organization {current_org.uid}"
328+
)
318329
return None
319-
330+
320331
except Exception as e:
321332
logger.error(f"Error finding user by email {email}: {e}")
322333
return None

libs/labelbox/src/labelbox/alignerr/alignerr_project_factory.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class AlignerrProjectFactory:
1919
def __init__(self, client: "Client"):
2020
self.client = client
2121

22-
def create(self, yaml_file_path: str, skip_validation: Union[bool, List] = False):
22+
def create(
23+
self, yaml_file_path: str, skip_validation: Union[bool, List] = False
24+
):
2325
"""
2426
Create an AlignerrProject from a YAML configuration file.
2527
@@ -236,46 +238,48 @@ def create(self, yaml_file_path: str, skip_validation: Union[bool, List] = False
236238
domains_config = config["domains"]
237239
if not isinstance(domains_config, list):
238240
raise ValueError("'domains' must be a list")
239-
241+
240242
if not all(isinstance(domain, str) for domain in domains_config):
241243
raise ValueError("All domain names must be strings")
242-
244+
243245
builder.set_domains(domains_config)
244246

245247
# Set enhanced resource tags if provided
246248
if "tags" in config:
247249
tags_config = config["tags"]
248250
if not isinstance(tags_config, list):
249251
raise ValueError("'tags' must be a list")
250-
252+
251253
for tag_config in tags_config:
252254
if not isinstance(tag_config, dict):
253255
raise ValueError("Each tag must be a dictionary")
254-
256+
255257
required_tag_fields = ["text", "type"]
256258
for field in required_tag_fields:
257259
if field not in tag_config:
258260
raise ValueError(
259261
f"Required field '{field}' is missing for tag"
260262
)
261-
263+
262264
# Validate tag type
263265
try:
264266
tag_type = ResourceTagType(tag_config["type"])
265267
except ValueError:
266268
raise ValueError(
267269
f"Invalid tag type '{tag_config['type']}'. Must be one of: {[e.value for e in ResourceTagType]}"
268270
)
269-
271+
270272
# Set the tag
271273
builder.set_tags([tag_config["text"]], tag_type)
272274

273275
# Set project owner if provided
274276
if "project_owner" in config:
275277
project_owner_config = config["project_owner"]
276278
if not isinstance(project_owner_config, str):
277-
raise ValueError("'project_owner' must be a string (email address)")
278-
279+
raise ValueError(
280+
"'project_owner' must be a string (email address)"
281+
)
282+
279283
builder.set_project_owner(project_owner_config)
280284

281285
# Create the project

0 commit comments

Comments
 (0)