Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return super(Exception, self).__str__()
class LoopMaxExhaustedError(Error):
"""Max attempts reached during looping."""
class PipelineDefinitionError(Error):
"""Pipeline definition incorrect. Likely a yaml error."""
class PipelineNotFoundError(Error):
"""Pipeline not found in working dir or in pypyr install dir."""
class PlugInError(Error):
"""Pypyr plug - ins should sub - class this."""
class PyModuleNotFoundError(Error, ModuleNotFoundError):
"""Could not load python module because it wasn't found."""
# -------------------------- Control of Flow Instructions ---------------------
class Stop(Error):
"""Control of flow. Stop all execution."""
class StopPipeline(Stop):
"""Control of flow. Stop current pipeline execution."""
error_type = type(error)
if error_type.__module__ in ['__main__', 'builtins']:
return error_type.__name__
else:
return f'{error_type.__module__}.{error_type.__name__}'
class Error(Exception):
"""Base class for all pypyr exceptions."""
class ContextError(Error):
"""Error in the pypyr context."""
class HandledError(Error):
"""Error that has already been saved to errors context collection"""
class KeyInContextHasNoValueError(ContextError):
"""pypyr context[key] doesn't have a value."""
class KeyNotInContextError(ContextError, KeyError):
"""Key not found in the pypyr context."""
def __str__(self):
"""KeyError has custom error formatting, avoid this behaviour."""
return super(Exception, self).__str__()
class LoopMaxExhaustedError(Error):
"""Key not found in the pypyr context."""
def __str__(self):
"""KeyError has custom error formatting, avoid this behaviour."""
return super(Exception, self).__str__()
class LoopMaxExhaustedError(Error):
"""Max attempts reached during looping."""
class PipelineDefinitionError(Error):
"""Pipeline definition incorrect. Likely a yaml error."""
class PipelineNotFoundError(Error):
"""Pipeline not found in working dir or in pypyr install dir."""
class PlugInError(Error):
"""Pypyr plug - ins should sub - class this."""
class PyModuleNotFoundError(Error, ModuleNotFoundError):
"""Could not load python module because it wasn't found."""
# -------------------------- Control of Flow Instructions ---------------------
class Stop(Error):
"""Control of flow. Stop all execution."""
Returns:
str. Canonical error name.
"""
error_type = type(error)
if error_type.__module__ in ['__main__', 'builtins']:
return error_type.__name__
else:
return f'{error_type.__module__}.{error_type.__name__}'
class Error(Exception):
"""Base class for all pypyr exceptions."""
class ContextError(Error):
"""Error in the pypyr context."""
class HandledError(Error):
"""Error that has already been saved to errors context collection"""
class KeyInContextHasNoValueError(ContextError):
"""pypyr context[key] doesn't have a value."""
class KeyNotInContextError(ContextError, KeyError):
"""Key not found in the pypyr context."""
def __str__(self):
"""KeyError has custom error formatting, avoid this behaviour."""
"""Error that has already been saved to errors context collection"""
class KeyInContextHasNoValueError(ContextError):
"""pypyr context[key] doesn't have a value."""
class KeyNotInContextError(ContextError, KeyError):
"""Key not found in the pypyr context."""
def __str__(self):
"""KeyError has custom error formatting, avoid this behaviour."""
return super(Exception, self).__str__()
class LoopMaxExhaustedError(Error):
"""Max attempts reached during looping."""
class PipelineDefinitionError(Error):
"""Pipeline definition incorrect. Likely a yaml error."""
class PipelineNotFoundError(Error):
"""Pipeline not found in working dir or in pypyr install dir."""
class PlugInError(Error):
"""Pypyr plug - ins should sub - class this."""
class PyModuleNotFoundError(Error, ModuleNotFoundError):
class PipelineNotFoundError(Error):
"""Pipeline not found in working dir or in pypyr install dir."""
class PlugInError(Error):
"""Pypyr plug - ins should sub - class this."""
class PyModuleNotFoundError(Error, ModuleNotFoundError):
"""Could not load python module because it wasn't found."""
# -------------------------- Control of Flow Instructions ---------------------
class Stop(Error):
"""Control of flow. Stop all execution."""
class StopPipeline(Stop):
"""Control of flow. Stop current pipeline execution."""
class StopStepGroup(Stop):
"""Control of flow. Stop current step - group execution."""
class ControlOfFlowInstruction(Error):
"""Control of flow instructions should inherit from this.
Attributes:
groups: list of str. List of step - groups to execute.
# -------------------------- Control of Flow Instructions ---------------------
class Stop(Error):
"""Control of flow. Stop all execution."""
class StopPipeline(Stop):
"""Control of flow. Stop current pipeline execution."""
class StopStepGroup(Stop):
"""Control of flow. Stop current step - group execution."""
class ControlOfFlowInstruction(Error):
"""Control of flow instructions should inherit from this.
Attributes:
groups: list of str. List of step - groups to execute.
success_group: str. Step - group to execute on success condition.
failure_group: str. Step - group to execute on failure condition.
"""
def __init__(self, groups, success_group, failure_group):
"""Initialize the control of flow instruction.
Args:
groups: list of str. List of step - groups to execute.
success_group: str. Step - group to execute on success condition.
failure_group: str. Step - group to execute on failure condition.
"""
# derive the destination directory, ensure it's ready for writing
basedir_out = None
is_outfile_name_known = False
if out_path:
# outpath could be a file, or a dir
pathlib_out = Path(out_path)
# yep, Path() strips trailing /, hence check original string
if isinstance(out_path, str) and out_path.endswith(os.sep):
# ensure dir - mimic posix mkdir -p
pathlib_out.mkdir(parents=True, exist_ok=True)
basedir_out = pathlib_out
elif pathlib_out.is_dir():
basedir_out = pathlib_out
else:
if len(in_paths) > 1:
raise Error(
f'{in_path} resolves to {len(in_paths)} files, '
'but you specified only a single file as out '
f'{out_path}. If the outpath is meant to be a '
'directory, put a / at the end.')
# at this point it must be a file (not dir) path
# make sure that the parent dir exists
basedir_out = pathlib_out.parent
basedir_out.parent.mkdir(parents=True, exist_ok=True)
is_outfile_name_known = True
# loop through all the in files and write them to the out dir
file_counter = 0
is_edit = False
for path in in_paths:
actual_in = Path(path)
"""Max attempts reached during looping."""
class PipelineDefinitionError(Error):
"""Pipeline definition incorrect. Likely a yaml error."""
class PipelineNotFoundError(Error):
"""Pipeline not found in working dir or in pypyr install dir."""
class PlugInError(Error):
"""Pypyr plug - ins should sub - class this."""
class PyModuleNotFoundError(Error, ModuleNotFoundError):
"""Could not load python module because it wasn't found."""
# -------------------------- Control of Flow Instructions ---------------------
class Stop(Error):
"""Control of flow. Stop all execution."""
class StopPipeline(Stop):
"""Control of flow. Stop current pipeline execution."""
class StopStepGroup(Stop):
"""Control of flow. Stop current step - group execution."""
"""pypyr context[key] doesn't have a value."""
class KeyNotInContextError(ContextError, KeyError):
"""Key not found in the pypyr context."""
def __str__(self):
"""KeyError has custom error formatting, avoid this behaviour."""
return super(Exception, self).__str__()
class LoopMaxExhaustedError(Error):
"""Max attempts reached during looping."""
class PipelineDefinitionError(Error):
"""Pipeline definition incorrect. Likely a yaml error."""
class PipelineNotFoundError(Error):
"""Pipeline not found in working dir or in pypyr install dir."""
class PlugInError(Error):
"""Pypyr plug - ins should sub - class this."""
class PyModuleNotFoundError(Error, ModuleNotFoundError):
"""Could not load python module because it wasn't found."""
# -------------------------- Control of Flow Instructions ---------------------