Use backwards compatible string formatting

master
James Curtin 5 years ago committed by James Curtin
parent 488b5dc8d3
commit 240134bf77
  1. 8
      hooks/pre_gen_project.py

@ -6,6 +6,7 @@ logging.basicConfig()
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
MODULE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]+$" MODULE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]+$"
class bcolors: class bcolors:
WARNING = "\033[93m" WARNING = "\033[93m"
ENDC = "\033[0m" ENDC = "\033[0m"
@ -14,15 +15,18 @@ class bcolors:
def colorize(escape_code, text): def colorize(escape_code, text):
code = getattr(bcolors, escape_code) code = getattr(bcolors, escape_code)
return f"{code}{text}{bcolors.ENDC}" return "{code}{text}{end_code}".format(code=code, text=text, end_code=bcolors.ENDC)
def log_module_name_warning(module_name, logger): def log_module_name_warning(module_name, logger):
warning = ( warning = (
f"\n{colorize('WARNING', 'WARNING:')} {colorize('BOLD', module_name)}" "\n{warning} {fmt_module_name}"
" is not a valid Python module name!\n" " is not a valid Python module name!\n"
"See https://www.python.org/dev/peps/pep-0008/#package-and-module-names" "See https://www.python.org/dev/peps/pep-0008/#package-and-module-names"
" for naming standards.\n" " for naming standards.\n"
).format(
warning=colorize("WARNING", "WARNING:"),
fmt_module_name=colorize("BOLD", module_name),
) )
logger.warning(warning) logger.warning(warning)

Loading…
Cancel
Save