diff --git a/python/README.md b/python/README.md index a6370a42..f277a20f 100644 --- a/python/README.md +++ b/python/README.md @@ -75,8 +75,9 @@ FusionEngine message specification. time-aligning FusionEngine data captured in a `*.p1log` file - `applications` - Applications and processing tools -- see [Applications](#applications) for detailed descriptions of each of these tools - - _The applications in this directory will be installed on your system by `pip install` along with the rest of - the library code so that they can be called directly from the command line_ + - _The applications in this directory will be installed on your system by `pip install`, along with the rest of + the library code, so that they can be called directly from the command line (e.g., `p1_display.py` can be run + on the command line as `p1_display`)_ - `messages` - Python message definitions - `parsers` - Message encoding and decoding support - [decoder.py](fusion_engine_client/parsers/decoder.py) - `FusionEngineDecoder` class, used to frame and parse diff --git a/python/fusion_engine_client/applications/p1_display.py b/python/fusion_engine_client/applications/p1_display.py index 9894a0d7..002ddd2d 100755 --- a/python/fusion_engine_client/applications/p1_display.py +++ b/python/fusion_engine_client/applications/p1_display.py @@ -1,5 +1,17 @@ #!/usr/bin/env python3 +import os +import sys + +# If this application is being run directly as a script (e.g., python p1_*.py), rather than as a script installed by pip +# (e.g., p1_*), manually set the package name and add the Python root directory (fusion-engine-client/python/) to the +# import search path to enable relative imports. +if __name__ == "__main__": + root_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..')) + sys.path.insert(0, root_dir) + __package__ = os.path.dirname(__file__).replace('/', '.') + + from ..analysis.analyzer import main as analyzer_main diff --git a/python/fusion_engine_client/applications/p1_extract.py b/python/fusion_engine_client/applications/p1_extract.py index f97cc152..53db7570 100755 --- a/python/fusion_engine_client/applications/p1_extract.py +++ b/python/fusion_engine_client/applications/p1_extract.py @@ -3,6 +3,14 @@ import os import sys +# If this application is being run directly as a script (e.g., python p1_*.py), rather than as a script installed by pip +# (e.g., p1_*), manually set the package name and add the Python root directory (fusion-engine-client/python/) to the +# import search path to enable relative imports. +if __name__ == "__main__": + root_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..')) + sys.path.insert(0, root_dir) + __package__ = os.path.dirname(__file__).replace('/', '.') + from ..utils import trace as logging from ..utils.argument_parser import ArgumentParser from ..utils.log import extract_fusion_engine_log, find_log_file, CANDIDATE_LOG_FILES, DEFAULT_LOG_BASE_DIR diff --git a/python/fusion_engine_client/applications/p1_lband_extract.py b/python/fusion_engine_client/applications/p1_lband_extract.py index ec80f69f..522a0522 100755 --- a/python/fusion_engine_client/applications/p1_lband_extract.py +++ b/python/fusion_engine_client/applications/p1_lband_extract.py @@ -3,6 +3,14 @@ import os import sys +# If this application is being run directly as a script (e.g., python p1_*.py), rather than as a script installed by pip +# (e.g., p1_*), manually set the package name and add the Python root directory (fusion-engine-client/python/) to the +# import search path to enable relative imports. +if __name__ == "__main__": + root_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..')) + sys.path.insert(0, root_dir) + __package__ = os.path.dirname(__file__).replace('/', '.') + from ..utils.trace import HighlightFormatter, BrokenPipeStreamHandler from ..utils.time_range import TimeRange from ..utils.log import locate_log, DEFAULT_LOG_BASE_DIR diff --git a/python/fusion_engine_client/applications/p1_print.py b/python/fusion_engine_client/applications/p1_print.py index 5dae08eb..78172346 100755 --- a/python/fusion_engine_client/applications/p1_print.py +++ b/python/fusion_engine_client/applications/p1_print.py @@ -1,8 +1,17 @@ #!/usr/bin/env python3 from collections import defaultdict +import os import sys +# If this application is being run directly as a script (e.g., python p1_*.py), rather than as a script installed by pip +# (e.g., p1_*), manually set the package name and add the Python root directory (fusion-engine-client/python/) to the +# import search path to enable relative imports. +if __name__ == "__main__": + root_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..')) + sys.path.insert(0, root_dir) + __package__ = os.path.dirname(__file__).replace('/', '.') + from ..messages import * from ..parsers import MixedLogReader from ..utils import trace as logging