commit be06e8b3561f5e4968bcafc28387e60496998c7af69866eb31e877fa84b695eb Author: Matej Cepl Date: Sun Apr 23 00:55:22 2023 +0000 Introduce python-browsers OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-browsers?expand=0&rev=1 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/_multibuild b/_multibuild new file mode 100644 index 0000000..fcc7b97 --- /dev/null +++ b/_multibuild @@ -0,0 +1,3 @@ + + test + diff --git a/_service b/_service new file mode 100644 index 0000000..c2574d3 --- /dev/null +++ b/_service @@ -0,0 +1,10 @@ + + + https://github.com/roniemartinez/browsers + git + @PARENT_TAG@ + refs/tags/0.5.2 + enable + + + diff --git a/_servicedata b/_servicedata new file mode 100644 index 0000000..a3dc57a --- /dev/null +++ b/_servicedata @@ -0,0 +1,4 @@ + + + https://github.com/roniemartinez/browsers + 904662c83fdc0397c482dfad9fae670289167bcd \ No newline at end of file diff --git a/browsers-0.5.2.obscpio b/browsers-0.5.2.obscpio new file mode 100644 index 0000000..273ad2d --- /dev/null +++ b/browsers-0.5.2.obscpio @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae4369a5603ff095b8332605cfe5a4b3a17783f4e56d991fb5e4728c6d7935bd +size 80395 diff --git a/browsers.obsinfo b/browsers.obsinfo new file mode 100644 index 0000000..043da75 --- /dev/null +++ b/browsers.obsinfo @@ -0,0 +1,4 @@ +name: browsers +version: 0.5.2 +mtime: 1671210338 +commit: 904662c83fdc0397c482dfad9fae670289167bcd diff --git a/chromium.patch b/chromium.patch new file mode 100644 index 0000000..c497289 --- /dev/null +++ b/chromium.patch @@ -0,0 +1,11 @@ +--- a/browsers/linux.py 2023-04-19 23:19:27.970310924 +0200 ++++ b/browsers/linux.py 2023-04-20 00:27:12.388333281 +0200 +@@ -9,7 +9,7 @@ + LINUX_DESKTOP_ENTRY_LIST = ( + # desktop entry name can be "firefox.desktop" or "firefox_firefox.desktop" + ("chrome", ("google-chrome",)), +- ("chromium", ("chromium", "chromium_chromium")), ++ ("chromium", ("chromium", "chromium-browser")), + ("firefox", ("firefox", "firefox_firefox")), + ("msedge", ("microsoft-edge",)), + ("opera", ("opera_opera",)), diff --git a/python-browsers.changes b/python-browsers.changes new file mode 100644 index 0000000..78fcf49 --- /dev/null +++ b/python-browsers.changes @@ -0,0 +1,4 @@ +------------------------------------------------------------------- +Wed Apr 19 21:22:36 UTC 2023 - Georg Pfuetzenreuter + +- Initial package diff --git a/python-browsers.spec b/python-browsers.spec new file mode 100644 index 0000000..e7a35e3 --- /dev/null +++ b/python-browsers.spec @@ -0,0 +1,97 @@ +# +# spec file for package python-browsers +# +# Copyright (c) 2023 Georg Pfuetzenreuter +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +%global flavor @BUILD_FLAVOR@%{nil} +%if "%{flavor}" == "test" +%define psuffix -test +%bcond_without test +%else +%define psuffix %{nil} +%bcond_with test +%endif +%define appname browsers +Name: python-%{appname}%{psuffix} +Version: 0.5.2 +Release: 0 +Summary: Library for detecting and launching browsers +License: MIT +URL: https://github.com/roniemartinez/browsers +Source: _service +# - test with Chromium instead of unavailable proprietary Chrome +# - adjust Firefox .desktop entry name +# - add Firefox to launch test +Patch0: test.patch +# - adjust Chromium .desktop file name +Patch1: chromium.patch +BuildRequires: %{python_module pip} +BuildRequires: %{python_module poetry} +BuildRequires: %{pythons} +BuildRequires: fdupes +BuildRequires: python-rpm-macros +Requires: python3-pyxdg +Provides: python3-pybrowsers +BuildArch: noarch +# Browsers like Chromium are not built for other architectures +ExclusiveArch: aarch64 riscv64 x86_64 +%if %{with test} +BuildRequires: %{python_module browsers} +BuildRequires: %{python_module pytest-cov} +BuildRequires: %{python_module pytest} +BuildRequires: %{python_module pyxdg} +BuildRequires: MozillaFirefox +BuildRequires: chromium +# Firefox needs /etc/os-release +BuildRequires: distribution-release +%endif +%python_subpackages + +%description +Python library for detecting and launching browsers + +%prep +%autosetup -p1 -DTn %{_sourcedir}/%{appname}-%{version} +sed -i '/pywin32/d' pyproject.toml + +%build +%if !%{with test} +%pyproject_wheel +%endif + +%install +%if !%{with test} +%pyproject_install +%python_expand %fdupes %{buildroot}%{$python_sitelib}/%{appname} +%endif + +%if %{with test} +%check +%python_expand $python -m poetry config --local virtualenvs.in-project true && $python -m poetry run pytest +rm -r /home/abuild/.config +%endif + +%if !%{with test} +%files %{python_files} +%license LICENSE +%doc README.md +%dir %{python_sitelib}/%{appname} +%{python_sitelib}/py%{appname}-%{version}*-info +%{python_sitelib}/%{appname}/*.py +%pycache_only %{python_sitelib}/%{appname}/__pycache__ +%endif + +%changelog diff --git a/test.patch b/test.patch new file mode 100644 index 0000000..4066e6a --- /dev/null +++ b/test.patch @@ -0,0 +1,93 @@ +--- a/tests/test_detect.py 2023-04-20 01:43:34.761649487 +0200 ++++ b/tests/test_detect.py 2023-04-20 01:43:56.461768969 +0200 +@@ -14,7 +14,7 @@ + @pytest.mark.parametrize( + "browser", + ( +- pytest.param("chrome", id="chrome"), ++ pytest.param("chromium", id="chromium"), + pytest.param("firefox", id="firefox"), + pytest.param("safari", id="safari", marks=pytest.mark.skipif(sys.platform != "darwin", reason="osx-only")), + pytest.param( +@@ -76,21 +76,21 @@ + id="msedge-osx", + ), + pytest.param( +- "chrome", ++ "chromium", + { +- "browser_type": "chrome", +- "display_name": "Google Chrome", +- "path": "/usr/bin/google-chrome-stable", ++ "browser_type": "chromium", ++ "display_name": "Chromium Web Browser", ++ "path": "/usr/bin/chromium-browser", + "version": ANY, + }, + marks=pytest.mark.skipif(sys.platform != "linux", reason="linux-only"), +- id="chrome-linux", ++ id="chromium-linux", + ), + pytest.param( + "firefox", + { + "browser_type": "firefox", +- "display_name": "Firefox Web Browser", ++ "display_name": "Firefox", + "path": "firefox", + "version": ANY, + }, +--- a/tests/test_launch.py 2023-04-20 01:43:34.761649487 +0200 ++++ b/tests/test_launch.py 2023-04-20 01:44:34.041975888 +0200 +@@ -11,30 +11,36 @@ + + + @pytest.mark.parametrize( +- "chrome_path", ++ "chromium_path", + ( + pytest.param( +- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", +- id="osx", +- marks=pytest.mark.skipif(sys.platform != "darwin", reason="osx-only"), +- ), +- pytest.param( +- "/usr/bin/google-chrome-stable", +- id="linux", ++ "/usr/bin/chromium-browser", ++ id="chromium-linux", + marks=pytest.mark.skipif(sys.platform != "linux", reason="linux-only"), + ), ++ ), ++) ++ ++@mock.patch.object(browsers, "_launch") ++def test_launch_chromium(mock_launch: mock.MagicMock, chromium_path: str) -> None: ++ browsers.launch("chromium", url="file:///tmp/dummy.html") ++ mock_launch.assert_called_with("chromium", chromium_path, [], "file:///tmp/dummy.html") ++ ++@pytest.mark.parametrize( ++ "firefox_path", ++ ( + pytest.param( +- r"C:\Program Files\Google\Chrome\Application\chrome.exe", +- id="windows", +- marks=pytest.mark.skipif(sys.platform != "win32", reason="windows-only"), ++ "firefox", ++ id="firefox-linux", ++ marks=pytest.mark.skipif(sys.platform != "linux", reason="linux-only"), + ), + ), + ) +-@mock.patch.object(browsers, "_launch") +-def test_launch(mock_launch: mock.MagicMock, chrome_path: str) -> None: +- browsers.launch("chrome", url="https://github.com/roniemartinez/browsers") +- mock_launch.assert_called_with("chrome", chrome_path, [], "https://github.com/roniemartinez/browsers") + ++@mock.patch.object(browsers, "_launch") ++def test_launch_firefox(mock_launch: mock.MagicMock, firefox_path: str) -> None: ++ browsers.launch("firefox", url="file:///tmp/dummy.html") ++ mock_launch.assert_called_with("firefox", firefox_path, [], "file:///tmp/dummy.html") + + @mock.patch.object(browsers, "_launch") + def test_launch_no_browser(mock_launch: mock.MagicMock) -> None: