From b8aec65ee7181f78ba536a30aa19b3ffd7ad1aff Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Sun, 17 Nov 2019 13:27:08 -0500 Subject: [PATCH] only use relative imports when a module --- OscCommentMacroListener.py | 11 +++++++++-- comment.py | 14 +++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/OscCommentMacroListener.py b/OscCommentMacroListener.py index fea2bc7..f0b00cd 100644 --- a/OscCommentMacroListener.py +++ b/OscCommentMacroListener.py @@ -16,11 +16,18 @@ __status__ = "Prototype" import logging -from .CommentMacroParser import CommentMacroParser -from .CommentMacroListener import CommentMacroListener from pythonosc import osc_message_builder from time import sleep +try: + # include reletive path imports when a module + from .CommentMacroParser import CommentMacroParser + from .CommentMacroListener import CommentMacroListener +except ImportError: + # include directly when called directly + from CommentMacroParser import CommentMacroParser + from CommentMacroListener import CommentMacroListener + logger = logging.getLogger('__main__') diff --git a/comment.py b/comment.py index 1841d1b..41a01be 100755 --- a/comment.py +++ b/comment.py @@ -23,11 +23,19 @@ from antlr4 import CommonTokenStream from antlr4 import InputStream from antlr4 import ParseTreeWalker from antlr4.error.ErrorListener import ErrorListener -from .CommentMacroLexer import CommentMacroLexer -from .CommentMacroParser import CommentMacroParser -from .OscCommentMacroListener import OscCommentMacroListener from pythonosc import udp_client +try: + # include reletive path imports when a module + from .CommentMacroLexer import CommentMacroLexer + from .CommentMacroParser import CommentMacroParser + from .OscCommentMacroListener import OscCommentMacroListener +except ImportError: + # include directly when called directly + from CommentMacroLexer import CommentMacroLexer + from CommentMacroParser import CommentMacroParser + from OscCommentMacroListener import OscCommentMacroListener + # define an error listener that raises SyntaxError exceptions class SyntaxErrorListener(ErrorListener):