def add_custom_extension_structure(self, struct, opts): custom_extension_file_content = extension(self.get_class_name_from_opts(opts)) filename = "{}.py".format(opts["package"]) struct = helpers.ensure(struct, [opts["project"], "src", opts["package"], filename], custom_extension_file_content, helpers.NO_OVERWRITE) struct = helpers.ensure(struct, [opts["project"], "setup.py"], setup(opts), helpers.NO_OVERWRITE) return struct, opts
def add_files(struct, opts): print("inside opts", opts) nov, ncr = helpers.NO_OVERWRITE, helpers.NO_CREATE struct = helpers.ensure(struct, "proj/tests/file0", "new") struct = helpers.ensure(struct, "proj/tests/file1", "new", nov) struct = helpers.ensure(struct, "proj/tests/file2", "new", ncr) struct = helpers.merge(struct, { "proj": {"tests": {"file3": ("new", nov), "file4": ("new", ncr), "file5": ("new", None), "file6": "new"}} }) return struct, opts
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
def test_ensure_overriden(): # When the original structure contains a leaf structure = {"a": {"b": "0"}} # that is overridden using the ensure method, structure = helpers.ensure(structure, Path("a", "b"), content="1") # and the file content should be overridden assert structure["a"]["b"] == "1"
def test_ensure_overriden(): # When the original structure contains a leaf structure = {"a": {"b": "0"}} # that is overridden using the ensure method, structure = helpers.ensure(structure, ["a", "b"], content="1") # and the file content should be overridden assert structure["a"]["b"] == "1"
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
def add_files(struct, opts): nov, ncr = helpers.NO_OVERWRITE, helpers.NO_CREATE struct = helpers.ensure(struct, "proj/tests/file0", "new") struct = helpers.ensure(struct, "proj/tests/file1", "new", nov) struct = helpers.ensure(struct, "proj/tests/file2", "new", ncr) struct = helpers.merge( struct, { "proj": { "tests": { "file3": ("new", nov), "file4": ("new", ncr), "file5": ("new", None), "file6": "new" } } }) return struct, opts
def add_files(struct, opts): struct = helpers.ensure(struct, "proj/tests/extra.file", "content") struct = helpers.merge( struct, {"proj": { "tests": { "another.file": "content" } }}) return struct, opts
def test_ensure_nested(): # When the original structure does not contain a leaf structure = {"a": {"b": "0"}} # that is added using the ensure method, structure = helpers.ensure(structure, Path("a", "c", "d", "e", "f"), content="1") # then all the necessary parent folder should be included assert isinstance(structure["a"]["c"], dict) assert isinstance(structure["a"]["c"]["d"], dict) assert isinstance(structure["a"]["c"]["d"]["e"], dict) # and the file itself assert structure["a"]["c"]["d"]["e"]["f"] == "1"
def test_ensure_nested(): # When the original structure does not contain a leaf structure = {"a": {"b": "0"}} # that is added using the ensure method, structure = helpers.ensure(structure, ["a", "c", "d", "e", "f"], content="1") # then all the necessary parent folder should be included assert isinstance(structure["a"]["c"], dict) assert isinstance(structure["a"]["c"]["d"], dict) assert isinstance(structure["a"]["c"]["d"]["e"], dict) # and the file itself assert structure["a"]["c"]["d"]["e"]["f"] == "1"
def add_pyproject_toml(self, struct, opts): """Add the pyproject.toml file 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 = [opts['project'], 'pyproject.toml'] content = pyproject_toml(opts) struct = helpers.ensure(struct, file, content) return struct, opts
def add_readme(struct, opts): """Adds README template 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_content = templates.readme(opts) path = [opts["project"], "README.rst"] struct = helpers.ensure(struct, path, file_content, helpers.NO_OVERWRITE) return struct, opts
def add_test_custom_extension(struct, opts): """Adds tests/test_custom_extension.py 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_content = templates.test_custom_extension(opts) path = [opts["project"], "tests", "test_custom_extension.py"] struct = helpers.ensure(struct, path, file_content, helpers.NO_OVERWRITE) return struct, opts
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
def add_custom_extension_structure(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 """ custom_extension_file_content = templates.extension(opts) filename = "{}.py".format(EXTENSION_FILE_NAME) path = [opts["project"], "src", opts["package"], filename] struct = helpers.ensure(struct, path, custom_extension_file_content, helpers.NO_OVERWRITE) return struct, opts
def test_ensure_path(): # When the ensure method is called with an string path structure = {} structure = helpers.ensure(structure, "a/b/c/d", content="1") # Then the effect should be the same as if it were split assert structure["a"]["b"]["c"]["d"] == "1"
def add_files(struct, opts): struct = helpers.ensure(struct, "proj/tests/extra.file", "content") struct = helpers.merge(struct, { "proj": {"tests": {"another.file": "content"}}}) return struct, opts
def test_ensure_path(): # When the ensure method is called with an string path structure = {} structure = helpers.ensure(structure, "a/b/c/d", content="1") # Then the effect should be the same as if it were split assert structure["a"]["b"]["c"]["d"] == "1"
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
def add_beeproject(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"], ".gitignore"] struct = helpers.ensure(struct, path, gitignore_all, helpers.NO_OVERWRITE) path = [opts["project"], "data", ".gitignore"] struct = helpers.ensure(struct, path, templates.gitignore_data(opts), 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"], "models", ".gitignore"] struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE) #### custom package #### # path = [opts["project"], "src", opts['package'], "__init__.py"] # init = templates.init(opts) # struct = helpers.ensure(struct, path, # init, # helpers.NO_OVERWRITE) path = [opts["project"], "src", opts["package"], "README.md"] project_readmd = templates.package_readme(opts) struct = helpers.ensure(struct, path, project_readmd, helpers.NO_OVERWRITE) path = [opts["project"], "src", opts["package"], "requirements.txt"] struct = helpers.ensure(struct, path) path = [opts["project"], "src", opts["package"], "run_temp_pkg.py"] run_project_main = templates.run_project_main(opts) struct = helpers.ensure(struct, path, run_project_main, helpers.NO_OVERWRITE) path = [opts["project"], "src", opts["package"], "supervisor_temp_pkg.ini"] supervisor_ini = templates.supervisor_ini(opts) struct = helpers.ensure(struct, path, supervisor_ini, helpers.NO_OVERWRITE) path = [opts["project"], "src", opts['package'], 'temp_pkg', "__init__.py"] init = templates.project_init(opts) struct = helpers.ensure(struct, path, init, helpers.NO_OVERWRITE) path = [opts["project"], "src", opts["package"], ".env.example"] struct = helpers.ensure(struct, path) path = [opts["project"], "src", opts["package"], 'temp_pkg', "settings.py"] settings = templates.settings(opts) struct = helpers.ensure(struct, path, settings, helpers.NO_OVERWRITE) path = [opts["project"], "src", opts["package"], 'temp_pkg', "manage.py"] project_manage = templates.manage(opts) struct = helpers.ensure(struct, path, project_manage, helpers.NO_OVERWRITE) path = [opts["project"], "src", opts["package"], 'temp_pkg', "_log.py"] log = templates.project_logger(opts) struct = helpers.ensure(struct, path, log, helpers.NO_OVERWRITE) path = [ opts["project"], "src", opts["package"], 'temp_pkg', "submodule", "__init__.py" ] init = templates.init(opts) struct = helpers.ensure(struct, path, init, helpers.NO_OVERWRITE) path = [ opts["project"], "src", opts["package"], 'temp_pkg', "submodule", "settings.py" ] subsettings = templates.subsettings(opts) struct = helpers.ensure(struct, path, subsettings, helpers.NO_OVERWRITE) path = [ opts["project"], "src", opts["package"], 'temp_pkg', "submodule", "manage.py" ] submanage = templates.submanage(opts) struct = helpers.ensure(struct, path, submanage, helpers.NO_OVERWRITE) return struct, opts