Exemplo n.º 1
0
def create(ctx, name, description, tags, public, init):
    """Create a new project.

    Uses /docs/core/cli/#caching

    Example:

    \b
    $ polyaxon project create --name=cats-vs-dogs --description="Image Classification with DL"

    \b
    $ polyaxon project create --name=owner/name --description="Project Description"
    """
    if not name:
        Printer.print_error(
            "Please provide a valid name to create a project.",
            command_help="project create",
            sys_exit=True,
        )
    owner, project_name = resolve_entity_info(name or ctx.obj.get("project"),
                                              is_cli=True,
                                              entity_name="project")

    tags = validate_tags(tags)

    if not owner:
        Printer.print_error(
            "Please provide a valid name with an owner namespace: --name=owner/project."
        )
        sys.exit(1)

    try:
        project_config = V1Project(name=project_name,
                                   description=description,
                                   tags=tags,
                                   is_public=public)
        polyaxon_client = ProjectClient(owner=owner)
        _project = polyaxon_client.create(project_config)
        config = polyaxon_client.client.sanitize_for_serialization(_project)
        cache.cache(config_manager=ProjectConfigManager, config=config)
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not create project `{}`.".format(project_name))
        sys.exit(1)

    Printer.print_success("Project `{}` was created successfully.".format(
        _project.name))
    click.echo("You can view this project on Polyaxon UI: {}".format(
        get_dashboard_url(subpath="{}/{}".format(owner, _project.name))))

    if init:
        ctx.obj = {}
        ctx.invoke(
            init_project,
            project="{}/{}".format(owner, project_name),
            polyaxonignore=True,
        )
Exemplo n.º 2
0
    def test_resolve_entity_info(self):
        with self.assertRaises(PolyaxonClientException):
            resolve_entity_info("", "")

        with self.assertRaises(PolyaxonClientException):
            resolve_entity_info("", "test")

        with self.assertRaises(PolyaxonClientException):
            resolve_entity_info(None, None)

        with self.assertRaises(PolyaxonSchemaError):
            resolve_entity_info("owner.entity.test", "")

        with self.assertRaises(PolyaxonSchemaError):
            resolve_entity_info("owner/entity/test", "")

        assert resolve_entity_info("owner.entity",
                                   "project") == ("owner", "entity")