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": "{{ cookiecutter.project_slug.lower().replace(' ', '-').replace('_', '-') }}",
|
||||||
"__project_slug_under": "{{ cookiecutter.project_slug.lower().replace(' ', '_').replace('-', '_') }}",
|
"__project_slug_under": "{{ cookiecutter.project_slug.lower().replace(' ', '_').replace('-', '_') }}",
|
||||||
"use_rich_logging": ["yes", "no"],
|
"use_rich_logging": ["yes", "no"],
|
||||||
"uses_config_ini": ["yes", "no"],
|
"use_config_ini": ["yes", "no"],
|
||||||
"uses_inflect": ["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)
|
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)
|
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:
|
try:
|
||||||
os.remove(config_ini_file_abs)
|
os.remove(config_ini_file_abs)
|
||||||
try:
|
try:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{%- if cookiecutter.use_rich_logging == "yes" -%}
|
{%- if cookiecutter.use_rich_logging == "yes" -%}
|
||||||
rich
|
rich
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{%- if cookiecutter.uses_inflect == "yes" -%}
|
{%- if cookiecutter.use_inflect == "yes" -%}
|
||||||
inflect
|
inflect
|
||||||
{% endif -%}
|
{% 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
|
# This file is autogenerated by pip-compile with python 3.10
|
||||||
# To update, run:
|
# To update, run:
|
||||||
@ -10,7 +10,7 @@
|
|||||||
commonmark==0.9.1
|
commonmark==0.9.1
|
||||||
# via rich
|
# via rich
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{%- if cookiecutter.uses_inflect == "yes" -%}
|
{%- if cookiecutter.use_inflect == "yes" -%}
|
||||||
inflect==5.6.0
|
inflect==5.6.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
{% if cookiecutter.uses_config_ini == "yes" -%}
|
{% if cookiecutter.use_config_ini == "yes" -%}
|
||||||
|
# Path and env manipulation
|
||||||
import os
|
import os
|
||||||
|
# Use a config file
|
||||||
import configparser
|
import configparser
|
||||||
|
# Exit with various exit codes
|
||||||
import sys
|
import sys
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- if cookiecutter.use_rich_logging == "yes" %}
|
{%- if cookiecutter.use_rich_logging == "yes" %}
|
||||||
|
# Manipulate style and content of logs
|
||||||
import logging
|
import logging
|
||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- if cookiecutter.uses_inflect == "yes" %}
|
{%- if cookiecutter.use_inflect == "yes" %}
|
||||||
|
# Correctly generate plurals, singular nouns etc.
|
||||||
import inflect
|
import inflect
|
||||||
{%- endif %}
|
{%- 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
|
# Exit codes
|
||||||
@ -24,7 +29,7 @@ class CONST(object):
|
|||||||
{%- if cookiecutter.use_rich_logging == "yes" %}
|
{%- if cookiecutter.use_rich_logging == "yes" %}
|
||||||
LOG_FORMAT = "%(message)s"
|
LOG_FORMAT = "%(message)s"
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- if cookiecutter.uses_config_ini == "yes" %}
|
{%- if cookiecutter.use_config_ini == "yes" %}
|
||||||
# How to find a config file
|
# How to find a config file
|
||||||
CFG_THIS_FILE_DIRNAME = os.path.dirname(__file__)
|
CFG_THIS_FILE_DIRNAME = os.path.dirname(__file__)
|
||||||
CFG_DEFAULT_FILENAME = "config.ini"
|
CFG_DEFAULT_FILENAME = "config.ini"
|
||||||
@ -82,7 +87,7 @@ log = logging.getLogger("rich")
|
|||||||
# Our own code logs with this level
|
# 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)
|
log.setLevel(os.environ.get("LOGLEVEL") if "LOGLEVEL" in [k for k, v in os.environ.items()] else logging.INFO)
|
||||||
{%- endif %}
|
{%- 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
|
# 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(
|
def an_important_function(
|
||||||
section_name: str,
|
section_name: str,
|
||||||
{%- if cookiecutter.uses_config_ini == "yes" %}
|
{%- if cookiecutter.use_config_ini == "yes" %}
|
||||||
config_obj: configparser.ConfigParser(),
|
config_obj: configparser.ConfigParser(),
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
whatever: str) -> list:
|
whatever: str) -> list:
|
||||||
{%- if cookiecutter.uses_config_ini == "yes" %}
|
{%- if cookiecutter.use_config_ini == "yes" %}
|
||||||
min_duration = config_obj.getint(section_name, "min_duration")
|
min_duration = config_obj.getint(section_name, "min_duration")
|
||||||
max_duration = config_obj.getint(section_name, "max_duration")
|
max_duration = config_obj.getint(section_name, "max_duration")
|
||||||
{%- else %}
|
{%- else %}
|
||||||
@ -208,7 +213,7 @@ def an_important_function(
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
{% if cookiecutter.uses_config_ini == "yes" -%}
|
{% if cookiecutter.use_config_ini == "yes" -%}
|
||||||
validate_default_section(config)
|
validate_default_section(config)
|
||||||
if config_has_valid_section(config):
|
if config_has_valid_section(config):
|
||||||
validate_config_sections(config)
|
validate_config_sections(config)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user