コード例 #1
0
ファイル: executor.py プロジェクト: mintproject/dame_cli
def build_command_line(resource, _dir):
    line = './run '
    setup_name = obtain_id(resource.id)
    inputs = resource.has_input
    try:
        parameters = resource.has_parameter
    except:
        parameters = None
    outputs = resource.has_output
    component_url = resource.has_component_location[0]
    software_image = resource.has_software_image
    if software_image:
        has_software_image = software_image[0].label[0]
    else:
        raise ValueError("Software is not available")
    component_dir = download_extract_zip(component_url, _dir)
    path = Path(component_dir)
    src_path = path / "src"
    if inputs:
        l = build_input(inputs, src_path)
        line += " {}".format(l)
    if outputs:
        l = build_output(outputs)
        line += " {}".format(l)
    if parameters is not None:
        l = build_parameter(parameters)
        line += " {}".format(l)
    return has_software_image, line, src_path
コード例 #2
0
ファイル: executor.py プロジェクト: mintproject/dame_cli
def prepare_execution(setup_path):
    """
    Create the execution directory and call the method to get the inputs and execution line
    :param setup_path: the path of the YAML file
    :type setup_path: Path
    :return:
        - src_path: (:py:class:`Path`) - Path component source directory
        - execution_dir: (:py:class:`Path`) - Path execution directory
        - setup_cmd_line: (:py:class:`Path`) - The execution line (./run)
        - setup_name: (:py:class:`Path`) - The name of setup
        - image: (:py:class:`Path`) - The name of the image
    """
    _dir = Path("%s/" % EXECUTION_DIRECTORY)
    _dir.mkdir(parents=True, exist_ok=True)
    setup_dict = load(setup_path.open(), Loader=Loader)
    setup_name = obtain_id(setup_dict.id)
    execution_dir = "{}/{}_{}".format(_dir, setup_name, uuid.uuid1())
    execution_dir_path = Path(execution_dir)
    execution_dir_path.mkdir(parents=True, exist_ok=True)

    try:
        image, setup_cmd_line, src_path = build_command_line(
            setup_dict, execution_dir_path)
    except Exception as e:
        raise e
    return src_path, execution_dir, setup_cmd_line, setup_name, image
コード例 #3
0
ファイル: cli_methods.py プロジェクト: mintproject/dame_cli
def verify_input_parameters(model_configuration,
                            interactive,
                            data_dir,
                            profile=None):
    profile_cmd = f"-p {profile}" if profile else ""
    if model_configuration.has_input is None:
        return []
    print_disabled_data_option(data_dir)
    for _input in model_configuration.has_input:
        uri = None
        if (not hasattr(_input, "has_fixed_resource")
                or _input.has_fixed_resource is None) and interactive:
            if hasattr(_input, "label") and hasattr(_input, "has_format"):
                extension = _input.has_format[0]
                extension = re.sub(r'^\.', '', extension)
                click.secho("To run this model configuration,"
                            "a {} file (.{} file) is required.".format(
                                _input.label[0], extension),
                            fg="yellow")
            elif hasattr(_input, "label"):
                click.secho(
                    "To run this model configuration, a {} file is required.".
                    format(_input.label[0]),
                    fg="yellow")
            else:
                click.secho(
                    "To run this model configuration, a {} file is required.".
                    format(_input.id),
                    fg="yellow")
            if data_dir and hasattr(_input, "has_format"):
                click.secho(
                    "Searching local files in the {}\n"
                    "You can change the target directory using the option -d or --data"
                )

                uri = find_file_directory(data_dir, extension)

            dataset_transformations = get_transformation_dataset(
                obtain_id(_input.id), profile=profile)
            if profile and dataset_transformations:
                click.secho(
                    "There are transformations available for this input. To use them, please exit and type",
                    fg="blue")
                click.secho(
                    f"$ dame transformation list {obtain_id(_input.id)}  {profile_cmd}",
                    fg="blue")

            if uri is None:
                uri = click.prompt('Please enter a url')
                uri = uri.replace(" ", '')
                while not url_validation(uri):
                    uri = click.prompt('Please enter a url')

            create_sample_resource(_input, uri)
        elif not hasattr(_input, "has_fixed_resource") and not interactive:
            raise ValueError("Missing information")
    click.secho(
        "The information needed to run the model is complete, and I can execute the model as follows:",
        fg="green")
    return model_configuration
