diff --git a/extension/ZAZPip_v0.10.2.oxt b/extension/ZAZPip_v0.10.2.oxt index bd1ba7b..2c37398 100644 Binary files a/extension/ZAZPip_v0.10.2.oxt and b/extension/ZAZPip_v0.10.2.oxt differ diff --git a/source/META-INF/manifest.xml b/source/META-INF/manifest.xml index 29ceecf..3fcb2d4 100644 --- a/source/META-INF/manifest.xml +++ b/source/META-INF/manifest.xml @@ -1,6 +1,8 @@ + + diff --git a/source/job.xcu b/source/job.xcu new file mode 100644 index 0000000..7228846 --- /dev/null +++ b/source/job.xcu @@ -0,0 +1,20 @@ + + + + + + + net.elmau.zaz.pip.PipRunner + + + + + + + + + + + \ No newline at end of file diff --git a/source/pip_runner.py b/source/pip_runner.py new file mode 100644 index 0000000..36ee398 --- /dev/null +++ b/source/pip_runner.py @@ -0,0 +1,60 @@ +# region Imports +from __future__ import unicode_literals, annotations +import os +import sys +from typing import TYPE_CHECKING, Tuple +from pathlib import Path +import uno +import unohelper +from com.sun.star.task import XJob + +if TYPE_CHECKING: + # just for design time + from com.sun.star.beans import NamedValue + +# endregion Imports + +# region Constants + +implementation_name = "net.elmau.zaz.pip.PipRunner" +implementation_services = ("com.sun.star.task.Job",) + +# endregion Constants + + + +# region XJob +class PipRunner(unohelper.Base, XJob): + def __init__(self, ctx): + self._is_flatpak = bool(os.getenv("FLATPAK_ID", "")) + if self._is_flatpak: + site_packages = self.get_flatpak_site_packages_dir() + ss = str(site_packages) + if site_packages.exists and ss not in sys.path: + sys.path.append(ss) + + def execute(self, *args: Tuple[NamedValue, ...]) -> None: + pass + + def get_flatpak_site_packages_dir(self) -> Path: + # should never be all users + sand_box = os.getenv("FLATPAK_SANDBOX_DIR", "") or str( + Path.home() / ".var/app/org.libreoffice.LibreOffice/sandbox" + ) + major_minor = f"{sys.version_info.major}.{sys.version_info.minor}" + site_packages = Path(sand_box) / f"lib/python{major_minor}/site-packages" + site_packages.mkdir(parents=True, exist_ok=True) + return site_packages + +# endregion XJob + +# region Implementation + +g_TypeTable = {} +# python loader looks for a static g_ImplementationHelper variable +g_ImplementationHelper = unohelper.ImplementationHelper() + +# add the FormatFactory class to the implementation container, +# which the loader uses to register/instantiate the component. +g_ImplementationHelper.addImplementation(PipRunner, implementation_name, implementation_services) +# endregion Implementation \ No newline at end of file