コード例 #1
0
ファイル: ipynb_to_dvc.py プロジェクト: peopledoc/mlvtools
    def run(self, *args, **kwargs):
        args = ArgumentBuilder(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                               description='Convert Notebook to python script') \
            .add_work_dir_argument() \
            .add_conf_path_argument() \
            .add_docstring_conf() \
            .add_force_argument() \
            .add_argument('-n', '--notebook', type=str, required=True,
                          help='The notebook to convert') \
            .parse(args)
        self.set_log_level(args)
        conf = self.get_conf(args.working_directory, args.notebook,
                             args.conf_path)
        if not conf.path:
            raise MlVToolException('Configuration file is mandatory')
        docstring_conf_path = args.docstring_conf or conf.docstring_conf
        docstring_conf = load_docstring_conf(
            docstring_conf_path) if docstring_conf_path else None

        output_script = get_script_output_path(args.notebook, conf)
        out_dvc_cmd = get_dvc_cmd_output_path(output_script, conf)
        self.check_force(args.force, [output_script, out_dvc_cmd])

        export_to_script(args.notebook, output_script, conf)
        gen_dvc_command(output_script, out_dvc_cmd, conf, docstring_conf)
コード例 #2
0
ファイル: gen_dvc.py プロジェクト: peopledoc/mlvtools
    def run(self, *args, **kwargs):
        args = ArgumentBuilder(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                               description='Generate python script wrappers') \
            .add_work_dir_argument() \
            .add_conf_path_argument() \
            .add_force_argument() \
            .add_docstring_conf() \
            .add_path_argument('-i', '--input-script', type=str, required=True,
                               help='The python input script') \
            .add_path_argument('-o', '--out-dvc-cmd', type=str,
                               help='Path to the generated bash dvc command') \
            .parse(args)

        self.set_log_level(args)
        conf = self.get_conf(args.working_directory, args.input_script,
                             args.conf_path)
        docstring_conf_path = args.docstring_conf or conf.docstring_conf

        if not conf.path and not args.out_dvc_cmd:
            raise MlVToolException(
                'Parameter --out-dvc-cmd is mandatory if no conf provided')

        docstring_conf = load_docstring_conf(
            docstring_conf_path) if docstring_conf_path else None
        out_dvc_cmd = args.out_dvc_cmd or get_dvc_cmd_output_path(
            args.input_script, conf)
        self.check_force(args.force, [out_dvc_cmd])
        gen_dvc_command(args.input_script, out_dvc_cmd, conf, docstring_conf)
コード例 #3
0
ファイル: test_conf.py プロジェクト: peopledoc/mlvtools
def test_should_load_conf_file(work_dir):
    """ Test load valid conf file """

    conf_file = join(work_dir, '.mlvtools')
    write_conf(work_dir=work_dir, conf_path=conf_file, ignore_keys=['# No effect', "# Ignore"],
               script_dir='./scripts', dvc_cmd_dir='./dvc_cmd',
               dvc_py_cmd_name='VAR_Name', dvc_py_cmd_path='var_PATh3',
               dvc_meta_file_name='mETA_VAR_NaME')

    conf = load_conf_or_default(conf_file, working_directory=work_dir)

    assert conf.path.python_script_root_dir == './scripts'
    assert conf.path.dvc_cmd_root_dir == './dvc_cmd'
    assert '# No effect' in conf.ignore_keys
    assert '# Ignore' in conf.ignore_keys
    assert conf.dvc_var_python_cmd_path == 'var_PATh3'
    assert conf.dvc_var_python_cmd_name == 'VAR_Name'
    assert conf.dvc_var_meta_filename == 'mETA_VAR_NaME'

    script_path = join(conf.path.python_script_root_dir, 'mlvtools_pipeline_part1.py')
    assert get_script_output_path('./data/Pipeline Part1.ipynb', conf) == join(work_dir, script_path)
    dvc_cmd_path = join(conf.path.dvc_cmd_root_dir, 'pipeline_part1_dvc')
    assert get_dvc_cmd_output_path('./data/pipeline_part1.py', conf) == join(work_dir, dvc_cmd_path)