refactor(config): Clearer Cookiecutter variable names
This commit is contained in:
parent
03f11d84ce
commit
b64dc5f595
@ -3,6 +3,6 @@
|
||||
"__project_slug": "{{ cookiecutter.project_slug.lower().replace(' ', '-').replace('_', '-') }}",
|
||||
"__project_slug_under": "{{ cookiecutter.project_slug.lower().replace(' ', '_').replace('-', '_') }}",
|
||||
"use_rich_logging": ["yes", "no"],
|
||||
"uses_config_ini": ["yes", "no"],
|
||||
"uses_inflect": ["yes", "no"]
|
||||
"use_config_ini": ["yes", "no"],
|
||||
"use_inflect": ["yes", "no"]
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ config_ini_file_name = "config.ini.example"
|
||||
examples_dir_abs = os.path.join(project_dir, examples_dir_name)
|
||||
config_ini_file_abs = os.path.join(project_dir, examples_dir_name, config_ini_file_name)
|
||||
|
||||
if {% if cookiecutter.uses_config_ini == "yes" -%}False{% else -%}True{%- endif -%}:
|
||||
if {% if cookiecutter.use_config_ini == "yes" -%}False{% else -%}True{%- endif -%}:
|
||||
try:
|
||||
os.remove(config_ini_file_abs)
|
||||
try:
|
||||
|
@ -1,6 +1,6 @@
|
||||
{%- if cookiecutter.use_rich_logging == "yes" -%}
|
||||
rich
|
||||
{% endif -%}
|
||||
{%- if cookiecutter.uses_inflect == "yes" -%}
|
||||
{%- if cookiecutter.use_inflect == "yes" -%}
|
||||
inflect
|
||||
{% endif -%}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{%- if cookiecutter.use_rich_logging == "yes" or cookiecutter.uses_inflect == "yes" -%}
|
||||
{%- if cookiecutter.use_rich_logging == "yes" or cookiecutter.use_inflect == "yes" -%}
|
||||
#
|
||||
# This file is autogenerated by pip-compile with python 3.10
|
||||
# To update, run:
|
||||
@ -10,7 +10,7 @@
|
||||
commonmark==0.9.1
|
||||
# via rich
|
||||
{% endif -%}
|
||||
{%- if cookiecutter.uses_inflect == "yes" -%}
|
||||
{%- if cookiecutter.use_inflect == "yes" -%}
|
||||
inflect==5.6.0
|
||||
# via -r requirements.in
|
||||
{% endif -%}
|
||||
|
@ -1,16 +1,21 @@
|
||||
{% if cookiecutter.uses_config_ini == "yes" -%}
|
||||
{% if cookiecutter.use_config_ini == "yes" -%}
|
||||
# Path and env manipulation
|
||||
import os
|
||||
# Use a config file
|
||||
import configparser
|
||||
# Exit with various exit codes
|
||||
import sys
|
||||
{%- endif %}
|
||||
{%- if cookiecutter.use_rich_logging == "yes" %}
|
||||
# Manipulate style and content of logs
|
||||
import logging
|
||||
from rich.logging import RichHandler
|
||||
{%- endif %}
|
||||
{%- if cookiecutter.uses_inflect == "yes" %}
|
||||
{%- if cookiecutter.use_inflect == "yes" %}
|
||||
# Correctly generate plurals, singular nouns etc.
|
||||
import inflect
|
||||
{%- endif %}
|
||||
{%- if cookiecutter.use_rich_logging == "yes" or cookiecutter.uses_config_ini == "yes" %}
|
||||
{%- if cookiecutter.use_rich_logging == "yes" or cookiecutter.use_config_ini == "yes" %}
|
||||
|
||||
|
||||
# Exit codes
|
||||
@ -24,7 +29,7 @@ class CONST(object):
|
||||
{%- if cookiecutter.use_rich_logging == "yes" %}
|
||||
LOG_FORMAT = "%(message)s"
|
||||
{%- endif %}
|
||||
{%- if cookiecutter.uses_config_ini == "yes" %}
|
||||
{%- if cookiecutter.use_config_ini == "yes" %}
|
||||
# How to find a config file
|
||||
CFG_THIS_FILE_DIRNAME = os.path.dirname(__file__)
|
||||
CFG_DEFAULT_FILENAME = "config.ini"
|
||||
@ -82,7 +87,7 @@ log = logging.getLogger("rich")
|
||||
# Our own code logs with this level
|
||||
log.setLevel(os.environ.get("LOGLEVEL") if "LOGLEVEL" in [k for k, v in os.environ.items()] else logging.INFO)
|
||||
{%- endif %}
|
||||
{%- if cookiecutter.uses_config_ini == "yes" %}
|
||||
{%- if cookiecutter.use_config_ini == "yes" %}
|
||||
|
||||
|
||||
# Use this version of class ConfigParser to {% if cookiecutter.use_rich_logging == "yes" -%}log.debug{%- else -%}print{%- endif %} contents of our config file. When parsing sections other than
|
||||
@ -193,11 +198,11 @@ def validate_config_sections(
|
||||
|
||||
def an_important_function(
|
||||
section_name: str,
|
||||
{%- if cookiecutter.uses_config_ini == "yes" %}
|
||||
{%- if cookiecutter.use_config_ini == "yes" %}
|
||||
config_obj: configparser.ConfigParser(),
|
||||
{%- endif %}
|
||||
whatever: str) -> list:
|
||||
{%- if cookiecutter.uses_config_ini == "yes" %}
|
||||
{%- if cookiecutter.use_config_ini == "yes" %}
|
||||
min_duration = config_obj.getint(section_name, "min_duration")
|
||||
max_duration = config_obj.getint(section_name, "max_duration")
|
||||
{%- else %}
|
||||
@ -208,7 +213,7 @@ def an_important_function(
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
{% if cookiecutter.uses_config_ini == "yes" -%}
|
||||
{% if cookiecutter.use_config_ini == "yes" -%}
|
||||
validate_default_section(config)
|
||||
if config_has_valid_section(config):
|
||||
validate_config_sections(config)
|
||||
|
Loading…
x
Reference in New Issue
Block a user