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 <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2022-10-28 11:13:28 +02:00
parent dde0843ee7
commit 638e2cbfbf
9 changed files with 72 additions and 61 deletions

View File

@ -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,17 +79,20 @@ async def main():
logger.info("Starting console-conf v{}".format(VERSION))
logger.info("Arguments passed: {}".format(sys.argv))
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)
# 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()
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())

View File

@ -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())

View File

@ -59,11 +59,14 @@ def make_app():
return app
async def main():
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())

View File

@ -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))
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()
asyncio.run(run_with_loop())
if __name__ == '__main__':
sys.exit(asyncio.run(main()))
sys.exit(main())

View File

@ -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
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()
asyncio.run(run_with_loop())
if __name__ == '__main__':
sys.exit(asyncio.run(main()))
sys.exit(main())

View File

@ -13,9 +13,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import asyncio
import sys
if __name__ == '__main__':
from system_setup.cmd.tui import main
sys.exit(asyncio.run(main()))
sys.exit(main())

View File

@ -38,11 +38,14 @@ def make_app():
return app
async def main():
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())

View File

@ -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
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()
asyncio.run(run_with_loop())
if __name__ == '__main__':
sys.exit(asyncio.run(main()))
sys.exit(main())

View File

@ -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
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()
asyncio.run(run_with_loop())
if __name__ == '__main__':
sys.exit(asyncio.run(main()))
sys.exit(main())