diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4195077..64f6772 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,8 +4,11 @@ repos: hooks: - id: check-added-large-files - id: check-ast + # exclude because of jinja templates + exclude: \{\{cookiecutter.project_slug\}\}/.+\.py - id: check-merge-conflict - id: check-yaml + # exclude because of jinja templates exclude: \{\{cookiecutter.project_slug\}\}/.gitlab-ci.yml - id: end-of-file-fixer - id: mixed-line-ending diff --git a/{{cookiecutter.project_slug}}/notebooks/example.ipynb b/{{cookiecutter.project_slug}}/notebooks/example.ipynb index 1137af1..b1ae923 100644 --- a/{{cookiecutter.project_slug}}/notebooks/example.ipynb +++ b/{{cookiecutter.project_slug}}/notebooks/example.ipynb @@ -10,7 +10,28 @@ "To use your module `{{ cookiecutter.module_name }}` from here, run `pip install -e .` from the root of your project directory." {% endif %} ] - }, + },{% if cookiecutter.config_file != 'none' %} + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + {% if cookiecutter.config_file == 'yaml' %}"import os\n", + {% endif %}"import logging\n", + "from {{ cookiecutter.module_name }} import util\n", + "\n", + "logger = logging.getLogger(\"{{ cookiecutter.module_name }}\")\n", + "\n", + "config = util.load_config({% if cookiecutter.config_file == 'yaml' %}os.path.join(os.path.abspath(os.pardir),\n", + " \"config\",\n", + " \"config.yml\"){% endif %})\n", + "util.logging_setup(config)\n", + "\n", + "logger.info(\"Use this setup to start logging in notebooks or to \"+\n", + " \"get the correct logging format in your {{ cookiecutter.module_name }} module\")" + ] + },{% endif %} { "cell_type": "code", "execution_count": null, diff --git a/{{cookiecutter.project_slug}}/src/{{cookiecutter.module_name}}/main.py b/{{cookiecutter.project_slug}}/src/{{cookiecutter.module_name}}/main.py index 4d27bd2..c6532ef 100644 --- a/{{cookiecutter.project_slug}}/src/{{cookiecutter.module_name}}/main.py +++ b/{{cookiecutter.project_slug}}/src/{{cookiecutter.module_name}}/main.py @@ -1,7 +1,19 @@ +import logging + +from {{ cookiecutter.module_name }} import util + +logger = logging.getLogger('{{ cookiecutter.module_name }}') + def main(): + {% if cookiecutter.config_file != 'none' -%} + config = util.load_config({% if cookiecutter.config_file == 'yaml' %}'config/config.yml'{% else %}None{% endif %}) + util.logging_setup(config) + {% else -%} + logging.basicConfig(level=logging.INFO) + {% endif -%} + logger.info("Looks like you're all set up. Let's get going!") # TODO your journey starts here - print("hello :)") if __name__ == "__main__":