def test_get_component_info(self):
        with self.assertRaises(PolyaxonSchemaError):
            get_component_info(None)

        with self.assertRaises(PolyaxonSchemaError):
            get_component_info("")

        assert get_component_info("hub") == ("polyaxon", "hub", "latest")
        assert get_component_info("hub:ver") == ("polyaxon", "hub", "ver")
        assert get_component_info("owner.hub") == ("owner", "hub", "latest")
        assert get_component_info("owner/hub") == ("owner", "hub", "latest")
        assert get_component_info("owner.hub:ver") == ("owner", "hub", "ver")
        assert get_component_info("owner/hub:ver") == ("owner", "hub", "ver")
Example #2
0
def get_info(component: str = None, version: str = None):
    if not any([component, version]):
        Printer.print_error(
            "A component or a component version is required.", sys_exit=True
        )
    if all([component, version]):
        Printer.print_error(
            "Only a component or a component version is required, not both.",
            sys_exit=True,
        )

    if component:
        entity = component
        entity_name = "component"
        is_version = False
    else:
        entity = version
        entity_name = "component version"
        is_version = True

    try:
        owner, component_hub, component_version = get_component_info(entity)
        return owner, component_hub, component_version, is_version
    except PolyaxonException as e:
        handle_cli_error(
            e,
            message="Could not resolve the {} from the value `{}`.".format(
                entity_name, entity
            ),
            sys_exit=True,
        )
Example #3
0
def _read_from_polyaxon_hub(hub: str):
    from polyaxon.client import PolyaxonClient
    from polyaxon.constants.globals import DEFAULT_HUB, NO_AUTH
    from polyaxon.env_vars.getters import get_component_info
    from polyaxon.schemas.cli.client_config import ClientConfig

    owner, component, version = get_component_info(hub)

    try:
        if owner == DEFAULT_HUB:
            config = ClientConfig()
            client = PolyaxonClient(
                config=config,
                token=NO_AUTH,
            )
        else:
            client = PolyaxonClient()
        response = client.component_hub_v1.get_component_version(
            owner, component, version
        )
        return _read_from_stream(response.content)
    except (ApiException, HTTPError) as e:
        raise PolyaxonClientException(
            "Component `{}` could not be fetched, "
            "an error was encountered".format(hub, e)
        )