From 097128682371e967f16295ae5500079586d380b0 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Tue, 5 Jul 2022 19:11:16 +0200 Subject: [PATCH] feat(config): For empty vars check differentiate between print and rich --- .../{{ cookiecutter.__project_slug }}.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python-naive/{{ cookiecutter.__project_slug }}/{{ cookiecutter.__project_slug }}.py b/python-naive/{{ cookiecutter.__project_slug }}/{{ cookiecutter.__project_slug }}.py index b3529f6..8fcddb5 100644 --- a/python-naive/{{ cookiecutter.__project_slug }}/{{ cookiecutter.__project_slug }}.py +++ b/python-naive/{{ cookiecutter.__project_slug }}/{{ cookiecutter.__project_slug }}.py @@ -193,6 +193,19 @@ def validate_config_sections( config_obj: configparser.ConfigParser()) -> None: for this_section in config_obj.sections(): {% if cookiecutter.use_rich_logging == "yes" -%}log.debug{%- else -%}print{%- endif %}(print_section_header(this_section)) + + unset_options = we_have_unset_options(config_obj, this_section) + if unset_options: + {% if cookiecutter.use_rich_logging == "yes" -%}log.error{%- else -%}print{%- endif %}(f"""{p.plural("Option", len(unset_options))} {unset_options} """ + {% if cookiecutter.use_rich_logging == "yes" %} {% endif %}f"""{p.plural("is", len(unset_options))} unset. """ + {% if cookiecutter.use_rich_logging == "yes" %} {% endif %}f"""{p.singular_noun("They", len(unset_options))} """ + {% if cookiecutter.use_rich_logging == "yes" %} {% endif %}f"must have a non-null value. " + {% if cookiecutter.use_rich_logging == "yes" %} {% endif %}f"""{p.plural("Default", len(unset_options))} {p.plural("is", len(unset_options))}:""") + for unset_option in unset_options: + {% if cookiecutter.use_rich_logging == "yes" -%}log.error{%- else -%}print{%- endif %}(f"{unset_option} = {internal_defaults[unset_option]}") + {% if cookiecutter.use_rich_logging == "yes" -%}log.error{%- else -%}print{%- endif %}(f"Exiting 7 ...") + sys.exit(7) + if not set(CONST.CFG_MANDATORY).issubset(config_obj.options(this_section, no_defaults=True)): {% if cookiecutter.use_rich_logging == "yes" -%}log.debug{%- else -%}print{%- endif %}(f"Config section '[{this_section}]' does not have all mandatory options " {% if cookiecutter.use_rich_logging == "yes" %} {% endif %}f"{CONST.CFG_MANDATORY} set, skipping section ...")