Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h3 depencency guard #1

Open
maphew opened this issue Apr 28, 2022 · 4 comments
Open

h3 depencency guard #1

maphew opened this issue Apr 28, 2022 · 4 comments

Comments

@maphew
Copy link
Contributor

maphew commented Apr 28, 2022

# not best practice. TODO: check with pkg_resources module instead and install via
# pip + subprocess + sys.executable?
# import pkg_resources

The place were the blessed route to a solution will be, if it can be found, is PIP dependencies for Python plugins QGIS enhancement proposal. It's a hard problem to solve. That thread contains exploration of what doesn't work well enough and some interim approaches.

The cleanest to my eye is qgis/QGIS-Enhancement-Proposals#202 (comment), an eye that has read throught things but not tried to implement anything! So do read and think through the rest.

...we solved the problem of conflicting versions of libraries with
our plugins when I was working for Boundles was to alter the path
through sites and ship all the dependencies within the plugin itself.

I can't remember the details @volaya knows probably more. Here is an
example of a plugin that was doing that:
https://github.com/planetfederal/qgis-geoserver-plugin/blob/master/geoserverexplorer/extlibs/site.py

So, each plugin imported its dependencies from a module
plugin_namespace.extlibs actually insulating them from other plugins.
IIRC it was working well but I can't remember if it led to issues with
binaries.

Above is my contribution to https://gis.stackexchange.com/questions/311726/adding-missing-python-packages-to-qgis-plugin/

@arongergely
Copy link
Owner

Thanks for the insight @maphew.

I have seen that QEP since.
Initially tried to handle the missing dependency and realized it's a hard thing.
Hence falling back to just explanation (via QMessageBox) of the problem if said dependency is missing

@maphew
Copy link
Contributor Author

maphew commented Feb 4, 2025

I think but haven't learned enough yet to verify that using uv run from Astral might be a solution: inline script dependencies, a feature described in PEP 723 and implemented by uv run. Running the script causes uv to create a temporary virtual environment with those dependencies installed, a process that takes just a few milliseconds once the uv cache has been populated.

@arongergely
Copy link
Owner

You mean as a solution to install the plugin's dependencies automatically?

I also looked at uv briefly. But I don't know if its behavior is consistent across OS platforms.
Also, it doesn't (and will not) have a python API: astral-sh/uv#7345

So one would need to call uv from CLI or via python's subprocess. The latter is shaky because it does not behave consistently across platforms.

@maphew
Copy link
Contributor Author

maphew commented Feb 5, 2025

Ah, that does put a damper on the idea. Thanks for the info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants