From e9b27422e0ca8586dd19e8ab2d04ce4639d0ffd9 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Thu, 22 Aug 2024 09:59:33 -0400 Subject: [PATCH] Get version of python for installed library Signed-off-by: Daniel J Walsh --- ramalama.py | 16 ++++++++++------ ramalama/cli.py | 7 ------- ramalama/common.py | 9 ++++++++- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/ramalama.py b/ramalama.py index dc953972..5c98aa7d 100755 --- a/ramalama.py +++ b/ramalama.py @@ -29,13 +29,17 @@ def main(args): if host != port: port = host.rsplit(':', 1)[1] + syspath = '/usr/share/ramalama/python' + sys.path.insert(0, syspath) + if conman: home = os.path.expanduser('~') - cwd = os.getcwd() - wd = os.path.join(cwd, "ramalama") - if not os.path.exists(wd): - wd = "/usr/lib/python3.12/site-packages/podman" - libpath = "/usr/lib/python3.12/site-packages/ramalama" + wd = "ramalama" + for p in sys.path: + target = p+"ramalama" + if os.path.exists(target): + wd = target + break conman_args = [conman, "run", "--rm", "-it", @@ -44,7 +48,7 @@ def main(args): f"-v{home}:{home}", "-v/tmp:/tmp", f"-v{sys.argv[0]}:/usr/bin/ramalama", - f"-v{wd}:{libpath}", + f"-v{wd}:{syspath}", "-e", "RAMALAMA_HOST", "-p", f"{host}:{port}", "quay.io/ramalama/ramalama:latest", __file__] + args diff --git a/ramalama/cli.py b/ramalama/cli.py index 43da0c24..4acda2c4 100644 --- a/ramalama/cli.py +++ b/ramalama/cli.py @@ -246,13 +246,6 @@ def create_store(): return store -def in_container(): - if os.path.exists("/run/.containerenv") or os.path.exists("/.dockerenv") or os.getenv("container"): - return True - - return False - - funcDict = {} funcDict["list"] = list_cli funcDict["ls"] = list_cli diff --git a/ramalama/common.py b/ramalama/common.py index 5a290970..9134935d 100644 --- a/ramalama/common.py +++ b/ramalama/common.py @@ -9,8 +9,15 @@ x = False +def in_container(): + if os.path.exists("/run/.containerenv") or os.path.exists("/.dockerenv") or os.getenv("container"): + return True + + return False + + def container_manager(): - if sys.platform == "darwin": + if in_container() or sys.platform == "darwin": return "" if sys.platform != "linux":