From 8cb09bcade74584d28835dd454460e0d3788a114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Sun, 18 Aug 2024 07:32:15 +0200 Subject: [PATCH 01/18] added a ubunu test --- .github/workflows/test_plugin.yml | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/test_plugin.yml diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml new file mode 100644 index 0000000..0c37589 --- /dev/null +++ b/.github/workflows/test_plugin.yml @@ -0,0 +1,32 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + schedule: + # runs once a week + # - cron: '0 6 * * 0' + # runs every day + - cron: '0 12 * * *' + push: + branches: [ "main"] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Pull qgis image + run: docker pull qgis/qgis:stable + + - name: Run tests + run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest test_plugins -s" + From 90f1b03511b570f1671ed941880edaa8102bcd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Mon, 19 Aug 2024 21:43:36 +0200 Subject: [PATCH 02/18] added a test --- .github/workflows/test_plugin.yml | 2 +- a00_qpip/plugin.py | 17 ++++++++++---- a00_qpip/utils.py | 6 ++++- tests/test_finding_req.py | 38 +++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 tests/test_finding_req.py diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 0c37589..3cfb717 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -28,5 +28,5 @@ jobs: run: docker pull qgis/qgis:stable - name: Run tests - run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest test_plugins -s" + run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python -m pip install pytest-qgis" xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" diff --git a/a00_qpip/plugin.py b/a00_qpip/plugin.py index 963a9e8..b616b78 100644 --- a/a00_qpip/plugin.py +++ b/a00_qpip/plugin.py @@ -20,15 +20,20 @@ class Plugin: """QGIS Plugin Implementation.""" - def __init__(self, iface): + def __init__(self, iface, test_path=None): self.iface = iface self._defered_packages = [] self.settings = QgsSettings() self.settings.beginGroup("QPIP") - - self.plugins_path = os.path.join( - QgsApplication.qgisSettingsDirPath(), "python", "plugins" - ) + + if test_path is None: + self.plugins_path = os.path.join( + QgsApplication.qgisSettingsDirPath(), "python", "plugins" + ) + self.test_mode = False + else: + self.plugins_path = test_path + self.test_mode = True self.prefix_path = os.path.join( QgsApplication.qgisSettingsDirPath().replace("/", os.path.sep), "python", @@ -170,6 +175,8 @@ def check_deps_and_prompt_install(self, additional_plugins=[], force_gui=False): dialog = MainDialog( libs.values(), self._check_on_startup(), self._check_on_install() ) + if self.test_mode: + return dialog.reqs_to_install if dialog.exec_(): reqs_to_uninstall = dialog.reqs_to_uninstall if reqs_to_uninstall: diff --git a/a00_qpip/utils.py b/a00_qpip/utils.py index acd2bfa..b2d508c 100644 --- a/a00_qpip/utils.py +++ b/a00_qpip/utils.py @@ -90,7 +90,11 @@ def run_cmd(args, description="running a system command"): f"Encountered an error while {description} !", parent=iface.mainWindow(), ) - message.setDetailedText(full_output) + if "no module named pip" in full_output.lower(): + msg = """It looks like that the python installation of qgis is missing pip, please install this separately first.""" + message.setDetailedText(msg) + else: + message.setDetailedText(full_output) message.exec_() else: log("Command succeeded.") diff --git a/tests/test_finding_req.py b/tests/test_finding_req.py new file mode 100644 index 0000000..7ab96aa --- /dev/null +++ b/tests/test_finding_req.py @@ -0,0 +1,38 @@ +import os + +import pytest +from pytest_qgis import qgis_iface + +from PyQt5.QtCore import QSettings, QDate + +from a00_qpip.plugin import Plugin + +class initializationCompleted: + def connect(self): + pass + +def popWidget(): + return True + +THIS_DIR = os.path.dirname(__file__) + +@pytest.fixture() +def plugin(qgis_iface): + qgis_iface.initializationCompleted = initializationCompleted + qgis_iface.messageBar().popWidget = popWidget + plugin = Plugin(qgis_iface, '.') + yield plugin + + +def test_plugin_a(plugin: Plugin): + plugin_a = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_a') + libs = plugin.check_deps_and_prompt_install([plugin_a]) + assert len(libs) == 2 + assert libs[0] == 'cowsay==4.0' + + +def test_plugin_b(plugin: Plugin): + plugin_b = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_b') + libs = plugin.check_deps_and_prompt_install([plugin_b]) + assert len(libs) == 2 + assert libs[0] == 'cowsay==5.0' \ No newline at end of file From 4838c5878b0deab9dcb1282df8a0db2e5ebb597b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Mon, 19 Aug 2024 21:47:09 +0200 Subject: [PATCH 03/18] fixed typo --- .github/workflows/test_plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 3cfb717..9d20c9a 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -28,5 +28,5 @@ jobs: run: docker pull qgis/qgis:stable - name: Run tests - run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python -m pip install pytest-qgis" xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" + run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python -m pip install pytest-qgis xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" From 91030cd39eed8bc7551c3665ec0c4a5721605036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Mon, 19 Aug 2024 21:49:23 +0200 Subject: [PATCH 04/18] fixed minor ci typo2 --- .github/workflows/test_plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 9d20c9a..6ef232d 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -28,5 +28,5 @@ jobs: run: docker pull qgis/qgis:stable - name: Run tests - run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python -m pip install pytest-qgis xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" + run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" From 839587e08e902001a1a1d74f12e5cbe0e22b1a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Mon, 19 Aug 2024 21:52:30 +0200 Subject: [PATCH 05/18] ci --- .github/workflows/test_plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 6ef232d..1f9f603 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -28,5 +28,5 @@ jobs: run: docker pull qgis/qgis:stable - name: Run tests - run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" + run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis && xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" From 1bb3525156483d69a73a199db054543820b05082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Mon, 19 Aug 2024 21:56:25 +0200 Subject: [PATCH 06/18] ci --- .github/workflows/test_plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 1f9f603..2607dc3 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -28,5 +28,5 @@ jobs: run: docker pull qgis/qgis:stable - name: Run tests - run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis && xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" + run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis --break-system-packages && xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" From 0e5486de2198815f6f3d8235f6d3a0b1c2a2ab2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Tue, 20 Aug 2024 19:01:09 +0200 Subject: [PATCH 07/18] minor fixes --- .github/workflows/test_plugin.yml | 11 +++-------- a00_qpip/plugin.py | 2 +- tests/test_finding_req.py | 6 ++++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 2607dc3..052f3c4 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -4,15 +4,10 @@ name: Python application on: - schedule: - # runs once a week - # - cron: '0 6 * * 0' - # runs every day - - cron: '0 12 * * *' push: - branches: [ "main"] + branches: ["main"] pull_request: - branches: [ "master" ] + branches: ["main"] permissions: contents: read @@ -28,5 +23,5 @@ jobs: run: docker pull qgis/qgis:stable - name: Run tests - run: docker run --net=host --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis --break-system-packages && xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" + run: docker run --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis --break-system-packages && xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" diff --git a/a00_qpip/plugin.py b/a00_qpip/plugin.py index b616b78..24ecda6 100644 --- a/a00_qpip/plugin.py +++ b/a00_qpip/plugin.py @@ -176,7 +176,7 @@ def check_deps_and_prompt_install(self, additional_plugins=[], force_gui=False): libs.values(), self._check_on_startup(), self._check_on_install() ) if self.test_mode: - return dialog.reqs_to_install + return dialog if dialog.exec_(): reqs_to_uninstall = dialog.reqs_to_uninstall if reqs_to_uninstall: diff --git a/tests/test_finding_req.py b/tests/test_finding_req.py index 7ab96aa..97550d3 100644 --- a/tests/test_finding_req.py +++ b/tests/test_finding_req.py @@ -26,13 +26,15 @@ def plugin(qgis_iface): def test_plugin_a(plugin: Plugin): plugin_a = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_a') - libs = plugin.check_deps_and_prompt_install([plugin_a]) + dialog = plugin.check_deps_and_prompt_install([plugin_a]) + libs = dialog.reqs_to_install assert len(libs) == 2 assert libs[0] == 'cowsay==4.0' def test_plugin_b(plugin: Plugin): plugin_b = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_b') - libs = plugin.check_deps_and_prompt_install([plugin_b]) + dialog = plugin.check_deps_and_prompt_install([plugin_b]) + libs = dialog.reqs_to_install assert len(libs) == 2 assert libs[0] == 'cowsay==5.0' \ No newline at end of file From 9142c63fc939d8bdf0b2bd77e82b9250c76ee548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 08:19:38 +0200 Subject: [PATCH 08/18] Updated the plugin with some refactoring --- .github/workflows/test_plugin.yml | 8 +++- a00_qpip/plugin.py | 70 ++++++++++++++++++------------- a00_qpip/utils.py | 6 +-- 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 052f3c4..f50dbda 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -22,6 +22,10 @@ jobs: - name: Pull qgis image run: docker pull qgis/qgis:stable + - name: Pip install + run: | + docker run --name qgis_container --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis --break-system-packages" + docker commit qgis_container qgis_with_deps + - name: Run tests - run: docker run --volume $(pwd):/app -w=/app qgis/qgis:stable sh -c "python3 -m pip install pytest-qgis --break-system-packages && xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" - + run: docker run --volume $(pwd):/app -w=/app qgis_with_deps sh -c "xvfb-run -s '+extension GLX -screen 0 1024x768x24' python3 -m pytest tests -s" diff --git a/a00_qpip/plugin.py b/a00_qpip/plugin.py index 24ecda6..7c6f69f 100644 --- a/a00_qpip/plugin.py +++ b/a00_qpip/plugin.py @@ -2,6 +2,7 @@ import platform import subprocess import sys +from typing import List from collections import defaultdict, namedtuple from importlib import metadata @@ -75,9 +76,12 @@ def initGui(self): def initComplete(self): if self._defered_packages: log(f"Initialization complete. Loading deferred packages") - self.check_deps_and_prompt_install( + dialog, run_gui = self.check_deps( additional_plugins=self._defered_packages ) + if run_gui: + self.promt_install(dialog) + self.save_settings(dialog) self.start_packages(self._defered_packages) self._defered_packages = [] @@ -123,11 +127,14 @@ def patched_load_plugin(self, packageName): return self._original_loadPlugin(packageName) else: log(f"Check on install enabled, we check {packageName}.") - self.check_deps_and_prompt_install(additional_plugins=[packageName]) + dialog, run_gui = self.check_deps(additional_plugins=[packageName]) + if run_gui: + self.promt_install(dialog) + self.save_settings(dialog) self.start_packages([packageName]) return True - def check_deps_and_prompt_install(self, additional_plugins=[], force_gui=False): + def check_deps(self, additional_plugins=[]) -> List[MainDialog, bool]: """ This checks dependencies for installed plugins and to-be installed plugins. If anything is missing, shows a GUI to install them. @@ -170,33 +177,34 @@ def check_deps_and_prompt_install(self, additional_plugins=[], force_gui=False): req = Req(plugin_name, str(requirement), error) libs[requirement.key].name = requirement.key libs[requirement.key].required_by.append(req) + dialog = MainDialog( + libs.values(), self._check_on_startup(), self._check_on_install() + ) + return dialog, needs_gui + + def promt_install(self, dialog: MainDialog): + """Promts the install dialog and ask the user what to install""" + if dialog.exec_(): + reqs_to_uninstall = dialog.reqs_to_uninstall + if reqs_to_uninstall: + log(f"Will uninstall selected dependencies : {reqs_to_uninstall}") + self.pip_uninstall_reqs(reqs_to_uninstall) + + reqs_to_install = dialog.reqs_to_install + if reqs_to_install: + log(f"Will install selected dependencies : {reqs_to_install}") + self.pip_install_reqs(reqs_to_install) + + def save_settings(self, dialog): + """Stores the settings values""" + sys.path_importer_cache.clear() - if force_gui or needs_gui: - dialog = MainDialog( - libs.values(), self._check_on_startup(), self._check_on_install() - ) - if self.test_mode: - return dialog - if dialog.exec_(): - reqs_to_uninstall = dialog.reqs_to_uninstall - if reqs_to_uninstall: - log(f"Will uninstall selected dependencies : {reqs_to_uninstall}") - self.pip_uninstall_reqs(reqs_to_uninstall) - - reqs_to_install = dialog.reqs_to_install - if reqs_to_install: - log(f"Will install selected dependencies : {reqs_to_install}") - self.pip_install_reqs(reqs_to_install) - - sys.path_importer_cache.clear() - - # Save these even if the dialog was closed - self.settings.setValue( - "check_on_startup", "yes" if dialog.check_on_startup else "no" - ) - self.settings.setValue( - "check_on_install", "yes" if dialog.check_on_install else "no" - ) + self.settings.setValue( + "check_on_startup", "yes" if dialog.check_on_startup else "no" + ) + self.settings.setValue( + "check_on_install", "yes" if dialog.check_on_install else "no" + ) def start_packages(self, packageNames): """ @@ -256,7 +264,9 @@ def pip_install_reqs(self, reqs_to_install): ) def check(self): - self.check_deps_and_prompt_install(force_gui=True) + dialog, _ = self.check_deps() + self.promt_install(dialog) + self.save_settings(dialog) def show_folder(self): if platform.system() == "Windows": diff --git a/a00_qpip/utils.py b/a00_qpip/utils.py index b2d508c..acd2bfa 100644 --- a/a00_qpip/utils.py +++ b/a00_qpip/utils.py @@ -90,11 +90,7 @@ def run_cmd(args, description="running a system command"): f"Encountered an error while {description} !", parent=iface.mainWindow(), ) - if "no module named pip" in full_output.lower(): - msg = """It looks like that the python installation of qgis is missing pip, please install this separately first.""" - message.setDetailedText(msg) - else: - message.setDetailedText(full_output) + message.setDetailedText(full_output) message.exec_() else: log("Command succeeded.") From e39b5780715add7e4d37cac68bf2ab5ca37a7e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 08:21:10 +0200 Subject: [PATCH 09/18] updated test call --- a00_qpip/plugin.py | 2 -- tests/test_finding_req.py | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/a00_qpip/plugin.py b/a00_qpip/plugin.py index 7c6f69f..abcd8bf 100644 --- a/a00_qpip/plugin.py +++ b/a00_qpip/plugin.py @@ -31,10 +31,8 @@ def __init__(self, iface, test_path=None): self.plugins_path = os.path.join( QgsApplication.qgisSettingsDirPath(), "python", "plugins" ) - self.test_mode = False else: self.plugins_path = test_path - self.test_mode = True self.prefix_path = os.path.join( QgsApplication.qgisSettingsDirPath().replace("/", os.path.sep), "python", diff --git a/tests/test_finding_req.py b/tests/test_finding_req.py index 97550d3..9f4c18d 100644 --- a/tests/test_finding_req.py +++ b/tests/test_finding_req.py @@ -26,7 +26,7 @@ def plugin(qgis_iface): def test_plugin_a(plugin: Plugin): plugin_a = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_a') - dialog = plugin.check_deps_and_prompt_install([plugin_a]) + dialog = plugin.check_deps([plugin_a]) libs = dialog.reqs_to_install assert len(libs) == 2 assert libs[0] == 'cowsay==4.0' @@ -34,7 +34,7 @@ def test_plugin_a(plugin: Plugin): def test_plugin_b(plugin: Plugin): plugin_b = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_b') - dialog = plugin.check_deps_and_prompt_install([plugin_b]) + dialog = plugin.check_deps([plugin_b]) libs = dialog.reqs_to_install assert len(libs) == 2 assert libs[0] == 'cowsay==5.0' \ No newline at end of file From 224e9d5cba5ef8edeeddd6515b5d0d9ac2f92750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 08:28:06 +0200 Subject: [PATCH 10/18] Fixed typhint mistake --- a00_qpip/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/a00_qpip/plugin.py b/a00_qpip/plugin.py index abcd8bf..3228529 100644 --- a/a00_qpip/plugin.py +++ b/a00_qpip/plugin.py @@ -132,7 +132,7 @@ def patched_load_plugin(self, packageName): self.start_packages([packageName]) return True - def check_deps(self, additional_plugins=[]) -> List[MainDialog, bool]: + def check_deps(self, additional_plugins=[]) -> MainDialog | bool: """ This checks dependencies for installed plugins and to-be installed plugins. If anything is missing, shows a GUI to install them. From a2401798f3659763933e0552c0e8b088e71c6df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 08:32:01 +0200 Subject: [PATCH 11/18] Updated github action to run on all branches --- .github/workflows/test_plugin.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index f50dbda..9504c07 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -1,13 +1,14 @@ # This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Python application +name: Run tests on: push: - branches: ["main"] + branches: + - '**' pull_request: - branches: ["main"] + - '**' permissions: contents: read From f3f40a43f46a2ed280a164f8393b0d2358dc0799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 08:34:36 +0200 Subject: [PATCH 12/18] update github action --- .github/workflows/test_plugin.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 9504c07..a0a38f1 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -5,10 +5,10 @@ name: Run tests on: push: - branches: - - '**' + branches: + - '**' pull_request: - - '**' + - '**' permissions: contents: read From d6a45f6f01a7c1c964e612c342221a2dfc9244af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 08:36:47 +0200 Subject: [PATCH 13/18] update github action --- .github/workflows/test_plugin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index a0a38f1..6bec539 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -6,9 +6,9 @@ name: Run tests on: push: branches: - - '**' + - '**' pull_request: - - '**' + - 'main' permissions: contents: read From 34f34881338c87b7620434e3a7793fb900eb22b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 08:38:06 +0200 Subject: [PATCH 14/18] new update --- .github/workflows/test_plugin.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 6bec539..64ffb52 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -5,9 +5,8 @@ name: Run tests on: push: - branches: - - '**' pull_request: + branches: - 'main' permissions: From 773c2907f2cc01bbf9679bb1dceea3e84d7a6266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 08:40:44 +0200 Subject: [PATCH 15/18] fixed test --- tests/test_finding_req.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_finding_req.py b/tests/test_finding_req.py index 9f4c18d..afe9057 100644 --- a/tests/test_finding_req.py +++ b/tests/test_finding_req.py @@ -26,7 +26,7 @@ def plugin(qgis_iface): def test_plugin_a(plugin: Plugin): plugin_a = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_a') - dialog = plugin.check_deps([plugin_a]) + dialog, _ = plugin.check_deps([plugin_a]) libs = dialog.reqs_to_install assert len(libs) == 2 assert libs[0] == 'cowsay==4.0' @@ -34,7 +34,7 @@ def test_plugin_a(plugin: Plugin): def test_plugin_b(plugin: Plugin): plugin_b = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_b') - dialog = plugin.check_deps([plugin_b]) + dialog, _ = plugin.check_deps([plugin_b]) libs = dialog.reqs_to_install assert len(libs) == 2 assert libs[0] == 'cowsay==5.0' \ No newline at end of file From 4e650d60eee1f4078d7a0ec5355387abca3f08cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 08:48:01 +0200 Subject: [PATCH 16/18] Added another test and some more docstrings --- a00_qpip/plugin.py | 10 +++++++--- tests/test_finding_req.py | 8 +++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/a00_qpip/plugin.py b/a00_qpip/plugin.py index 3228529..17f5d51 100644 --- a/a00_qpip/plugin.py +++ b/a00_qpip/plugin.py @@ -21,18 +21,18 @@ class Plugin: """QGIS Plugin Implementation.""" - def __init__(self, iface, test_path=None): + def __init__(self, iface, plugin_path=None): self.iface = iface self._defered_packages = [] self.settings = QgsSettings() self.settings.beginGroup("QPIP") - if test_path is None: + if plugin_path is None: self.plugins_path = os.path.join( QgsApplication.qgisSettingsDirPath(), "python", "plugins" ) else: - self.plugins_path = test_path + self.plugins_path = plugin_path self.prefix_path = os.path.join( QgsApplication.qgisSettingsDirPath().replace("/", os.path.sep), "python", @@ -136,6 +136,10 @@ def check_deps(self, additional_plugins=[]) -> MainDialog | bool: """ This checks dependencies for installed plugins and to-be installed plugins. If anything is missing, shows a GUI to install them. + + The function returns: + - MainDialog, the QDialog object (without opening it) + - A bool if the dialog needs to be opened or not """ plugin_names = [*qgis.utils.active_plugins, *additional_plugins] diff --git a/tests/test_finding_req.py b/tests/test_finding_req.py index afe9057..08c148a 100644 --- a/tests/test_finding_req.py +++ b/tests/test_finding_req.py @@ -26,15 +26,17 @@ def plugin(qgis_iface): def test_plugin_a(plugin: Plugin): plugin_a = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_a') - dialog, _ = plugin.check_deps([plugin_a]) + dialog, needs_gui = plugin.check_deps([plugin_a]) libs = dialog.reqs_to_install assert len(libs) == 2 assert libs[0] == 'cowsay==4.0' + assert needs_gui def test_plugin_b(plugin: Plugin): plugin_b = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_b') - dialog, _ = plugin.check_deps([plugin_b]) + dialog, needs_gui = plugin.check_deps([plugin_b]) libs = dialog.reqs_to_install assert len(libs) == 2 - assert libs[0] == 'cowsay==5.0' \ No newline at end of file + assert libs[0] == 'cowsay==5.0' + assert needs_gui From cb7052ebd173a67278d3536817cb0a1765e60bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 10:58:19 +0200 Subject: [PATCH 17/18] Fixed black issues --- a00_qpip/plugin.py | 14 +++++++------- tests/test_finding_req.py | 14 +++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/a00_qpip/plugin.py b/a00_qpip/plugin.py index 17f5d51..0859e60 100644 --- a/a00_qpip/plugin.py +++ b/a00_qpip/plugin.py @@ -26,7 +26,7 @@ def __init__(self, iface, plugin_path=None): self._defered_packages = [] self.settings = QgsSettings() self.settings.beginGroup("QPIP") - + if plugin_path is None: self.plugins_path = os.path.join( QgsApplication.qgisSettingsDirPath(), "python", "plugins" @@ -74,9 +74,7 @@ def initGui(self): def initComplete(self): if self._defered_packages: log(f"Initialization complete. Loading deferred packages") - dialog, run_gui = self.check_deps( - additional_plugins=self._defered_packages - ) + dialog, run_gui = self.check_deps(additional_plugins=self._defered_packages) if run_gui: self.promt_install(dialog) self.save_settings(dialog) @@ -98,7 +96,9 @@ def unload(self): os.environ["PYTHONPATH"] = os.environ["PYTHONPATH"].replace( self.bin_path + os.pathsep, "" ) - os.environ["PATH"] = os.environ["PATH"].replace(self.bin_path + os.pathsep, "") + os.environ["PATH"] = os.environ["PATH"].replace( + self.bin_path + os.pathsep, "" + ) def patched_load_plugin(self, packageName): """ @@ -183,7 +183,7 @@ def check_deps(self, additional_plugins=[]) -> MainDialog | bool: libs.values(), self._check_on_startup(), self._check_on_install() ) return dialog, needs_gui - + def promt_install(self, dialog: MainDialog): """Promts the install dialog and ask the user what to install""" if dialog.exec_(): @@ -196,7 +196,7 @@ def promt_install(self, dialog: MainDialog): if reqs_to_install: log(f"Will install selected dependencies : {reqs_to_install}") self.pip_install_reqs(reqs_to_install) - + def save_settings(self, dialog): """Stores the settings values""" sys.path_importer_cache.clear() diff --git a/tests/test_finding_req.py b/tests/test_finding_req.py index 08c148a..6a9c41d 100644 --- a/tests/test_finding_req.py +++ b/tests/test_finding_req.py @@ -7,36 +7,40 @@ from a00_qpip.plugin import Plugin + class initializationCompleted: def connect(self): pass + def popWidget(): return True + THIS_DIR = os.path.dirname(__file__) + @pytest.fixture() def plugin(qgis_iface): qgis_iface.initializationCompleted = initializationCompleted qgis_iface.messageBar().popWidget = popWidget - plugin = Plugin(qgis_iface, '.') + plugin = Plugin(qgis_iface, ".") yield plugin def test_plugin_a(plugin: Plugin): - plugin_a = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_a') + plugin_a = os.path.join(THIS_DIR, "..", "test_plugins", "plugin_a") dialog, needs_gui = plugin.check_deps([plugin_a]) libs = dialog.reqs_to_install assert len(libs) == 2 - assert libs[0] == 'cowsay==4.0' + assert libs[0] == "cowsay==4.0" assert needs_gui def test_plugin_b(plugin: Plugin): - plugin_b = os.path.join(THIS_DIR, '..', 'test_plugins', 'plugin_b') + plugin_b = os.path.join(THIS_DIR, "..", "test_plugins", "plugin_b") dialog, needs_gui = plugin.check_deps([plugin_b]) libs = dialog.reqs_to_install assert len(libs) == 2 - assert libs[0] == 'cowsay==5.0' + assert libs[0] == "cowsay==5.0" assert needs_gui From 88bdc0604ab0d605910b297ed1e60517338c476c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20H=C3=B6rteborn?= Date: Wed, 21 Aug 2024 18:14:46 +0200 Subject: [PATCH 18/18] minor typing issues --- .github/workflows/test_plugin.yml | 2 +- a00_qpip/plugin.py | 1 - tests/test_finding_req.py | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/test_plugin.yml b/.github/workflows/test_plugin.yml index 64ffb52..03b0d77 100644 --- a/.github/workflows/test_plugin.yml +++ b/.github/workflows/test_plugin.yml @@ -7,7 +7,7 @@ on: push: pull_request: branches: - - 'main' + - 'main' permissions: contents: read diff --git a/a00_qpip/plugin.py b/a00_qpip/plugin.py index 0859e60..837c66c 100644 --- a/a00_qpip/plugin.py +++ b/a00_qpip/plugin.py @@ -2,7 +2,6 @@ import platform import subprocess import sys -from typing import List from collections import defaultdict, namedtuple from importlib import metadata diff --git a/tests/test_finding_req.py b/tests/test_finding_req.py index 6a9c41d..8642511 100644 --- a/tests/test_finding_req.py +++ b/tests/test_finding_req.py @@ -1,9 +1,6 @@ import os import pytest -from pytest_qgis import qgis_iface - -from PyQt5.QtCore import QSettings, QDate from a00_qpip.plugin import Plugin