From 3f9e45a34428fa312bd2baf92541594b938457e6 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 12 Feb 2021 17:51:07 -0500 Subject: [PATCH] Detect ghostscript and default image viewer in FreeBSD (#878) Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/__init__.py | 2 +- pygmt/helpers/utils.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pygmt/__init__.py b/pygmt/__init__.py index b7a6aa6007f..3afdf093e4f 100644 --- a/pygmt/__init__.py +++ b/pygmt/__init__.py @@ -95,7 +95,7 @@ def _get_ghostscript_version(): Get ghostscript version. """ os_name = sys.platform - if os_name.startswith("linux") or os_name == "darwin": + if os_name.startswith(("linux", "freebsd", "darwin")): cmds = ["gs"] elif os_name == "win32": cmds = ["gswin64c.exe", "gswin32c.exe"] diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index 920579fd1d8..92f55feb678 100644 --- a/pygmt/helpers/utils.py +++ b/pygmt/helpers/utils.py @@ -209,9 +209,10 @@ def launch_external_viewer(fname): # Open the file with the default viewer. # Fall back to the browser if can't recognize the operating system. - if sys.platform.startswith("linux") and shutil.which("xdg-open"): + os_name = sys.platform + if os_name.startswith(("linux", "freebsd")) and shutil.which("xdg-open"): subprocess.run(["xdg-open", fname], check=False, **run_args) - elif sys.platform == "darwin": # Darwin is macOS + elif os_name == "darwin": # Darwin is macOS subprocess.run(["open", fname], check=False, **run_args) else: webbrowser.open_new_tab("file://{}".format(fname))