How to use the renku.core.errors.UsageError function in renku

To help you get started, we’ve selected a few renku examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SwissDataScienceCenter / renku-python / renku / cli / exception_handler.py View on Github external
def main(self, *args, **kwargs):
        """Catch and print all Renku exceptions."""
        try:
            return super().main(*args, **kwargs)
        except RenkuException as e:
            click.echo('Error: {}'.format(e))
            if e.__cause__ is not None:
                click.echo('\n{}'.format(traceback.format_exc()))
            exit_code = 1
            if isinstance(e, (ParameterError, UsageError)):
                exit_code = 2
            sys.exit(exit_code)
github SwissDataScienceCenter / renku-python / renku / core / management / datasets.py View on Github external
destination = self._resolve_path(dataset_path, destination)
        destination = self.path / dataset_path / destination

        files = []

        for url in urls:
            is_remote, is_git = _check_url(url)

            if is_git and is_remote:  # Remote git repo
                sources = sources or ()
                data = self._add_from_git(
                    dataset, url, sources, destination, ref
                )
            else:
                if sources:
                    raise errors.UsageError(
                        'Cannot use "--source" with URLs or local files.'
                    )

                if not is_remote:  # Local path, might be git
                    if is_git:
                        warning_message = 'Adding data from local Git ' \
                            'repository. Use remote\'s Git URL instead to ' \
                            'enable lineage information and updates.'
                    u = parse.urlparse(url)
                    data = self._add_from_local(
                        dataset, u.path, link, destination
                    )
                else:  # Remote URL
                    data = self._add_from_url(dataset, url, destination)

            files.extend(data)
github SwissDataScienceCenter / renku-python / renku / core / commands / options.py View on Github external
def validate_endpoint(ctx, param, value):
    """Validate endpoint."""
    try:
        config = ctx.obj['config']
    except Exception:
        return

    endpoint = default_endpoint(ctx, param, value)

    if endpoint not in config.get('endpoints', {}):
        raise UsageError('Unknown endpoint: {0}'.format(endpoint))

    return endpoint
github SwissDataScienceCenter / renku-python / renku / core / commands / dataset.py View on Github external
client,
    urls,
    name,
    link=False,
    force=False,
    create=False,
    sources=(),
    destination='',
    ref=None,
    with_metadata=None,
    urlscontext=contextlib.nullcontext,
    commit_message=None,
):
    """Add data to a dataset."""
    if len(urls) == 0:
        raise UsageError('No URL is specified')
    if (sources or destination) and len(urls) > 1:
        raise UsageError(
            'Cannot add multiple URLs with --source or --destination'
        )

    # check for identifier before creating the dataset
    identifier = extract_doi(
        with_metadata.identifier
    ) if with_metadata else None
    try:
        with client.with_dataset(
            name=name, identifier=identifier, create=create
        ) as dataset:
            with urlscontext(urls) as bar:
                warning_message = client.add_data_to_dataset(
                    dataset,
github SwissDataScienceCenter / renku-python / renku / cli / config.py View on Github external
def config(key, value, remove, local_only, global_only):
    """Manage configuration options."""
    is_write = value is not None

    if is_write and remove:
        raise errors.UsageError('Cannot remove and set at the same time.')
    if remove and not key:
        raise errors.UsageError('KEY is missing.')
    if local_only and global_only:
        raise errors.UsageError('Cannot use --local and --global together.')

    if remove:
        update_config(key, remove=remove, global_only=global_only)
    elif is_write:
        update_config(key, value=value, global_only=global_only)
    else:
        value = read_config(key, local_only, global_only)
        click.secho(value)
github SwissDataScienceCenter / renku-python / renku / core / commands / dataset.py View on Github external
name,
    link=False,
    force=False,
    create=False,
    sources=(),
    destination='',
    ref=None,
    with_metadata=None,
    urlscontext=contextlib.nullcontext,
    commit_message=None,
):
    """Add data to a dataset."""
    if len(urls) == 0:
        raise UsageError('No URL is specified')
    if (sources or destination) and len(urls) > 1:
        raise UsageError(
            'Cannot add multiple URLs with --source or --destination'
        )

    # check for identifier before creating the dataset
    identifier = extract_doi(
        with_metadata.identifier
    ) if with_metadata else None
    try:
        with client.with_dataset(
            name=name, identifier=identifier, create=create
        ) as dataset:
            with urlscontext(urls) as bar:
                warning_message = client.add_data_to_dataset(
                    dataset,
                    bar,
                    link=link,
github SwissDataScienceCenter / renku-python / renku / core / commands / options.py View on Github external
def default_endpoint(ctx, param, value):
    """Return default endpoint if specified."""
    if ctx.resilient_parsing:
        return

    config = ctx.obj['config']
    endpoint = default_endpoint_from_config(config, option=value)

    if endpoint is None:
        raise UsageError('No default endpoint found.')

    return endpoint
github SwissDataScienceCenter / renku-python / renku / cli / config.py View on Github external
def config(key, value, remove, local_only, global_only):
    """Manage configuration options."""
    is_write = value is not None

    if is_write and remove:
        raise errors.UsageError('Cannot remove and set at the same time.')
    if remove and not key:
        raise errors.UsageError('KEY is missing.')
    if local_only and global_only:
        raise errors.UsageError('Cannot use --local and --global together.')

    if remove:
        update_config(key, remove=remove, global_only=global_only)
    elif is_write:
        update_config(key, value=value, global_only=global_only)
    else:
        value = read_config(key, local_only, global_only)
        click.secho(value)