Пример #1
0
def remove_file(struct, opts):
    """Remove a file from the project tree representation if existent by our own

    Args:
        struct (dict): project representation as (possibly) nested
            :obj:`dict`.
        opts (dict): given options, see :obj:`create_project` for
            an extensive list.

    Returns:
        struct, opts: updated project representation and options
    """
    # file_path = [opts['project'], "requirements.txt"]
    # struct = helpers.reject(struct, file_path)
    # file_path = [opts['project'], "environment.yaml"]
    # struct = helpers.reject(struct, file_path)

    file_path = [opts['project'], "setup.cfg"]
    struct = helpers.reject(struct, file_path)
    file_path = [opts['project'], "setup.py"]
    struct = helpers.reject(struct, file_path)

    file_path = [opts['project'], "src", opts["package"], "__init__.py"]
    struct = helpers.reject(struct, file_path)

    file_path = [opts['project'], "docs", "conf.py"]
    struct = helpers.reject(struct, file_path)
    docs_conf = templates.sphinx_conf(opts)
    struct = helpers.ensure(struct, file_path, docs_conf, helpers.NO_OVERWRITE)

    return struct, opts
Пример #2
0
def test_reject():
    # When the original structure contain a leaf
    structure = {"a": {"b": {"c": "0"}}}
    # that is removed using the reject method,
    structure = helpers.reject(structure, ["a", "b", "c"])
    # then the structure should not contain the file
    assert "c" not in structure["a"]["b"]
Пример #3
0
def test_reject():
    # When the original structure contain a leaf
    structure = {"a": {"b": {"c": "0"}}}
    # that is removed using the reject method,
    structure = helpers.reject(structure, Path("a", "b", "c"))
    # then the structure should not contain the file
    assert "c" not in structure["a"]["b"]
Пример #4
0
def test_reject_without_ancestor():
    # Given a defined structure,
    structure = {"a": {"b": {"c": "0"}}}
    # when someone tries to remove a file using the reject method
    # but one of its ancestor does not exist in the structure,
    structure = helpers.reject(structure, "a/b/x/c")
    # then the structure should be the same
    assert structure["a"]["b"]["c"] == "0"
    assert len(structure["a"]["b"]["c"]) == 1
    assert len(structure["a"]["b"]) == 1
    assert len(structure["a"]) == 1
Пример #5
0
def test_reject_without_file():
    # Given a defined structure,
    structure = {"a": {"b": {"c": "0"}}}
    # when someone tries to remove a file using the reject method
    # but one of its ancestor does not exist in the structure,
    structure = helpers.reject(structure, "a/b/x")
    # then the structure should be the same
    assert structure["a"]["b"]["c"] == "0"
    assert len(structure["a"]["b"]["c"]) == 1
    assert len(structure["a"]["b"]) == 1
    assert len(structure["a"]) == 1
Пример #6
0
def add_dsproject(struct, opts):
    """Adds basic module for custom extension

    Args:
        struct (dict): project representation as (possibly) nested
            :obj:`dict`.
        opts (dict): given options, see :obj:`create_project` for
            an extensive list.

    Returns:
        struct, opts: updated project representation and options
    """
    gitignore_all = templates.gitignore_all(opts)

    path = [opts["project"], "data", ".gitignore"]
    struct = helpers.ensure(struct, path, templates.gitignore_data(opts),
                            helpers.NO_OVERWRITE)
    for folder in ('external', 'interim', 'preprocessed', 'raw'):
        path = [opts["project"], "data", folder, ".gitignore"]
        struct = helpers.ensure(struct, path, gitignore_all,
                                helpers.NO_OVERWRITE)

    path = [opts["project"], "notebooks", "template.ipynb"]
    template_ipynb = templates.template_ipynb(opts)
    struct = helpers.ensure(struct, path, template_ipynb, helpers.NO_OVERWRITE)

    path = [opts["project"], "scripts", "train_model.py"]
    train_model_py = templates.train_model_py(opts)
    struct = helpers.ensure(struct, path, train_model_py, helpers.NO_OVERWRITE)

    path = [opts["project"], "models", ".gitignore"]
    struct = helpers.ensure(struct, path, gitignore_all, helpers.NO_OVERWRITE)

    path = [opts["project"], "references", ".gitignore"]
    struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE)

    path = [opts["project"], "reports", "figures", ".gitignore"]
    struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE)

    path = [opts["project"], "environment.yaml"]
    environment_yaml = templates.environment_yaml(opts)
    struct = helpers.ensure(struct, path, environment_yaml,
                            helpers.NO_OVERWRITE)

    path = [opts["project"], "requirements.txt"]
    struct = helpers.reject(struct, path)

    path = [opts["project"], "configs", ".gitignore"]
    struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE)
    return struct, opts
