From 93365ffd4204a54724c07f8ade464157e94dd594 Mon Sep 17 00:00:00 2001 From: jgunstone Date: Fri, 14 Apr 2023 18:02:17 +0100 Subject: [PATCH] try except `maplocal` so it won't fail if it isn't installed --- src/ipyautoui/_utils.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/ipyautoui/_utils.py b/src/ipyautoui/_utils.py index 727df09f..7f3b144c 100644 --- a/src/ipyautoui/_utils.py +++ b/src/ipyautoui/_utils.py @@ -15,22 +15,42 @@ import inspect import immutables import getpass -import maplocal + frozenmap = immutables.Map +try: + import maplocal + + if maplocal.maplocal_openlocal_exists(): + from maplocal import openlocal as open_path + from maplocal import maplocal as make_new_path + else: + + def make_new_path(path, *args, **kwargs): + return path + + def open_path(path): + import subprocess + import sys + + if sys.platform == "linux": + subprocess.call(["xdg-open", path]) + else: + subprocess.call(["explorer.exe", path]) -if maplocal.maplocal_openlocal_exists(): - from maplocal import openlocal as open_path - from maplocal import maplocal as make_new_path -else: +except: def make_new_path(path, *args, **kwargs): return path - def open_path(path): - import subprocess + def open_path(path): + import subprocess + import sys - subprocess.call(["open", path]) + if sys.platform == "linux": + subprocess.call(["xdg-open", path]) + else: + subprocess.call(["explorer.exe", path]) def getuser():