Skip to content

Commit

Permalink
feat: display version info when startup
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Sep 23, 2022
1 parent 3baf19e commit f93edc9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion python_boilerplate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from python_boilerplate.configuration.application_configuration import (
configure as application_configure,
)
from python_boilerplate.configuration.application_configuration import setup_cfg
from python_boilerplate.configuration.loguru_configuration import (
configure as loguru_configure,
)
Expand Down Expand Up @@ -51,7 +52,8 @@

__elapsed = time.perf_counter() - __start_time
logger.info(
f"Started {get_module_name()} in {round(__elapsed, 3)} seconds ({round(__elapsed * 1000, 2)} ms)"
f"Started {get_module_name()}@{setup_cfg['metadata']['version']} in {round(__elapsed, 3)} seconds "
f"({round(__elapsed * 1000, 2)} ms)"
)


Expand Down
2 changes: 1 addition & 1 deletion python_boilerplate/common/common_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_data_dir(sub_path="") -> Path:
if len(sub_path) > 0:
data_dir = data_dir / sub_path
if not data_dir.exists():
# If parents is false (the default), a missing parent raises FileNotFoundError.
# If parents are false (the default), a missing parent raises FileNotFoundError.
# If exist_ok is false (the default), FileExistsError is raised if the target directory already exists.
data_dir.mkdir(parents=True, exist_ok=True)
return data_dir
Expand Down
16 changes: 14 additions & 2 deletions python_boilerplate/configuration/application_configuration.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import configparser
from typing import Final

from loguru import logger
from pyhocon import ConfigFactory, ConfigTree

from python_boilerplate.common.common_function import get_resources_dir
from python_boilerplate.common.common_function import (
PROJECT_ROOT_PATH,
get_resources_dir,
)

# `application_conf` contains the configuration for the application.
application_conf: ConfigTree = ConfigFactory.parse_file(
get_resources_dir() / "application.conf"
)

# setup.cfg contains the project constants
setup_cfg: Final = configparser.ConfigParser()
setup_cfg.read(PROJECT_ROOT_PATH / "setup.cfg")


def configure() -> None:
"""
Configure application.
"""
logger.warning(f"Application configuration loaded, {application_conf}")
logger.warning(
f"Application configuration loaded, {application_conf}, {setup_cfg.sections()}"
)

0 comments on commit f93edc9

Please sign in to comment.