From 8b4fa9c187c786907991671758aaccf9b3c308de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20B=C3=B6hm?= Date: Fri, 20 Aug 2021 16:53:13 +0200 Subject: [PATCH 1/4] Use dev and prod configs instead of debug for hocon option --- hooks/post_gen_project.py | 7 ++++--- tests/test_options.py | 4 ++-- .../config/{debug.conf => dev.conf} | 1 + {{cookiecutter.project_slug}}/config/prod.conf | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) rename {{cookiecutter.project_slug}}/config/{debug.conf => dev.conf} (52%) create mode 100644 {{cookiecutter.project_slug}}/config/prod.conf diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 4c14940..e80176c 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -64,14 +64,15 @@ files_config_hocon = [ f'{module_dir}/util__hocon.py', f'{module_dir}/res/default.conf', - 'config/debug.conf', + 'config/dev.conf', + 'config/prod.conf', ] files_ci_gitlab = { ".gitlab-ci.yml", } -files_ci_all = files_ci_gitlab +files_ci_all = files_ci_gitlab folders_editor = [ '.idea__editor', @@ -165,7 +166,7 @@ def handle_editor_settings(): def handle_ci(): ci_pipeline = '{{ cookiecutter.ci_pipeline }}' - if ci_pipeline == "gitlab": + if ci_pipeline == "gitlab": _delete_files(files_ci_all - files_ci_gitlab) elif ci_pipeline == 'none': _delete_files(files_ci_all) diff --git a/tests/test_options.py b/tests/test_options.py index 83ed6cf..6783bc5 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -83,7 +83,7 @@ def test_config_hocon(): check_project( settings={'config_file': 'hocon', 'create_cli': 'yes'}, files_existent=['src/{module_name}/util.py', 'src/{module_name}/res/default.conf', - 'config/debug.conf'], + 'config/dev.conf', 'config/prod.conf'], files_non_existent=['config/config.yml'], test_cli=True, run_pytest=True) @@ -92,7 +92,7 @@ def test_config_yaml(): check_project( settings={'config_file': 'yaml'}, files_existent=['src/{module_name}/util.py', 'config/config.yml'], - files_non_existent=['config/debug.conf', 'src/{module_name}/res/default.conf'], + files_non_existent=['config/dev.conf', 'config/prod.conf', 'src/{module_name}/res/default.conf'], run_pytest=True) diff --git a/{{cookiecutter.project_slug}}/config/debug.conf b/{{cookiecutter.project_slug}}/config/dev.conf similarity index 52% rename from {{cookiecutter.project_slug}}/config/debug.conf rename to {{cookiecutter.project_slug}}/config/dev.conf index 5d668c9..e99d3eb 100644 --- a/{{cookiecutter.project_slug}}/config/debug.conf +++ b/{{cookiecutter.project_slug}}/config/dev.conf @@ -1 +1,2 @@ +environment = "dev" logging.level = DEBUG diff --git a/{{cookiecutter.project_slug}}/config/prod.conf b/{{cookiecutter.project_slug}}/config/prod.conf new file mode 100644 index 0000000..23a817b --- /dev/null +++ b/{{cookiecutter.project_slug}}/config/prod.conf @@ -0,0 +1 @@ +environment = "prod" From 3650cb2d19f5cc3c91114a6bf7543a7e4b6ffd78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20B=C3=B6hm?= Date: Fri, 22 Oct 2021 16:24:05 +0200 Subject: [PATCH 2/4] Update description of hocon config in Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd7e5de..3b93cf8 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Unfortunately, cookiecutter does not allow us to show any description of the opt * `create_cli` (yes or no): if you plan to build an application with a command line interface (CLI), select *yes* here. This will integrate a template for the CLI into your project - minimal boilerplate guaranteed! (We're leveraging the awesome [typer](https://typer.tiangolo.com/) library for this.) * `config_file`: select your preferred config format. It is best practice to store your configuration separate from your code, even for small projects, but because there are a gazillion ways to do this, each project seems to reinvents the wheel. We want to provide a few options to set you up with a working configuration: - `yaml`: use [YAML](https://yaml.org/) as your configuration file format. Easy to read and write, widely adopted, relies on the [PyYAML](https://pyyaml.org/) package. - - `hocon`: use [HOCON](https://github.com/lightbend/config/blob/master/HOCON.md) as your configuration file format. It is a superset of JSON, very resilient (it's really hard to make a breaking syntax error) and comes with powerful functions, e.g. for inheritance or variable substitution. Relies on the [pyhocon](https://github.com/chimpler/pyhocon/) package. + - `hocon`: use [HOCON](https://github.com/lightbend/config/blob/master/HOCON.md) as your configuration file format. It is a superset of JSON, very resilient (it's really hard to make a breaking syntax error) and comes with powerful functions, e.g. for inheritance or variable substitution. In this example you can find two environment configurations (`dev.conf`, `prod.conf`) that can are overriding parts of the default configuration. Relies on the [pyhocon](https://github.com/chimpler/pyhocon/) package. - `none`: don't need any configuration or want to do your own thing? choose this option. * `code_formatter`: a code formatter is a powerful tool that can help teams to stick to a common code style. However, a formatter cannot solve every code style problem for you and it may lead to issues for users that are not aware of how it works. Always talk to your team about [PEP 8](https://www.python.org/dev/peps/pep-0008/) and a common code style, then choose the right formatter for you (or none at all): - [`black`](https://github.com/psf/black): *the uncompromising Python code formatter*. From 2e0f7c44c891071df5939cc474ee552d78ffe4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20B=C3=B6hm?= Date: Fri, 22 Oct 2021 16:27:27 +0200 Subject: [PATCH 3/4] Add comment to the log level override in dev.conf --- {{cookiecutter.project_slug}}/config/dev.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/config/dev.conf b/{{cookiecutter.project_slug}}/config/dev.conf index e99d3eb..664f55e 100644 --- a/{{cookiecutter.project_slug}}/config/dev.conf +++ b/{{cookiecutter.project_slug}}/config/dev.conf @@ -1,2 +1,2 @@ environment = "dev" -logging.level = DEBUG +logging.level = DEBUG # overrides the log level that is specified in res/default.conf From be48d2daacf43f0b9cc6a49fe762bfa9b569b958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20B=C3=B6hm?= Date: Fri, 22 Oct 2021 16:28:35 +0200 Subject: [PATCH 4/4] Fix typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b93cf8..571ab9c 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Unfortunately, cookiecutter does not allow us to show any description of the opt * `create_cli` (yes or no): if you plan to build an application with a command line interface (CLI), select *yes* here. This will integrate a template for the CLI into your project - minimal boilerplate guaranteed! (We're leveraging the awesome [typer](https://typer.tiangolo.com/) library for this.) * `config_file`: select your preferred config format. It is best practice to store your configuration separate from your code, even for small projects, but because there are a gazillion ways to do this, each project seems to reinvents the wheel. We want to provide a few options to set you up with a working configuration: - `yaml`: use [YAML](https://yaml.org/) as your configuration file format. Easy to read and write, widely adopted, relies on the [PyYAML](https://pyyaml.org/) package. - - `hocon`: use [HOCON](https://github.com/lightbend/config/blob/master/HOCON.md) as your configuration file format. It is a superset of JSON, very resilient (it's really hard to make a breaking syntax error) and comes with powerful functions, e.g. for inheritance or variable substitution. In this example you can find two environment configurations (`dev.conf`, `prod.conf`) that can are overriding parts of the default configuration. Relies on the [pyhocon](https://github.com/chimpler/pyhocon/) package. + - `hocon`: use [HOCON](https://github.com/lightbend/config/blob/master/HOCON.md) as your configuration file format. It is a superset of JSON, very resilient (it's really hard to make a breaking syntax error) and comes with powerful functions, e.g. for inheritance or variable substitution. In this example you can find two environment configurations (`dev.conf`, `prod.conf`) that override parts of the default configuration. Relies on the [pyhocon](https://github.com/chimpler/pyhocon/) package. - `none`: don't need any configuration or want to do your own thing? choose this option. * `code_formatter`: a code formatter is a powerful tool that can help teams to stick to a common code style. However, a formatter cannot solve every code style problem for you and it may lead to issues for users that are not aware of how it works. Always talk to your team about [PEP 8](https://www.python.org/dev/peps/pep-0008/) and a common code style, then choose the right formatter for you (or none at all): - [`black`](https://github.com/psf/black): *the uncompromising Python code formatter*.