Skip to content

Commit

Permalink
add conditional to error formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
petrelharp committed Apr 5, 2024
1 parent e2a8f5d commit 2ad99df
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions stdpopsim/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pathlib
import shutil
import os
import re
import inspect

import msprime
Expand Down Expand Up @@ -54,6 +55,12 @@ class CLIFormatter(logging.Formatter):
# DEBUG: Write out debug messages for the user/developer.
def format(self, record):
if record.name == "py.warnings":
if len(record.args) > 0:
# trim the ugly warnings.warn message
match = re.search(
r"Warning:\s*(.*?)\s*warnings.warn\(", record.args[0], re.DOTALL
)
record.args = (match.group(1),)
self._style = logging.PercentStyle("WARNING: %(message)s")
else:
if record.levelno == logging.WARNING:
Expand Down

0 comments on commit 2ad99df

Please sign in to comment.