Skip to content

Commit

Permalink
馃敤 Run OSX executables directly (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
roniemartinez committed Apr 23, 2022
1 parent 8550e12 commit 77f5cd8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
7 changes: 2 additions & 5 deletions browsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ def _launch(browser: str, path: str, args: Sequence[str], url: str = None) -> su
url_arg.append(url)

if sys.platform != "linux":
command = [path, *url_arg, "--args", *args]
command = [path, *url_arg, *args]
else:
command = [*shlex.split(path), *url_arg, "--args", *args]

if sys.platform == "darwin":
command = ["open", "--wait-apps", "--new", "--fresh", "-a", *command]
command = [*shlex.split(path), *url_arg, *args]

return subprocess.Popen(command)
4 changes: 3 additions & 1 deletion browsers/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def browsers() -> Iterator[Tuple[str, Dict]]: # type: ignore[return]
for path in paths:
with open(os.path.join(path, "Contents/Info.plist"), "rb") as f:
plist = plistlib.load(f)
executable_name = plist.get("CFBundleExecutable")
executable = os.path.join(path, "Contents/MacOS", executable_name)
display_name = plist.get("CFBundleDisplayName") or plist.get("CFBundleName", browser)
version = plist[version_string]
yield browser, dict(path=path, display_name=display_name, version=version)
yield browser, dict(path=executable, display_name=display_name, version=version)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pybrowsers"
version = "0.2.0"
version = "0.3.0"
repository = "https://github.com/roniemartinez/browsers"
description = "Python library for detecting and launching browsers"
authors = ["Ronie Martinez <ronmarti18@gmail.com>"]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_get_available_browsers(browser: str) -> None:
"chrome",
{
"display_name": "Google Chrome",
"path": "/Applications/Google Chrome.app",
"path": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"version": ANY,
},
marks=pytest.mark.skipif(sys.platform != "darwin", reason="osx-only"),
Expand All @@ -45,7 +45,7 @@ def test_get_available_browsers(browser: str) -> None:
"firefox",
{
"display_name": "Firefox",
"path": "/Applications/Firefox.app",
"path": "/Applications/Firefox.app/Contents/MacOS/firefox",
"version": ANY,
},
marks=pytest.mark.skipif(sys.platform != "darwin", reason="osx-only"),
Expand All @@ -55,7 +55,7 @@ def test_get_available_browsers(browser: str) -> None:
"safari",
{
"display_name": "Safari",
"path": "/Applications/Safari.app",
"path": "/Applications/Safari.app/Contents/MacOS/Safari",
"version": ANY,
},
marks=pytest.mark.skipif(sys.platform != "darwin", reason="osx-only"),
Expand All @@ -65,7 +65,7 @@ def test_get_available_browsers(browser: str) -> None:
"msedge",
{
"display_name": "Microsoft Edge",
"path": "/Applications/Microsoft Edge.app",
"path": "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
"version": ANY,
},
marks=pytest.mark.skipif(sys.platform != "darwin", reason="osx-only"),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"chrome_path",
(
pytest.param(
"/Applications/Google Chrome.app",
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
id="osx",
marks=pytest.mark.skipif(sys.platform != "darwin", reason="osx-only"),
),
Expand Down

0 comments on commit 77f5cd8

Please sign in to comment.