From c953140d70e2364b5a977f71fa51c00cef2a1404 Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Sun, 10 Sep 2023 16:37:25 -0400 Subject: [PATCH] Expose console scripts that launch 6S in a subprocess --- pyproject.toml | 10 ++++++++++ src/sixs_bin/_cli.py | 23 +++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b3b91fb..91427a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,16 @@ py6s = "^1.9.2" [tool.poetry.extras] wrapper = ["py6s", "python-dateutil"] +[tool.poetry.scripts] +# Expose console scripts that launch 6S in a subprocess. +# These scripts have overhead compared to running 6S directly, but allow 6S to be usuable from PATH without any +# additional steps after installation. +# Alterively, we could expose 6S binaries directly using something like +# "sixsV1.1" = { reference = "src/sixs_bin/sixsV1.1", type = "file } +# but this results in the binary being duplicated in the wheel, which doubles their size. +"sixsV1.1" = "sixs_bin._cli:_exec_11" +"sixsV2.1" = "sixs_bin._cli:_exec_21" + [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" diff --git a/src/sixs_bin/_cli.py b/src/sixs_bin/_cli.py index 9d43190..3a0e78b 100644 --- a/src/sixs_bin/_cli.py +++ b/src/sixs_bin/_cli.py @@ -67,6 +67,24 @@ def _make_version() -> str: return f"{sixs_bin.DISTRIBUTION_NAME} {sixs_bin.__version__} (6S {', '.join(sixs_bin._SIXS_BINARIES.keys())})" +def _exec_subprocess(sixs_path: pathlib.Path) -> None: + """Execute the given 6S executable in a subprocess.""" + proc_args = (sixs_path,) + ret_code = subprocess.Popen(proc_args).wait() + if ret_code: + raise subprocess.CalledProcessError(ret_code, proc_args) + + +def _exec_11() -> None: + """Launch 6SV1.1 subprocess, bypassing main CLI entrypoint.""" + _exec_subprocess(sixs_bin.get_path("1.1")) + + +def _exec_21() -> None: + """Launch 6SV2.1 subprocess, bypassing main CLI entrypoint.""" + _exec_subprocess(sixs_bin.get_path("2.1")) + + def main(cli_args: list[str]) -> None: """CLI entrypoint.""" parser = _make_parser() @@ -77,10 +95,7 @@ def main(cli_args: list[str]) -> None: return if args.exec is not None: - proc_args = (sixs_bin.get_path(args.exec),) - ret_code = subprocess.Popen(proc_args).wait() - if ret_code: - raise subprocess.CalledProcessError(ret_code, proc_args) + _exec_subprocess(sixs_bin.get_path(args.exec)) return if args.path is not None: