summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Peveler <matt.peveler@gmail.com>2021-01-29 13:52:39 +0000
committerMatthew Peveler <matt.peveler@gmail.com>2021-01-29 13:52:39 +0000
commitd9d29331890097705a18020977874b6550f34986 (patch)
treea55f9b96af669fc9cde121dbdb93f86410382693
parent8ecac1e77d13417343fe5ce6405c245d96229a18 (diff)
downloadasciidoc-py3-d9d29331890097705a18020977874b6550f34986.tar.gz
fix errors not displaying when called via module
Signed-off-by: Matthew Peveler <matt.peveler@gmail.com>
-rw-r--r--asciidoc/__main__.py5
-rw-r--r--asciidoc/asciidoc.py10
-rwxr-xr-xtests/testasciidoc.py1
3 files changed, 12 insertions, 4 deletions
diff --git a/asciidoc/__main__.py b/asciidoc/__main__.py
index 59bbb90..d7384c5 100644
--- a/asciidoc/__main__.py
+++ b/asciidoc/__main__.py
@@ -1,6 +1,7 @@
try:
- from .asciidoc import cli
+ from .asciidoc import cli, set_caller
except ImportError:
- from asciidoc import cli
+ from asciidoc import cli, set_caller
+set_caller(__name__)
cli()
diff --git a/asciidoc/asciidoc.py b/asciidoc/asciidoc.py
index bcafdcd..da5769f 100644
--- a/asciidoc/asciidoc.py
+++ b/asciidoc/asciidoc.py
@@ -187,7 +187,7 @@ class Message:
if msg == self.prev_msg: # Suppress repeated messages.
return
self.messages.append(msg)
- if __name__ == '__main__':
+ if APPLICATION_CALLER == '__main__':
sys.stderr.write('%s: %s%s' % (self.PROG, msg, os.linesep))
self.prev_msg = msg
@@ -6083,6 +6083,7 @@ class Plugin:
# ---------
USER_DIR = None # ~/.asciidoc
HELP_FILE = 'help.conf' # Default (English) help file.
+APPLICATION_CALLER = __name__
# Globals
# -------
@@ -6105,6 +6106,11 @@ trace = Trace() # Implements trace attribute processing.
messages = message.messages
+def set_caller(name):
+ global APPLICATION_CALLER
+ APPLICATION_CALLER = name
+
+
def reset_asciidoc():
global document, config, reader, writer, message
global paragraphs, lists, blocks, tables_OLD, tables
@@ -6284,7 +6290,7 @@ def asciidoc(backend, doctype, confiles, infile, outfile, options):
if isinstance(e, EAsciiDoc):
message.stderr('%s%s' % (msg, str(e)))
else:
- if __name__ == '__main__':
+ if APPLICATION_CALLER == '__main__':
message.stderr(msg + 'unexpected error:')
message.stderr('-' * 60)
traceback.print_exc(file=sys.stderr)
diff --git a/tests/testasciidoc.py b/tests/testasciidoc.py
index 1379034..2aace85 100755
--- a/tests/testasciidoc.py
+++ b/tests/testasciidoc.py
@@ -398,6 +398,7 @@ class Lines(list):
if __name__ == '__main__':
# guarantee a stable timestamp matching the test fixtures
os.environ['SOURCE_DATE_EPOCH'] = '1038184662'
+ asciidoc.set_caller(__name__)
# Process command line options.
from argparse import ArgumentParser
parser = ArgumentParser(