From 6d9eca601792808f61ceda477cf7329cccb8ab74 Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Fri, 12 Dec 2025 08:10:07 -0600 Subject: [PATCH 1/2] use console_scripts --- .gitignore | 4 +++- bin/udapy.bat | 4 ---- setup.cfg | 8 +++---- bin/udapy => udapi/cli.py | 48 +++++++++++++++++++++------------------ 4 files changed, 33 insertions(+), 31 deletions(-) delete mode 100644 bin/udapy.bat rename bin/udapy => udapi/cli.py (85%) diff --git a/.gitignore b/.gitignore index a75e7c05..adc7bbbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.cache .idea +*.egg-info/ *.pyc -.cache +dist/ diff --git a/bin/udapy.bat b/bin/udapy.bat deleted file mode 100644 index 013e08e7..00000000 --- a/bin/udapy.bat +++ /dev/null @@ -1,4 +0,0 @@ -@REM The Python launcher "py" must be accessible via the PATH environment variable. -@REM We assume that this batch script lies next to udapy in udapi-python/bin. -@REM The PYTHONPATH environment variable must contain path to udapi-python. -py %~dp$PATH:0\udapy %* diff --git a/setup.cfg b/setup.cfg index fdbae292..2cdfaaa9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,14 +16,14 @@ classifiers = packages = find: python_requires = >=3.9 include_package_data = True -scripts = - bin/udapy install_requires = colorama termcolor +[options.entry_points] +console_scripts = + udapy = udapi:cli.main + [options.extras_require] test = pytest - - diff --git a/bin/udapy b/udapi/cli.py similarity index 85% rename from bin/udapy rename to udapi/cli.py index 30cb2595..de55f8cb 100755 --- a/bin/udapy +++ b/udapi/cli.py @@ -58,35 +58,34 @@ argparser.add_argument( 'scenario', nargs=argparse.REMAINDER, help="A sequence of blocks and their parameters.") -args = argparser.parse_args() -# Set the level of logs according to parameters. -if args.verbose: - level = logging.DEBUG -elif args.quiet: - level = logging.CRITICAL -else: - level = logging.INFO - -logging.basicConfig(format='%(asctime)-15s [%(levelname)7s] %(funcName)s - %(message)s', - level=level) +# Process and provide the scenario. +def main(argv=None): + args = argparser.parse_args(argv) -# Global flag to track if an unhandled exception occurred -_unhandled_exception_occurred = False + # Set the level of logs according to parameters. + if args.verbose: + level = logging.DEBUG + elif args.quiet: + level = logging.CRITICAL + else: + level = logging.INFO -def _custom_excepthook(exc_type, exc_value, traceback): - global _unhandled_exception_occurred - _unhandled_exception_occurred = True + logging.basicConfig(format='%(asctime)-15s [%(levelname)7s] %(funcName)s - %(message)s', + level=level) - # Call the default excepthook to allow normal error reporting - sys.__excepthook__(exc_type, exc_value, traceback) + # Global flag to track if an unhandled exception occurred + _unhandled_exception_occurred = False -# Override the default excepthook -sys.excepthook = _custom_excepthook + def _custom_excepthook(exc_type, exc_value, traceback): + global _unhandled_exception_occurred + _unhandled_exception_occurred = True + # Call the default excepthook to allow normal error reporting + sys.__excepthook__(exc_type, exc_value, traceback) -# Process and provide the scenario. -if __name__ == "__main__": + # Override the default excepthook + sys.excepthook = _custom_excepthook # Disabling garbage collections makes the whole processing much faster. # Similarly, we can save several seconds by partially disabling the at-exit Python cleanup @@ -134,3 +133,8 @@ def _custom_excepthook(exc_type, exc_value, traceback): runner.execute() except BrokenPipeError: pass + return 0 + + +if __name__ == "__main__": + sys.exit(main()) From 27f6a4c6bd04adab7f2d6c4702834e8ba846c632 Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Mon, 15 Dec 2025 08:11:23 -0600 Subject: [PATCH 2/2] restore at-rest bin scripts --- bin/udapy | 7 +++++++ bin/udapy.bat | 4 ++++ 2 files changed, 11 insertions(+) create mode 100755 bin/udapy create mode 100644 bin/udapy.bat diff --git a/bin/udapy b/bin/udapy new file mode 100755 index 00000000..83c7a6f2 --- /dev/null +++ b/bin/udapy @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +"""Thin wrapper for backward compatibility. Calls udapi.cli.main().""" +import sys +from udapi.cli import main + +if __name__ == "__main__": + sys.exit(main()) diff --git a/bin/udapy.bat b/bin/udapy.bat new file mode 100644 index 00000000..013e08e7 --- /dev/null +++ b/bin/udapy.bat @@ -0,0 +1,4 @@ +@REM The Python launcher "py" must be accessible via the PATH environment variable. +@REM We assume that this batch script lies next to udapy in udapi-python/bin. +@REM The PYTHONPATH environment variable must contain path to udapi-python. +py %~dp$PATH:0\udapy %*