Skip to content

Commit 37b7b12

Browse files
authored
[PLT-1490] Removed project.setup (#1843)
1 parent 1d78bee commit 37b7b12

File tree

7 files changed

+260
-171
lines changed

7 files changed

+260
-171
lines changed

libs/labelbox/src/labelbox/schema/ontology.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,14 +562,18 @@ class OntologyBuilder:
562562
There are no required instantiation arguments.
563563
564564
To create an ontology, use the asdict() method after fully building your
565-
ontology within this class, and inserting it into project.setup() as the
566-
"labeling_frontend_options" parameter.
565+
ontology within this class, and inserting it into client.create_ontology() as the
566+
"normalized" parameter.
567567
568568
Example:
569-
builder = OntologyBuilder()
570-
...
571-
frontend = list(client.get_labeling_frontends())[0]
572-
project.setup(frontend, builder.asdict())
569+
>>> builder = OntologyBuilder()
570+
>>> ...
571+
>>> ontology = client.create_ontology(
572+
>>> "Ontology from new features",
573+
>>> ontology_builder.asdict(),
574+
>>> media_type=lb.MediaType.Image,
575+
>>> )
576+
>>> project.connect_ontology(ontology)
573577
574578
attributes:
575579
tools: (list)

libs/labelbox/src/labelbox/schema/project.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -684,34 +684,6 @@ def connect_ontology(self, ontology) -> None:
684684
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
685685
self.update(setup_complete=timestamp)
686686

687-
def setup(self, labeling_frontend, labeling_frontend_options) -> None:
688-
"""This method will associate default labeling frontend with the project and create an ontology based on labeling_frontend_options.
689-
690-
Args:
691-
labeling_frontend (LabelingFrontend): Do not use, this parameter is deprecated. We now associate the default labeling frontend with the project.
692-
labeling_frontend_options (dict or str): Labeling frontend options,
693-
a.k.a. project ontology. If given a `dict` it will be converted
694-
to `str` using `json.dumps`.
695-
"""
696-
697-
warnings.warn("This method is deprecated use connect_ontology instead.")
698-
if labeling_frontend is not None:
699-
warnings.warn(
700-
"labeling_frontend parameter will not be used to create a new labeling frontend."
701-
)
702-
703-
if self.is_chat_evaluation() or self.is_prompt_response():
704-
warnings.warn("""
705-
This project is a live chat evaluation project or prompt and response generation project.
706-
Editor was setup automatically.
707-
""")
708-
return
709-
710-
self._connect_default_labeling_front_end(labeling_frontend_options)
711-
712-
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
713-
self.update(setup_complete=timestamp)
714-
715687
def _connect_default_labeling_front_end(self, ontology_as_dict: dict):
716688
labeling_frontend = self.labeling_frontend()
717689
if (

libs/labelbox/tests/conftest.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ def configured_project_with_label(
656656
[data_row.uid], # sample of data row objects
657657
5, # priority between 1(Highest) - 5(lowest)
658658
)
659-
ontology = _setup_ontology(project)
659+
ontology = _setup_ontology(project, client)
660660
label = _create_label(
661661
project, data_row, ontology, wait_for_label_processing
662662
)
@@ -699,20 +699,19 @@ def create_label():
699699
return label
700700

701701

702-
def _setup_ontology(project):
703-
editor = list(
704-
project.client.get_labeling_frontends(
705-
where=LabelingFrontend.name == "editor"
706-
)
707-
)[0]
702+
def _setup_ontology(project: Project, client: Client):
708703
ontology_builder = OntologyBuilder(
709704
tools=[
710705
Tool(tool=Tool.Type.BBOX, name="test-bbox-class"),
711706
]
712707
)
713-
project.setup(editor, ontology_builder.asdict())
714-
# TODO: ontology may not be synchronous after setup. remove sleep when api is more consistent
715-
time.sleep(2)
708+
ontology = client.create_ontology(
709+
name="ontology with features",
710+
media_type=MediaType.Image,
711+
normalized=ontology_builder.asdict(),
712+
)
713+
project.connect_ontology(ontology)
714+
716715
return OntologyBuilder.from_project(project)
717716

718717

@@ -754,7 +753,7 @@ def configured_batch_project_with_label(
754753
project.create_batch("test-batch", data_rows)
755754
project.data_row_ids = data_rows
756755

757-
ontology = _setup_ontology(project)
756+
ontology = _setup_ontology(project, client)
758757
label = _create_label(
759758
project, data_row, ontology, wait_for_label_processing
760759
)
@@ -786,7 +785,7 @@ def configured_batch_project_with_multiple_datarows(
786785
batch_name = f"batch {uuid.uuid4()}"
787786
project.create_batch(batch_name, global_keys=global_keys)
788787

789-
ontology = _setup_ontology(project)
788+
ontology = _setup_ontology(project, client)
790789
for datarow in data_rows:
791790
_create_label(project, datarow, ontology, wait_for_label_processing)
792791

@@ -1023,11 +1022,11 @@ def _upload_invalid_data_rows_for_dataset(dataset: Dataset):
10231022

10241023
@pytest.fixture
10251024
def configured_project(
1026-
project_with_empty_ontology, initial_dataset, rand_gen, image_url
1025+
project_with_one_feature_ontology, initial_dataset, rand_gen, image_url
10271026
):
10281027
dataset = initial_dataset
10291028
data_row_id = dataset.create_data_row(row_data=image_url).uid
1030-
project = project_with_empty_ontology
1029+
project = project_with_one_feature_ontology
10311030

10321031
batch = project.create_batch(
10331032
rand_gen(str),
@@ -1042,20 +1041,21 @@ def configured_project(
10421041

10431042

10441043
@pytest.fixture
1045-
def project_with_empty_ontology(project):
1046-
editor = list(
1047-
project.client.get_labeling_frontends(
1048-
where=LabelingFrontend.name == "editor"
1049-
)
1050-
)[0]
1051-
empty_ontology = {"tools": [], "classifications": []}
1052-
project.setup(editor, empty_ontology)
1044+
def project_with_one_feature_ontology(project, client: Client):
1045+
tools = [
1046+
Tool(tool=Tool.Type.BBOX, name="test-bbox-class").asdict(),
1047+
]
1048+
empty_ontology = {"tools": tools, "classifications": []}
1049+
ontology = client.create_ontology(
1050+
"empty ontology", empty_ontology, MediaType.Image
1051+
)
1052+
project.connect_ontology(ontology)
10531053
yield project
10541054

10551055

10561056
@pytest.fixture
10571057
def configured_project_with_complex_ontology(
1058-
client, initial_dataset, rand_gen, image_url, teardown_helpers
1058+
client: Client, initial_dataset, rand_gen, image_url, teardown_helpers
10591059
):
10601060
project = client.create_project(
10611061
name=rand_gen(str),
@@ -1072,19 +1072,12 @@ def configured_project_with_complex_ontology(
10721072
)
10731073
project.data_row_ids = data_row_ids
10741074

1075-
editor = list(
1076-
project.client.get_labeling_frontends(
1077-
where=LabelingFrontend.name == "editor"
1078-
)
1079-
)[0]
1080-
10811075
ontology = OntologyBuilder()
10821076
tools = [
10831077
Tool(tool=Tool.Type.BBOX, name="test-bbox-class"),
10841078
Tool(tool=Tool.Type.LINE, name="test-line-class"),
10851079
Tool(tool=Tool.Type.POINT, name="test-point-class"),
10861080
Tool(tool=Tool.Type.POLYGON, name="test-polygon-class"),
1087-
Tool(tool=Tool.Type.NER, name="test-ner-class"),
10881081
]
10891082

10901083
options = [
@@ -1116,7 +1109,11 @@ def configured_project_with_complex_ontology(
11161109
for c in classifications:
11171110
ontology.add_classification(c)
11181111

1119-
project.setup(editor, ontology.asdict())
1112+
ontology = client.create_ontology(
1113+
"complex image ontology", ontology.asdict(), MediaType.Image
1114+
)
1115+
1116+
project.connect_ontology(ontology)
11201117

11211118
yield [project, data_row]
11221119
teardown_helpers.teardown_project_labels_ontology_feature_schemas(project)

0 commit comments

Comments
 (0)