Пример #7
0
def replace_readme(struct, opts):
    """Replace the readme.md of the markdown extension by our own

    Args:
        struct (dict): project representation as (possibly) nested
            :obj:`dict`.
        opts (dict): given options, see :obj:`create_project` for
            an extensive list.

    Returns:
        struct, opts: updated project representation and options
    """
    # let the markdown extension do its job first
    struct, opts = MarkDown("markdown").markdown(struct, opts)

    file_path = [opts["project"], "README.md"]
    struct = helpers.reject(struct, file_path)
    readme = templates.readme_md(opts)
    struct = helpers.ensure(struct, file_path, readme, helpers.NO_OVERWRITE)
    return struct, opts
Пример #8
0
def add_dsproject_vscode(struct, opts):
    """Adds basic module for custom extension

    Args:
        struct (dict): project representation as (possibly) nested
            :obj:`dict`.
        opts (dict): given options, see :obj:`create_project` for
            an extensive list.

    Returns:
        struct, opts: updated project representation and options
    """
    gitignore_all = templates.gitignore_all(opts)
    gitkeep = templates.gitkeep(opts)

    path = [opts["project"], "data", ".gitignore"]
    struct = helpers.ensure(struct, path, templates.gitignore_data(opts),
                            helpers.NO_OVERWRITE)
    for folder in ("external", "interim", "preprocessed", "raw"):
        path = [opts["project"], "data", folder, ".gitignore"]
        struct = helpers.ensure(struct, path, gitignore_all,
                                helpers.NO_OVERWRITE)

    path = [opts["project"], "data", "output", ".gitkeep"]
    struct = helpers.ensure(struct, path, gitkeep, helpers.NO_OVERWRITE)

    path = [opts["project"], "notebooks", "template.ipynb"]
    template_ipynb = templates.template_ipynb(opts)
    struct = helpers.ensure(struct, path, template_ipynb, helpers.NO_OVERWRITE)

    path = [opts["project"], "scripts", "train_model.py"]
    train_model_py = templates.train_model_py(opts)
    struct = helpers.ensure(struct, path, train_model_py, helpers.NO_OVERWRITE)

    path = [opts["project"], "models", ".gitignore"]
    struct = helpers.ensure(struct, path, gitignore_all, helpers.NO_OVERWRITE)

    path = [opts["project"], "references", ".gitignore"]
    struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE)

    path = [opts["project"], "reports", "figures", ".gitignore"]
    struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE)

    # path = [opts["project"], ".devcontainer", "devcontainer.json"]
    # devcontainer_json = templates.devcontainer_json(opts)
    # struct = helpers.ensure(struct, path, devcontainer_json, helpers.NO_OVERWRITE)

    path = [opts["project"], ".devcontainer", "devcontainer.local.json"]
    devcontainer_local_json = templates.devcontainer_local_json(opts)
    struct = helpers.ensure(struct, path, devcontainer_local_json,
                            helpers.NO_OVERWRITE)

    path = [opts["project"], ".devcontainer", "devcontainer.remote.json"]
    devcontainer_remote_json = templates.devcontainer_remote_json(opts)
    struct = helpers.ensure(struct, path, devcontainer_remote_json,
                            helpers.NO_OVERWRITE)

    path = [opts["project"], ".devcontainer", "Dockerfile.dev.base"]
    dockerfile_dev_base = templates.dockerfile_dev_base(opts)
    struct = helpers.ensure(struct, path, dockerfile_dev_base,
                            helpers.NO_OVERWRITE)

    path = [opts["project"], ".vscode", "settings.json"]
    settings_json = templates.settings_json(opts)
    struct = helpers.ensure(struct, path, settings_json, helpers.NO_OVERWRITE)

    path = [opts["project"], "environment.dev.base.yml"]
    environment_dev_base_yml = templates.environment_dev_base_yml(opts)
    struct = helpers.ensure(struct, path, environment_dev_base_yml,
                            helpers.NO_OVERWRITE)

    path = [opts["project"], "docker-compose.yml"]
    docker_compose_yml = templates.docker_compose_yml(opts)
    struct = helpers.ensure(struct, path, docker_compose_yml,
                            helpers.NO_OVERWRITE)

    path = [opts["project"], "docker-compose.remote.yml"]
    docker_compose_remote_yml = templates.docker_compose_remote_yml(opts)
    struct = helpers.ensure(struct, path, docker_compose_remote_yml,
                            helpers.NO_OVERWRITE)

    path = [opts["project"], "path.env"]
    path_env = templates.path_env(opts)
    struct = helpers.ensure(struct, path, path_env, helpers.NO_OVERWRITE)

    path = [opts["project"], "requirements.txt"]
    struct = helpers.reject(struct, path)

    path = [opts["project"], "configs", ".gitignore"]
    struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE)
    return struct, opts