Esempio n. 1
0
def load_configs_from_directory(root: Path,
                                overwrite: bool = True,
                                force_data: bool = False) -> None:
    """
    Load all the examples from a given directory.
    """
    contents: Dict[str, str] = {}
    queue = [root]
    while queue:
        path_name = queue.pop()
        if path_name.is_dir():
            queue.extend(path_name.glob("*"))
        elif path_name.suffix.lower() in YAML_EXTENSIONS:
            with open(path_name) as fp:
                contents[str(path_name.relative_to(root))] = fp.read()

    # removing "type" from the metadata allows us to import any exported model
    # from the unzipped directory directly
    metadata = yaml.load(contents.get(METADATA_FILE_NAME, "{}"))
    if "type" in metadata:
        del metadata["type"]
    contents[METADATA_FILE_NAME] = yaml.dump(metadata)

    command = ImportExamplesCommand(contents,
                                    overwrite=overwrite,
                                    force_data=force_data)
    try:
        command.run()
    except CommandInvalidError as ex:
        _logger.error("An error occurred: %s", ex.normalized_messages())
Esempio n. 2
0
def load_from_configs(force_data: bool = False,
                      load_test_data: bool = False) -> None:
    contents = load_contents(load_test_data)
    command = ImportExamplesCommand(contents,
                                    overwrite=True,
                                    force_data=force_data)
    command.run()
Esempio n. 3
0
def load_examples_from_configs(force_data: bool = False,
                               load_test_data: bool = False) -> None:
    """
    Load all the examples inside superset/examples/configs/.
    """
    contents = load_contents(load_test_data)
    command = ImportExamplesCommand(contents,
                                    overwrite=True,
                                    force_data=force_data)
    command.run()
Esempio n. 4
0
def load_from_configs() -> None:
    contents = load_contents()
    command = ImportExamplesCommand(contents, overwrite=True)
    command.run()