From c0dc7820acdfc4ac1f14e4bc7be1dd38b5ebe865 Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Sun, 18 Aug 2019 18:46:02 +0200 Subject: [PATCH] Add .gitignore also in data --- src/pyscaffoldext/dsproject/extension.py | 4 ++++ .../dsproject/templates/__init__.py | 18 ++++++++++++++++++ .../templates/environment_yaml.template | 2 +- .../templates/gitignore_data.template | 8 ++++++++ .../templates/template_ipynb.template | 3 +++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/pyscaffoldext/dsproject/templates/gitignore_data.template diff --git a/src/pyscaffoldext/dsproject/extension.py b/src/pyscaffoldext/dsproject/extension.py index 4cb90f8..f347d63 100644 --- a/src/pyscaffoldext/dsproject/extension.py +++ b/src/pyscaffoldext/dsproject/extension.py @@ -74,6 +74,10 @@ def add_dsproject(struct, opts): """ 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, diff --git a/src/pyscaffoldext/dsproject/templates/__init__.py b/src/pyscaffoldext/dsproject/templates/__init__.py index d4bd0a2..2037a75 100644 --- a/src/pyscaffoldext/dsproject/templates/__init__.py +++ b/src/pyscaffoldext/dsproject/templates/__init__.py @@ -21,6 +21,8 @@ def get_template(name): def gitignore_all(opts): """gitignore file that ignores just everything + Ignore everything except of this gitignore file. + Args: opts (dict): given options, see :obj:`create_project` for an extensive list. @@ -32,6 +34,22 @@ def gitignore_all(opts): return template.safe_substitute(opts) +def gitignore_data(opts): + """gitignore file that ignores almost everything + + Ignore everything except of gitignore also in sub directories. + + Args: + opts (dict): given options, see :obj:`create_project` for + an extensive list. + + Returns: + str: file content as string + """ + template = get_template("gitignore_data") + return template.safe_substitute(opts) + + def environment_yaml(opts): """Environment.yaml with some basic libraries diff --git a/src/pyscaffoldext/dsproject/templates/environment_yaml.template b/src/pyscaffoldext/dsproject/templates/environment_yaml.template index 0ddf8bd..363c417 100644 --- a/src/pyscaffoldext/dsproject/templates/environment_yaml.template +++ b/src/pyscaffoldext/dsproject/templates/environment_yaml.template @@ -20,7 +20,7 @@ dependencies: - scikit-learn - pytorch - pip: - # add here only pip-packages that are not available in conda-forge! E.g.: + # add here only pip-packages that are not available in conda/conda-forge! E.g.: - optuna # for development only (could also be kept in a separate environment file) - jupyterlab diff --git a/src/pyscaffoldext/dsproject/templates/gitignore_data.template b/src/pyscaffoldext/dsproject/templates/gitignore_data.template new file mode 100644 index 0000000..48db540 --- /dev/null +++ b/src/pyscaffoldext/dsproject/templates/gitignore_data.template @@ -0,0 +1,8 @@ +# Ignore everything in this directory +* +# Except this file and .gitignore in sub directories +!.gitignore +!raw +!external +!preprocessed +!interim diff --git a/src/pyscaffoldext/dsproject/templates/template_ipynb.template b/src/pyscaffoldext/dsproject/templates/template_ipynb.template index 1cda010..a181e18 100644 --- a/src/pyscaffoldext/dsproject/templates/template_ipynb.template +++ b/src/pyscaffoldext/dsproject/templates/template_ipynb.template @@ -6,8 +6,11 @@ "metadata": {}, "outputs": [], "source": [ + "import os\n", "import sys\n", + "import math\n", "import logging\n", + "from pathlib import Path\n", "\n", "import numpy as np\n", "import scipy as sp\n",