Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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")
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}.")
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
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)
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}.'
- 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")