Exemplo n.º 1
0
def test_should_raise_if_docstring_configuration_file_not_found(work_dir):
    """
        Test should raise if docstring configuration file not found
    """
    docstring_conf_path = join(work_dir, 'not_found.yml')
    with pytest.raises(MlVToolConfException) as ex:
        load_docstring_conf(docstring_conf_path)
    assert isinstance(ex.value.__cause__, IOError)
Exemplo n.º 2
0
def test_should_raise_if_docstring_configuration_invalid_yaml(work_dir):
    """
        Test should raise if docstring configuration Yaml format is invalid
    """
    docstring_conf_path = join(work_dir, 'dc_conf.yml')
    with open(docstring_conf_path, 'w') as fd:
        fd.write('t\n\t\thhh')
    with pytest.raises(MlVToolConfException) as ex:
        load_docstring_conf(docstring_conf_path)
    assert isinstance(ex.value.__cause__, YAMLError)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
def test_should_load_docstring_configuration(work_dir):
    """
        Test load Yaml format docstring configuration
    """
    docstring_conf_path = join(work_dir, 'dc_conf.yml')
    with open(docstring_conf_path, 'w') as fd:
        fd.write('var1: ./ouptut_path.txt\nvar2: test')
    dc_conf = load_docstring_conf(docstring_conf_path)
    assert dc_conf == {'var1': './ouptut_path.txt',
                       'var2': 'test'}