Skip to content

Commit

Permalink
Expose console scripts that launch 6S in a subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
brianschubert committed Sep 10, 2023
1 parent 1842e63 commit c953140
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 19 additions & 4 deletions src/sixs_bin/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down

0 comments on commit c953140

Please sign in to comment.