Skip to content

Commit 0d33b8a

Browse files
stchabiSihem Tchabi
and
Sihem Tchabi
authored
fix(LAB-3474): deprecation of projectType and creation of fromDemoProject parameter
Co-authored-by: Sihem Tchabi <[email protected]>
1 parent 00604a0 commit 0d33b8a

File tree

6 files changed

+71
-29
lines changed

6 files changed

+71
-29
lines changed

src/kili/adapters/kili_api_gateway/project/operations_mixin.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
load_project_json_fields,
1515
)
1616
from kili.adapters.kili_api_gateway.project.operations import get_projects_query
17-
from kili.core.enums import ProjectType
17+
from kili.core.enums import DemoProjectType, ProjectType
1818
from kili.domain.project import ComplianceTag, InputType, ProjectFilters, ProjectId
1919
from kili.domain.types import ListOrTuple
2020

@@ -45,18 +45,20 @@ def create_project(
4545
description: str,
4646
project_type: Optional[ProjectType],
4747
compliance_tags: Optional[ListOrTuple[ComplianceTag]],
48+
from_demo_project: Optional[DemoProjectType],
4849
) -> ProjectId:
4950
"""Create a project."""
5051
variables = {
5152
"data": {
5253
"description": description,
54+
"fromDemoProject": from_demo_project,
5355
"inputType": input_type,
5456
"jsonInterface": json.dumps(json_interface),
5557
"projectType": project_type,
5658
"title": title,
5759
}
5860
}
59-
# complience tags are only available for Kili app > 2.138
61+
# compliance tags are only available for Kili app > 2.138
6062
if compliance_tags:
6163
variables["data"]["complianceTags"] = compliance_tags
6264

src/kili/core/enums.py

+21
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,27 @@
6464
]
6565

6666

67+
DemoProjectType = Literal[
68+
"DEMO_COMPUTER_VISION_TUTORIAL",
69+
"DEMO_TEXT_TUTORIAL",
70+
"DEMO_PDF_TUTORIAL",
71+
"VIDEO_FRAME_OBJECT_TRACKING",
72+
"DEMO_SEGMENTATION_COCO",
73+
"DEMO_NER",
74+
"DEMO_ID_OCR",
75+
"DEMO_REVIEWS",
76+
"DEMO_OCR",
77+
"DEMO_NER_TWEETS",
78+
"DEMO_PLASTIC",
79+
"DEMO_CHATBOT",
80+
"DEMO_PDF",
81+
"DEMO_ANIMALS",
82+
"DEMO_LLM",
83+
"DEMO_LLM_INSTR_FOLLOWING",
84+
"DEMO_SEGMENTATION",
85+
]
86+
87+
6788
Right = Literal[
6889
"CAN_ACCESS_SMART_TOOLS",
6990
"CAN_LABEL",

src/kili/presentation/client/project.py

+36-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Client presentation methods for projects."""
2-
32
import warnings
43
from typing import (
54
Any,
@@ -16,10 +15,11 @@
1615
from typeguard import typechecked
1716

1817
from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions
19-
from kili.core.enums import ProjectType
18+
from kili.core.enums import DemoProjectType, ProjectType
2019
from kili.domain.project import ComplianceTag, InputType, ProjectFilters, ProjectId
2120
from kili.domain.tag import TagId
2221
from kili.domain.types import ListOrTuple
22+
from kili.exceptions import IncompatibleArgumentsError
2323
from kili.presentation.client.helpers.common_validators import (
2424
disable_tqdm_if_as_generator,
2525
)
@@ -46,6 +46,7 @@ def create_project(
4646
project_type: Optional[ProjectType] = None,
4747
tags: Optional[ListOrTuple[str]] = None,
4848
compliance_tags: Optional[ListOrTuple[ComplianceTag]] = None,
49+
from_demo_project: Optional[DemoProjectType] = None,
4950
) -> Dict[Literal["id"], str]:
5051
"""Create a project.
5152
@@ -55,34 +56,31 @@ def create_project(
5556
title: Title of the project.
5657
description: Description of the project.
5758
project_id: Identifier of the project to copy.
58-
project_type: Currently, one of:
59-
60-
- `IMAGE_CLASSIFICATION_MULTI`
61-
- `IMAGE_CLASSIFICATION_SINGLE`
62-
- `IMAGE_OBJECT_DETECTION_POLYGON`
63-
- `IMAGE_OBJECT_DETECTION_RECTANGLE`
64-
- `IMAGE_OBJECT_DETECTION_SEMANTIC`
65-
- `IMAGE_POSE_ESTIMATION`
66-
- `OCR`
67-
- `PDF_CLASSIFICATION_MULTI`
68-
- `PDF_CLASSIFICATION_SINGLE`
69-
- `PDF_NAMED_ENTITY_RECOGNITION`
70-
- `PDF_OBJECT_DETECTION_RECTANGLE`
71-
- `SPEECH_TO_TEXT`
72-
- `TEXT_CLASSIFICATION_MULTI`
73-
- `TEXT_CLASSIFICATION_SINGLE`
74-
- `TEXT_NER`
75-
- `TEXT_TRANSCRIPTION`
76-
- `TIME_SERIES`
77-
- `VIDEO_CLASSIFICATION_SINGLE`
78-
- `VIDEO_FRAME_CLASSIFICATION`
79-
- `VIDEO_FRAME_OBJECT_TRACKING`
80-
59+
project_type: Will be deprecated soon, use from_demo_project instead.
8160
tags: Tags to add to the project. The tags must already exist in the organization.
8261
compliance_tags: Compliance tags of the project.
8362
Compliance tags are used to categorize projects based on the sensitivity of
8463
the data being handled and the legal constraints associated with it.
8564
Possible values are: `PHI` and `PII`.
65+
from_demo_project: Currently, one of:
66+
67+
- `DEMO_COMPUTER_VISION_TUTORIAL`
68+
- `DEMO_TEXT_TUTORIAL`
69+
- `DEMO_PDF_TUTORIAL`
70+
- `VIDEO_FRAME_OBJECT_TRACKING`
71+
- `DEMO_SEGMENTATION_COCO`
72+
- `DEMO_NER`
73+
- `DEMO_ID_OCR`
74+
- `DEMO_REVIEWS`
75+
- `DEMO_OCR`
76+
- `DEMO_NER_TWEETS`
77+
- `DEMO_PLASTIC`
78+
- `DEMO_CHATBOT`
79+
- `DEMO_PDF`
80+
- `DEMO_ANIMALS`
81+
- `DEMO_LLM`
82+
- `DEMO_LLM_INSTR_FOLLOWING`
83+
- `DEMO_SEGMENTATION`
8684
8785
Returns:
8886
A dict with the id of the created project.
@@ -94,6 +92,18 @@ def create_project(
9492
For more detailed examples on how to create projects,
9593
see [the recipe](https://docs.kili-technology.com/recipes/creating-a-project).
9694
"""
95+
if project_type is not None:
96+
warnings.warn(
97+
"Parameter project_type will be soon deprecated, please use from_demo_project instead.",
98+
DeprecationWarning,
99+
stacklevel=1,
100+
)
101+
102+
if project_type is not None and from_demo_project is not None:
103+
raise IncompatibleArgumentsError(
104+
"Either provide project_type or from_demo_project. Not both at the same time."
105+
)
106+
97107
project_id = ProjectUseCases(self.kili_api_gateway).create_project(
98108
input_type=input_type,
99109
json_interface=json_interface,
@@ -102,6 +112,7 @@ def create_project(
102112
project_id=project_id,
103113
project_type=project_type,
104114
compliance_tags=compliance_tags,
115+
from_demo_project=from_demo_project,
105116
)
106117

107118
if tags is not None:

src/kili/use_cases/project/project.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions
1212
from kili.adapters.kili_api_gateway.project.mappers import project_data_mapper
1313
from kili.adapters.kili_api_gateway.project.types import ProjectDataKiliAPIGatewayInput
14-
from kili.core.enums import ProjectType
14+
from kili.core.enums import DemoProjectType, ProjectType
1515
from kili.domain.project import ComplianceTag, InputType, ProjectFilters, ProjectId
1616
from kili.domain.types import ListOrTuple
1717
from kili.exceptions import NotFound
@@ -21,13 +21,14 @@
2121
class ProjectUseCases(BaseUseCases):
2222
"""Project use cases."""
2323

24-
# pylint: disable=too-many-arguments
24+
# pylint: disable=too-many-arguments, too-many-locals
2525
def create_project(
2626
self,
2727
title: str,
2828
description: str,
2929
project_type: Optional[ProjectType],
3030
compliance_tags: Optional[ListOrTuple[ComplianceTag]],
31+
from_demo_project: Optional[DemoProjectType],
3132
project_id: Optional[ProjectId] = None,
3233
input_type: Optional[InputType] = None,
3334
json_interface: Optional[Dict] = None,
@@ -47,6 +48,7 @@ def create_project(
4748
description=description,
4849
project_type=project_type,
4950
compliance_tags=compliance_tags,
51+
from_demo_project=from_demo_project,
5052
)
5153
if project_copied["instructions"]:
5254
self.update_properties_in_project(
@@ -75,6 +77,7 @@ def create_project(
7577
description=description,
7678
project_type=project_type,
7779
compliance_tags=compliance_tags,
80+
from_demo_project=from_demo_project,
7881
)
7982

8083
# The project is not immediately available after creation

tests/integration/presentation/test_project.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_when_creating_project_then_it_returns_project_id(mocker: pytest_mock.Mo
2828
"jsonInterface": "{}",
2929
"projectType": None,
3030
"title": "fake_title",
31+
"fromDemoProject": None,
3132
}
3233
},
3334
)

tests/integration/use_cases/test_project.py

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_when_create_project_it_works(kili_api_gateway: KiliAPIGateway):
4242
project_id=None,
4343
project_type=None,
4444
compliance_tags=None,
45+
from_demo_project=None,
4546
)
4647

4748
# Then
@@ -66,6 +67,7 @@ def test_when_create_project_without_inputType_or_jsonInterface_it_throw_an_erro
6667
description="description",
6768
project_type=None,
6869
compliance_tags=None,
70+
from_demo_project=None,
6971
)
7072

7173

@@ -91,6 +93,7 @@ def test_when_create_project_with_project_id_it_works(kili_api_gateway: KiliAPIG
9193
project_id=ProjectId("fake_project_id"),
9294
project_type=None,
9395
compliance_tags=None,
96+
from_demo_project=None,
9497
)
9598

9699
# Then
@@ -128,6 +131,7 @@ def test_when_create_project_with_project_id_it_throw_an_error_if_tags_do_not_be
128131
project_id=ProjectId("fake_project_id"),
129132
project_type=None,
130133
compliance_tags=None,
134+
from_demo_project=None,
131135
)
132136

133137

0 commit comments

Comments
 (0)