diff --git a/Applications/Python/ogs/_internal/__init__.py b/Applications/Python/ogs/_internal/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..ba497f9ed6810773225511a25225fab2bb6bef6b 100644 --- a/Applications/Python/ogs/_internal/__init__.py +++ b/Applications/Python/ogs/_internal/__init__.py @@ -0,0 +1,3 @@ +import os + +OGS_USE_PATH = os.getenv("OGS_USE_PATH", "False").lower() in ("true", "1", "t") diff --git a/Applications/Python/ogs/_internal/provide_ogs_cli_tools_via_wheel.py b/Applications/Python/ogs/_internal/provide_ogs_cli_tools_via_wheel.py index da8df9ccc0b5422d1c355f23b0bf2db117f8bdc2..185846f944241f13469b024157f5ea536ebd3f87 100644 --- a/Applications/Python/ogs/_internal/provide_ogs_cli_tools_via_wheel.py +++ b/Applications/Python/ogs/_internal/provide_ogs_cli_tools_via_wheel.py @@ -4,6 +4,8 @@ import subprocess import sys from pathlib import Path +from . import OGS_USE_PATH + # Here, we assume that this script is installed, e.g., in a virtual environment # alongside a "bin" directory. OGS_BIN_DIR = Path(__file__).parent.parent.parent / "bin" @@ -82,6 +84,7 @@ def pyproject_get_binaries(): } +# Not used when OGS_USE_PATH is true! def ogs(): raise SystemExit(ogs_with_args(sys.argv)) @@ -114,12 +117,13 @@ if "PEP517_BUILD_BACKEND" not in os.environ: def _program(name, args): exe = OGS_BIN_DIR / name - if "OGS_USE_PATH" in os.environ: + if OGS_USE_PATH: exe = name return subprocess.run([exe] + args).returncode # noqa: PLW1510 FUNC_TEMPLATE = """def {0}(): raise SystemExit(_program("{0}", sys.argv[1:]))""" for f in binaries_list: - if f == "ogs" and "OGS_USE_PATH" not in os.environ: + if f == "ogs" and not OGS_USE_PATH: continue # provided by separate function + # When OGS_USE_PATH is true then ogs()-function above is not used! exec(FUNC_TEMPLATE.format(f)) diff --git a/Applications/Python/ogs/_internal/wrap_cli_tools.py b/Applications/Python/ogs/_internal/wrap_cli_tools.py index 85927cd196dbd81f8b9b197104b496d92f46e037..78ea940473a2049eead92a64d471a76cb508ac43 100644 --- a/Applications/Python/ogs/_internal/wrap_cli_tools.py +++ b/Applications/Python/ogs/_internal/wrap_cli_tools.py @@ -1,7 +1,7 @@ -import os import subprocess from pathlib import Path +from . import OGS_USE_PATH from .provide_ogs_cli_tools_via_wheel import binaries_list, ogs_with_args # Here, we assume that this script is installed, e.g., in a virtual environment @@ -43,7 +43,7 @@ class CLI: cmdline = CLI._get_cmdline("ogs", *args, **kwargs) - if "OGS_USE_PATH" in os.environ: + if OGS_USE_PATH: return subprocess.call(cmdline) return ogs_with_args(cmdline) @@ -67,9 +67,8 @@ class CLI: @staticmethod def _get_run_cmd(attr): def run_cmd(*args, **kwargs): - # TODO provide override via os.environ? cmd = OGS_BIN_DIR / attr - if "OGS_USE_PATH" in os.environ: + if OGS_USE_PATH: cmd = attr cmdline = CLI._get_cmdline(cmd, *args, **kwargs) return subprocess.call(cmdline)