Skip to content

[PLT-0] Clone method project #1624

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 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions libs/labelbox/src/labelbox/schema/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,24 @@ def get_overview(self) -> ProjectOverview:
overview["all_in_data_rows"] = overview.pop("all")

return ProjectOverview(**overview)

def clone(self) -> "Project":
"""
Clones the current project.

Returns:
Project: The cloned project.
"""
mutation = """
mutation CloneProjectPyApi($projectId: ID!) {
cloneProject(data: { projectId: $projectId }) {
id
}
}
"""
print(self.uid)
result = self.client.execute(mutation, {"projectId": self.uid})
return self.client.get_project(result["cloneProject"]["id"])


class ProjectMember(DbObject):
Expand Down
16 changes: 16 additions & 0 deletions libs/labelbox/tests/integration/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,19 @@ def test_label_count(client, configured_batch_project_with_label):
[source_project, _, _, _] = configured_batch_project_with_label
num_labels = sum([1 for _ in source_project.labels()])
assert source_project.get_label_count() == num_labels


def test_clone(client, project, rand_gen):
# cannot clone unknown project media type
project = client.create_project(name=rand_gen(str), media_type=MediaType.Image)
cloned_project = project.clone()

assert cloned_project.description == project.description
assert cloned_project.media_type == project.media_type
assert cloned_project.queue_mode == project.queue_mode
assert cloned_project.auto_audit_number_of_labels == project.auto_audit_number_of_labels
assert cloned_project.auto_audit_percentage == project.auto_audit_percentage
assert cloned_project.get_label_count() == 0

project.delete()
cloned_project.delete()