Skip to content

Commit

Permalink
Improve GitHubActionsFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Aug 20, 2023
1 parent 2cc30e0 commit 72c2ed4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/py_build_cmake/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def read_all_metadata(
try:
update_dynamic_metadata(cfg.standard_metadata, modfile)
except ImportError as e:
logger.error("Error importing %s for reading metadata", str(modfile))
if hasattr(e, "msg"):
e.msg = (
"\n"
Expand All @@ -293,6 +294,7 @@ def read_all_metadata(
)
raise
except ProblemInModule as e:
logger.error("Error reading metadata from %s", str(modfile))
e.args = (
"\n"
"\n"
Expand Down
20 changes: 14 additions & 6 deletions src/py_build_cmake/common/logformat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import os
from pathlib import Path


class GitHubActionsFormatter(logging.Formatter):
Expand All @@ -9,12 +11,18 @@ def __init__(self):

def format(self, record: logging.LogRecord):
s = super().format(record)
loc = ""
if os.environ.get("GITHUB_REPOSITORY", "").endswith("/py-build-cmake"):
p = Path(record.pathname)
try:
i = len(p.parts) - p.parts[-1::-1].index("py_build_cmake") - 1
file = Path("src", *p.parts[i:])
loc = f" file={file},line={record.lineno}"
except ValueError:
pass
prefix = {
logging.INFO:
"::notice file=%(pathname)s,line=%(lineno)d::" % record.__dict__,
logging.WARNING:
"::warning file=%(pathname)s,line=%(lineno)d::" % record.__dict__,
logging.ERROR:
"::error file=%(pathname)s,line=%(lineno)d::" % record.__dict__
logging.INFO: f"::notice{loc}::",
logging.WARNING: f"::warning{loc}::",
logging.ERROR: f"::error{loc}::",
}.get(record.levelno, record.levelname + ":")
return prefix + s
4 changes: 2 additions & 2 deletions src/py_build_cmake/config/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def read_full_config_checked(
overrides = parse_config_settings_overrides(config_settings, verbose)
cfg = read_config(pyproject_path, overrides)
except ConfigError as e:
logger.error("Invalid user configuration", exc_info=e)
logger.error("Error in user configuration", exc_info=e)
e.args = (
"\n" "\n" "\t\u274C Error in user configuration:\n" "\n" f"\t\t{e}\n" "\n",
)
raise
except Exception as e:
logger.error("Internal error while processing configuration", exc_info=e)
logger.error("Internal error while processing the configuration", exc_info=e)
e.args = (
"\n"
"\n"
Expand Down

0 comments on commit 72c2ed4

Please sign in to comment.