Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add environment configs for hocon to demonstrate overwriting base config #50

Merged
merged 4 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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*.
Expand Down
7 changes: 4 additions & 3 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)


Expand Down
1 change: 0 additions & 1 deletion {{cookiecutter.project_slug}}/config/debug.conf

This file was deleted.

2 changes: 2 additions & 0 deletions {{cookiecutter.project_slug}}/config/dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
environment = "dev"
logging.level = DEBUG # overrides the log level that is specified in res/default.conf
1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/config/prod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "prod"