Skip to content

Commit

Permalink
project create: add options to import a dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
SpecLad committed Dec 11, 2024
1 parent 146a544 commit d96eb18
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
40 changes: 36 additions & 4 deletions cvat-cli/src/cvat_cli/_internal/commands_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProjectList(GenericListCommand, GenericProjectCommand):
class ProjectCreate:
description = textwrap.dedent(
"""\
Create a new CVAT project.
Create a new CVAT project, optionally importing a dataset.
"""
)

Expand All @@ -44,10 +44,42 @@ def configure_parser(self, parser: argparse.ArgumentParser) -> None:
type=parse_label_arg,
help="string or file containing JSON labels specification",
)
parser.add_argument(
"--dataset_path",
default="",
type=str,
help="path to the dataset file to import",
)
parser.add_argument(
"--dataset_format",
default="CVAT 1.1",
type=str,
help="format of the dataset file being uploaded, e.g. CVAT 1.1",
)
parser.add_argument(
"--completion_verification_period",
dest="status_check_period",
default=2,
type=float,
help="period between status checks (only applies when --dataset_path is specified)",
),

def execute(self, client: Client, *, name: str, labels: dict, **kwargs) -> None:
project = client.projects.create(
spec=models.ProjectWriteRequest(name=name, labels=labels, **kwargs)
def execute(
self,
client: Client,
*,
name: str,
labels: dict,
dataset_path: str,
dataset_format: str,
status_check_period: int,
**kwargs,
) -> None:
project = client.projects.create_from_dataset(
spec=models.ProjectWriteRequest(name=name, labels=labels, **kwargs),
dataset_path=dataset_path,
dataset_format=dataset_format,
status_check_period=status_check_period,
)
print(f"Created project ID {project.id}")

Expand Down
4 changes: 4 additions & 0 deletions site/content/en/docs/api_sdk/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ see that command's examples for more information.
```bash
cvat-cli project create "new project" --labels labels.json
```
- Create a project from a dataset in the COCO format:
```bash
cvat-cli project create "new project" --dataset_file coco.zip --dataset_format "COCO 1.0"
```

### Delete

Expand Down
2 changes: 1 addition & 1 deletion tests/python/cli/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# SPDX-License-Identifier: MIT

from sdk.fixtures import fxt_client # pylint: disable=unused-import
pytest_plugins = ["sdk.fixtures"]
18 changes: 18 additions & 0 deletions tests/python/cli/test_cli_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: MIT

import json
import os

import pytest
from cvat_sdk.api_client import exceptions
Expand Down Expand Up @@ -40,6 +41,23 @@ def test_can_create_project(self):
assert created_project.bug_tracker == "https://bugs.example/"
assert {label.name for label in created_project.get_labels()} == {"car", "person"}

def test_can_create_project_from_dataset(self, fxt_coco_dataset):
stdout = self.run_cli(
"project",
"create",
"new_project",
"--dataset_path",
os.fspath(fxt_coco_dataset),
"--dataset_format",
"COCO 1.0",
)

project_id = int(stdout.split()[-1])
created_project = self.client.projects.retrieve(project_id)
assert created_project.name == "new_project"
assert {label.name for label in created_project.get_labels()} == {"car", "person"}
assert created_project.tasks.count == 1

def test_can_list_projects_in_simple_format(self, fxt_new_project: Project):
output = self.run_cli("project", "ls")

Expand Down

0 comments on commit d96eb18

Please sign in to comment.