From 638e2cbfbfc6e8dca17f4ca91f54ac85ac51bf03 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 28 Oct 2022 11:13:28 +0200 Subject: [PATCH] loop: fix setuptools entry-points not using asyncio.run setuptools declares a certain number of entry points that use the main function of the associated component. That said, now that main is an async function, it does not work. There seems to be no way to tell setuptools to wrap the call to the entry point with asyncio.run so we need to revert to a synchronous main function. Signed-off-by: Olivier Gayot --- console_conf/cmd/tui.py | 25 ++++++++++++++----------- subiquity/__main__.py | 3 +-- subiquity/cmd/schema.py | 13 ++++++++----- subiquity/cmd/server.py | 19 ++++++++++--------- subiquity/cmd/tui.py | 19 ++++++++++--------- system_setup/__main__.py | 3 +-- system_setup/cmd/schema.py | 13 ++++++++----- system_setup/cmd/server.py | 19 ++++++++++--------- system_setup/cmd/tui.py | 19 ++++++++++--------- 9 files changed, 72 insertions(+), 61 deletions(-) diff --git a/console_conf/cmd/tui.py b/console_conf/cmd/tui.py index 9432bc28..00d6805a 100755 --- a/console_conf/cmd/tui.py +++ b/console_conf/cmd/tui.py @@ -69,7 +69,7 @@ def parse_options(argv): LOGDIR = "/var/log/console-conf/" -async def main(): +def main(): opts = parse_options(sys.argv[1:]) global LOGDIR if opts.dry_run: @@ -79,16 +79,19 @@ async def main(): logger.info("Starting console-conf v{}".format(VERSION)) logger.info("Arguments passed: {}".format(sys.argv)) - if opts.chooser_systems: - # when running as a chooser, the stdin/stdout streams are set up by the - # process that runs us, attempt to restore the tty in/out by looking at - # stderr - chooser_input, chooser_output = restore_std_streams_from(sys.stderr) - interface = RecoveryChooser(opts, chooser_input, chooser_output) - else: - interface = ConsoleConf(opts) + async def run_with_loop(): + if opts.chooser_systems: + # when running as a chooser, the stdin/stdout streams are set up by + # the process that runs us, attempt to restore the tty in/out by + # looking at stderr + chooser_input, chooser_output = restore_std_streams_from( + sys.stderr) + interface = RecoveryChooser(opts, chooser_input, chooser_output) + else: + interface = ConsoleConf(opts) + await interface.run() - await interface.run() + asyncio.run(run_with_loop()) def restore_std_streams_from(from_file): @@ -105,4 +108,4 @@ def restore_std_streams_from(from_file): if __name__ == '__main__': - sys.exit(asyncio.run(main())) + sys.exit(main()) diff --git a/subiquity/__main__.py b/subiquity/__main__.py index cc3e9c19..9ada9ef3 100644 --- a/subiquity/__main__.py +++ b/subiquity/__main__.py @@ -1,6 +1,5 @@ -import asyncio import sys if __name__ == '__main__': from subiquity.cmd.tui import main - sys.exit(asyncio.run(main())) + sys.exit(main()) diff --git a/subiquity/cmd/schema.py b/subiquity/cmd/schema.py index 359318b1..7ebb646a 100644 --- a/subiquity/cmd/schema.py +++ b/subiquity/cmd/schema.py @@ -59,11 +59,14 @@ def make_app(): return app -async def main(): - schema = make_schema(make_app()) - jsonschema.validate({"version": 1}, schema) - print(json.dumps(schema, indent=4)) +def main(): + async def run_with_loop(): + schema = make_schema(make_app()) + jsonschema.validate({"version": 1}, schema) + print(json.dumps(schema, indent=4)) + + asyncio.run(run_with_loop()) if __name__ == '__main__': - sys.exit(asyncio.run(main())) + sys.exit(main()) diff --git a/subiquity/cmd/server.py b/subiquity/cmd/server.py index f140f4b5..113952e3 100644 --- a/subiquity/cmd/server.py +++ b/subiquity/cmd/server.py @@ -112,7 +112,7 @@ def make_server_args_parser(): return parser -async def main(): +def main(): print('starting server') setup_environment() # setup_environment sets $APPORT_DATA_DIR which must be set before @@ -155,15 +155,16 @@ async def main(): logger.debug("Kernel commandline: {}".format(opts.kernel_cmdline)) logger.debug("Storage version: {}".format(opts.storage_version)) - server = SubiquityServer(opts, block_log_dir) + async def run_with_loop(): + server = SubiquityServer(opts, block_log_dir) + server.note_file_for_apport( + "InstallerServerLog", logfiles['debug']) + server.note_file_for_apport( + "InstallerServerLogInfo", logfiles['info']) + await server.run() - server.note_file_for_apport( - "InstallerServerLog", logfiles['debug']) - server.note_file_for_apport( - "InstallerServerLogInfo", logfiles['info']) - - await server.run() + asyncio.run(run_with_loop()) if __name__ == '__main__': - sys.exit(asyncio.run(main())) + sys.exit(main()) diff --git a/subiquity/cmd/tui.py b/subiquity/cmd/tui.py index 333a6c0c..d62271d8 100755 --- a/subiquity/cmd/tui.py +++ b/subiquity/cmd/tui.py @@ -80,7 +80,7 @@ def make_client_args_parser(): AUTO_ANSWERS_FILE = "/subiquity_config/answers.yaml" -async def main(): +def main(): setup_environment() # setup_environment sets $APPORT_DATA_DIR which must be set before # apport is imported, which is done by this import: @@ -141,15 +141,16 @@ async def main(): opts.answers.close() opts.answers = None - subiquity_interface = SubiquityClient(opts) + async def run_with_loop(): + subiquity_interface = SubiquityClient(opts) + subiquity_interface.note_file_for_apport( + "InstallerLog", logfiles['debug']) + subiquity_interface.note_file_for_apport( + "InstallerLogInfo", logfiles['info']) + await subiquity_interface.run() - subiquity_interface.note_file_for_apport( - "InstallerLog", logfiles['debug']) - subiquity_interface.note_file_for_apport( - "InstallerLogInfo", logfiles['info']) - - await subiquity_interface.run() + asyncio.run(run_with_loop()) if __name__ == '__main__': - sys.exit(asyncio.run(main())) + sys.exit(main()) diff --git a/system_setup/__main__.py b/system_setup/__main__.py index 51b525eb..5b826b12 100644 --- a/system_setup/__main__.py +++ b/system_setup/__main__.py @@ -13,9 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import asyncio import sys if __name__ == '__main__': from system_setup.cmd.tui import main - sys.exit(asyncio.run(main())) + sys.exit(main()) diff --git a/system_setup/cmd/schema.py b/system_setup/cmd/schema.py index 5ece6e1d..9e7146a9 100644 --- a/system_setup/cmd/schema.py +++ b/system_setup/cmd/schema.py @@ -38,11 +38,14 @@ def make_app(): return app -async def main(): - schema = make_schema(make_app()) - jsonschema.validate({"version": 1}, schema) - print(json.dumps(schema, indent=4)) +def main(): + async def run_with_loop(): + schema = make_schema(make_app()) + jsonschema.validate({"version": 1}, schema) + print(json.dumps(schema, indent=4)) + + asyncio.run(run_with_loop()) if __name__ == '__main__': - sys.exit(asyncio.run(main())) + sys.exit(main()) diff --git a/system_setup/cmd/server.py b/system_setup/cmd/server.py index 78a25640..f592ad0e 100644 --- a/system_setup/cmd/server.py +++ b/system_setup/cmd/server.py @@ -54,7 +54,7 @@ def make_server_args_parser(): return parser -async def main(): +def main(): print('starting server') setup_environment() # setup_environment sets $APPORT_DATA_DIR which must be set before @@ -97,15 +97,16 @@ async def main(): .format(prefillFile)) opts.prefill = None - server = SystemSetupServer(opts, block_log_dir) + async def run_with_loop(): + server = SystemSetupServer(opts, block_log_dir) + server.note_file_for_apport( + "InstallerServerLog", logfiles['debug']) + server.note_file_for_apport( + "InstallerServerLogInfo", logfiles['info']) + await server.run() - server.note_file_for_apport( - "InstallerServerLog", logfiles['debug']) - server.note_file_for_apport( - "InstallerServerLogInfo", logfiles['info']) - - await server.run() + asyncio.run(run_with_loop()) if __name__ == '__main__': - sys.exit(asyncio.run(main())) + sys.exit(main()) diff --git a/system_setup/cmd/tui.py b/system_setup/cmd/tui.py index 7bf29add..8db9d6cf 100755 --- a/system_setup/cmd/tui.py +++ b/system_setup/cmd/tui.py @@ -66,7 +66,7 @@ def make_client_args_parser(): AUTO_ANSWERS_FILE = "/subiquity_config/answers.yaml" -async def main(): +def main(): setup_environment() # setup_environment sets $APPORT_DATA_DIR which must be set before # apport is imported, which is done by this import: @@ -147,15 +147,16 @@ async def main(): opts.answers.close() opts.answers = None - subiquity_interface = SystemSetupClient(opts) + async def run_with_loop(): + subiquity_interface = SystemSetupClient(opts) + subiquity_interface.note_file_for_apport( + "InstallerLog", logfiles['debug']) + subiquity_interface.note_file_for_apport( + "InstallerLogInfo", logfiles['info']) + await subiquity_interface.run() - subiquity_interface.note_file_for_apport( - "InstallerLog", logfiles['debug']) - subiquity_interface.note_file_for_apport( - "InstallerLogInfo", logfiles['info']) - - await subiquity_interface.run() + asyncio.run(run_with_loop()) if __name__ == '__main__': - sys.exit(asyncio.run(main())) + sys.exit(main())