# Path: datapackage_pipelines/manager/runners/local_python.py
# class LocalPythonRunner(BaseRunner):
# 
#     def get_execution_args(self, step, _, idx):
#         return [
#             sys.executable,
#             step['executor'],
#             str(idx),
#             json.dumps(step.get('parameters', {})),
#             str(step.get('validate', False)),
#             step.get('_cache_hash') if step.get('cache') else ''
#         ]
# 
# class WrappedPythonRunner(LocalPythonRunner):
# 
#     def get_execution_args(self, step, cwd, idx):
#         args = super(WrappedPythonRunner, self).get_execution_args(step, cwd, idx)
#         for i in range(len(args)):
#             args[i] = '\\\"' + args[i].replace('"', '\\\\\\\"') + '\\\"'
#         cmd = " ".join(args)
#         abspath = os.path.abspath(cwd)
#         cmd = self.parameters['wrapper'].format(path=cwd,
#                                                 abspath=abspath,
#                                                 cmd=cmd,
#                                                 env=os.environ)
#         args = shlex.split(cmd)
#         return args


import os
import yaml
from .local_python import LocalPythonRunner, WrappedPythonRunner



class RunnerConfiguration(object):

    ENV_VAR = 'DPP_RUNNER_CONFIG'
    DEFAULT_RUNNER_CONFIG = 'dpp-runners.yaml'

    def __init__(self):

        config_fn = os.environ.get(self.ENV_VAR, self.DEFAULT_RUNNER_CONFIG)
        if os.path.exists(config_fn):
            self.config = yaml.load(open(config_fn), Loader=yaml.Loader)
        else:
            self.config = {}

    def get_runner_class(self, kind):
        return {

# Path: datapackage_pipelines/manager/runners/local_python.py
# class LocalPythonRunner(BaseRunner):
# 
#     def get_execution_args(self, step, _, idx):
#         return [
#             sys.executable,
#             step['executor'],
#             str(idx),
#             json.dumps(step.get('parameters', {})),
#             str(step.get('validate', False)),
#             step.get('_cache_hash') if step.get('cache') else ''
#         ]
# 
# class WrappedPythonRunner(LocalPythonRunner):
# 
#     def get_execution_args(self, step, cwd, idx):
#         args = super(WrappedPythonRunner, self).get_execution_args(step, cwd, idx)
#         for i in range(len(args)):
#             args[i] = '\\\"' + args[i].replace('"', '\\\\\\\"') + '\\\"'
#         cmd = " ".join(args)
#         abspath = os.path.abspath(cwd)
#         cmd = self.parameters['wrapper'].format(path=cwd,
#                                                 abspath=abspath,
#                                                 cmd=cmd,
#                                                 env=os.environ)
#         args = shlex.split(cmd)
#         return args


# Path: datapackage_pipelines/manager/runners/runner_config.py
import os
import yaml
from .local_python import LocalPythonRunner, WrappedPythonRunner




class RunnerConfiguration(object):

    ENV_VAR = 'DPP_RUNNER_CONFIG'
    DEFAULT_RUNNER_CONFIG = 'dpp-runners.yaml'

    def __init__(self):

        config_fn = os.environ.get(self.ENV_VAR, self.DEFAULT_RUNNER_CONFIG)
        if os.path.exists(config_fn):
            self.config = yaml.load(open(config_fn), Loader=yaml.Loader)
        else:
            self.config = {}

    def get_runner_class(self, kind):
        return {

            'local-python': LocalPythonRunner,