Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 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):
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",
}
}
},
)
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
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)
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