コード例 #4
0
    def put(self, request):
        model_id = obtain_id(request.id)
        api, username = get_api(profile=self.profile)
        api_instance = modelcatalog.ModelApi(api)
        model = Model(**request) if isinstance(request, dict) else request

        try:
            # Update a Model
            return api_instance.models_id_put(model_id, username, model=model)
        except ApiException as e:
            print("Exception when calling ModelApi->models_id_put: %s\n" % e)
コード例 #5
0
def test_print_table_list():
    model_configurations = [
        get_model_configuration(CONFIG_PARTIAL_INFO, profile=testing)
    ]
    setups = [
        get_setup(obtain_id(SETUP_PARTIAL_INFO), profile=testing),
        get_setup(SETUP_FULL_INFO, profile=testing)
    ]

    print_table_list(setups)
    print_table_list(model_configurations)
コード例 #6
0
ファイル: cli_methods.py プロジェクト: mintproject/dame_cli
def print_table_list(items):
    headings = ['Id', 'Description']
    tab = tt.Texttable()
    tab.header(headings)
    for item in items:
        _id = obtain_id(item.id)
        _label = "".join(item.label) if hasattr(item, "label") and getattr(
            item, "label") else "No information"
        _description = "".join(item.description) if hasattr(
            item, "description") and getattr(item, "description") else _label
        tab.add_row([_id, _description])
    print(tab.draw())
コード例 #7
0
def test_print_data_property_table():
    setups = [
        get_setup(obtain_id(SETUP_PARTIAL_INFO), profile=testing),
        get_setup(SETUP_FULL_INFO, profile=testing)
    ]
    model_configurations = [
        get_model_configuration(CONFIG_PARTIAL_INFO, profile=testing)
    ]

    for setup in setups:
        print_data_property_table(setup)
    for model_configuration in model_configurations:
        print_data_property_table(model_configuration)
コード例 #8
0
def step8(mic_file, profile):
    """
    Publish your model into the Model Catalog

    Example:
    mic encapsulate step8 -f <mic_file>
    """
    mic_config_path = Path(mic_file)
    model_configuration = create_model_catalog_resource(Path(mic_file),
                                                        allow_local_path=False)

    api_response_model, api_response_mc = publish_model_configuration(
        model_configuration, profile)
    click.echo(
        "You can run or see the details using DAME. More info at https://dame-cli.readthedocs.io/en/latest/"
    )
    click.echo("For example, you can run it using:\ndame run {}".format(
        obtain_id(api_response_mc.id)))
    write_spec(mic_config_path, STEP_KEY, 8)
コード例 #9
0
def test_show_model_configuration_details():
    model_configurations = [
        get_model_configuration(CONFIG_PARTIAL_INFO, profile=testing)
    ]
    setups = [
        get_setup(obtain_id(SETUP_PARTIAL_INFO), profile=testing),
        get_setup(SETUP_FULL_INFO, profile=testing)
    ]

    for setup in setups:
        try:
            show_model_configuration_details(setup)
        except AttributeError:
            pass

    for model_configuration in model_configurations:
        try:
            show_model_configuration_details(model_configuration)
        except AttributeError:
            pass
コード例 #10
0
ファイル: cli_methods.py プロジェクト: mintproject/dame_cli
def run_method_setup(setup, interactive, data_dir):
    """
    Call download_setup(): Download the setup(s) as yaml file
    Call execute_setup(): Read the yaml file and execute
    """
    try:
        name = obtain_id(setup.id)
        file_path = create_yaml_from_resource(resource=setup,
                                              name=name,
                                              output=Path('.'))
        if check_if_cwl_compatible(setup):
            run_cwl(setup, file_path.parent)
            exit(0)

        else:
            component_src_dir, execution_dir, setup_cmd_line, setup_name, image = prepare_execution(
                file_path)

    except ApiException as e:
        click.secho("Unable to download the setup {}".format(e), fg="red")
        exit(1)

    try:
        execute_setups(component_src_dir, execution_dir, setup_cmd_line,
                       setup_name, image, interactive)
        click.secho(
            "[{}] The execution has been successful".format(setup_name),
            fg="green")
        click.secho("[{}] Results available at: {} ".format(
            setup_name, component_src_dir),
                    fg="green")
    except Exception as e:
        log.error(e, exc_info=True)
        click.secho("[{}] The execution has failed".format(setup_name),
                    fg="red")
        exit(1)
コード例 #11
0
ファイル: test_utils.py プロジェクト: mintproject/dame_cli
 def test_obtain_id(self):
     url = "https://w3id.org/okn/i/mint/cycles-0.10.2-alpha-collection-oromia-single-point"
     assert obtain_id(
         url) == "cycles-0.10.2-alpha-collection-oromia-single-point"