Skip to content
Snippets Groups Projects
Unverified Commit f75f02f7 authored by Caleb Connolly's avatar Caleb Connolly :recycle:
Browse files

helpers: logging: reduce the risk of a cyclical import


Lazy load pmb.config.styles and move the pmb.__version__ print elsewhere
so the logging module is (closer to) a standalone entity. This is
necessary to be able to import it in pmb/helpers/apk.py otherwise we get
a cyclical dependency.

Signed-off-by: default avatarCaleb Connolly <caleb@postmarketos.org>
parent 8c7c8140
No related branches found
No related tags found
No related merge requests found
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import sys
import pmb.config
from pmb.core.context import Context
from pmb.core.pkgrepo import pkgrepo_default_path
......@@ -89,6 +91,7 @@ def init(args: PmbArgs) -> PmbArgs:
# Initialize logs (we could raise errors below)
pmb.helpers.logging.init(context.log, args.verbose, context.details_to_stdout)
pmb.helpers.logging.debug(f"Pmbootstrap v{pmb.__version__} (Python {sys.version})")
# Initialization code which may raise errors
if args.action not in [
......
......@@ -5,7 +5,6 @@ import os
from pathlib import Path
import sys
from typing import Final, TextIO
import pmb.config
from pmb.meta import Cache
logfd: TextIO
......@@ -29,6 +28,12 @@ class log_handler(logging.StreamHandler):
self.details_to_stdout = details_to_stdout
self.quiet = False
# FIXME: importing pmb.config pulls in a whole lot of stuff
# and can easily lead to circular imports, so we defer it until here.
import pmb.config
self.styles = pmb.config.styles
def emit(self, record):
try:
msg = self.format(record)
......@@ -37,7 +42,7 @@ class log_handler(logging.StreamHandler):
if self.details_to_stdout or (not self.quiet and record.levelno >= logging.INFO):
stream = self.stream
styles = pmb.config.styles
styles = self.styles
msg_col = (
msg.replace(
......@@ -147,7 +152,6 @@ def init(logfile: Path, verbose: bool, details_to_stdout: bool = False):
handler.setFormatter(formatter)
root_logger.addHandler(handler)
logging.debug(f"Pmbootstrap v{pmb.__version__} (Python {sys.version})")
if "--password" in sys.argv:
sys.argv[sys.argv.index("--password") + 1] = "[REDACTED]"
logging.debug(f"$ pmbootstrap {' '.join(sys.argv)}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment