How to use the pypyr.errors.KeyInContextHasNoValueError function in pypyr

To help you get started, we’ve selected a few pypyr 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 pypyr / pypyr-cli / pypyr / steps / glob.py View on Github external
Returns:
        None. updates context ['globOut'] with list of resolved paths as
              strings.

    """
    logger.debug("started")
    context.assert_key_has_value(key='glob', caller=__name__)

    paths = context.get_formatted('glob')
    if isinstance(paths, list):
        if not paths or any(not p for p in paths):
            raise KeyInContextHasNoValueError("The glob list has an empty str")
        in_count = len(paths)
    else:
        if not paths:
            raise KeyInContextHasNoValueError("The glob path is an empty str")
        in_count = 1

    context['globOut'] = pypyr.utils.filesystem.get_glob(paths)

    logger.info("glob checked %s globs and saved "
                "%s paths to globOut", in_count, len(context['globOut']))
    logger.debug("done")
github pypyr / pypyr-cli / pypyr / context.py View on Github external
key: validate this key exists in context AND has a value that isn't
                 None.
            caller: string. calling function name - this used to construct
                    error messages

        Raises:
            KeyNotInContextError: Key doesn't exist
            KeyInContextHasNoValueError: context[key] is None
            AssertionError: if key is None

        """
        assert key, ("key parameter must be specified.")
        self.assert_key_exists(key, caller)

        if self[key] is None:
            raise KeyInContextHasNoValueError(
                f"context['{key}'] must have a value for {caller}.")
github pypyr / pypyr-cli / pypyr / steps / pype.py View on Github external
failure_group #str
               )

    Raises:
       pypyr.errors.KeyNotInContextError: if ['pype']['name'] is missing.
       pypyr.errors.KeyInContextHasNoValueError: if ['pype']['name'] exists but
                                                 is None.
    """
    context.assert_key_has_value(key='pype', caller=__name__)
    pype = context.get_formatted('pype')

    try:
        pipeline_name = pype['name']

        if pipeline_name is None:
            raise KeyInContextHasNoValueError(
                "pypyr.steps.pype ['pype']['name'] exists but is empty.")
    except KeyError as err:
        raise KeyNotInContextError(
            "pypyr.steps.pype missing 'name' in the 'pype' context item. "
            "You need to specify the pipeline name to run another "
            "pipeline.") from err

    args = pype.get('args', None)

    if args is not None and not isinstance(args, dict):
        raise ContextError(
            "pypyr.steps.pype 'args' in the 'pype' context item "
            "must be a dict.")

    if args and 'useParentContext' not in pype:
        use_parent_context = False
github pypyr / pypyr-cli / pypyr / steps / pathcheck.py View on Github external
Returns:
        None. updates context arg.

    Raises:
        pypyr.errors.KeyNotInContextError: pathExists missing in context.
        pypyr.errors.KeyInContextHasNoValueError: pathCheck exists but is None.

    """
    logger.debug("started")
    context.assert_key_has_value(key='pathCheck', caller=__name__)

    paths_to_check = context['pathCheck']

    if not paths_to_check:
        raise KeyInContextHasNoValueError("context['pathCheck'] must have a "
                                          f"value for {__name__}.")

    # pathsToCheck can be a string or a list in case there are multiple paths
    if isinstance(paths_to_check, list):
        check_me = paths_to_check
    else:
        # assuming it's a str/path at this point
        check_me = [paths_to_check]

    out = {}
    total_found = 0

    for path in check_me:
        logger.debug("checking path: %s", path)
        formatted_path = context.get_formatted_string(path)
        found_paths = pypyr.utils.filesystem.get_glob(formatted_path)
github pypyr / pypyr-cli / pypyr / context.py View on Github external
else:
            append_error_text = f' {extra_error_text}'

        if not context_item.key_in_context:
            raise KeyNotInContextError(f'{caller} couldn\'t find '
                                       f'{context_item.key} in context.'
                                       f'{append_error_text}')

        if not context_item.has_value:
            raise KeyInContextHasNoValueError(
                f'{caller} found {context_item.key} in '
                f'context but it doesn\'t have a value.'
                f'{append_error_text}')

        if not context_item.is_expected_type:
            raise KeyInContextHasNoValueError(
                f'{caller} found {context_item.key} in context, but it\'s '
                f'not a {context_item.expected_type}.'
github pypyr / pypyr-cli / pypyr / steps / glob.py View on Github external
- glob. str or list. Single path, or list of paths.

    All inputs support pypyr formatting expressions.

    Returns:
        None. updates context ['globOut'] with list of resolved paths as
              strings.

    """
    logger.debug("started")
    context.assert_key_has_value(key='glob', caller=__name__)

    paths = context.get_formatted('glob')
    if isinstance(paths, list):
        if not paths or any(not p for p in paths):
            raise KeyInContextHasNoValueError("The glob list has an empty str")
        in_count = len(paths)
    else:
        if not paths:
            raise KeyInContextHasNoValueError("The glob path is an empty str")
        in_count = 1

    context['globOut'] = pypyr.utils.filesystem.get_glob(paths)

    logger.info("glob checked %s globs and saved "
                "%s paths to globOut", in_count, len(context['globOut']))
    logger.debug("done")