<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Thank you, I checked out your plugin - yes that seems also a good
way.<br>
I already had the logic to detect, throw message, guide to dialog,
etc... implemented similar to yours.<br>
<br>
But I wanted to let pip manage the actual package, so I went with
the subprocess+pip route. Here is a minimum working example:<br>
</p>
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'JetBrains Mono',monospace;font-size:9.8pt;"><span style="color:#cc7832;">import </span>subprocess
<span style="color:#cc7832;">import </span>sys
<span style="color:#cc7832;">try</span>:
subprocess.check_call((sys.executable<span style="color:#cc7832;">, </span><span style="color:#6a8759;">'-m'</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">'pip'</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">'install'</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">'h3<=3.99'</span>))
<span style="color:#cc7832;">except </span>subprocess.CalledProcessError <span style="color:#cc7832;">as </span>e:
<span style="color:#cc7832;">raise </span>e <span style="color:#808080;"># handle any errors here instead</span>
</pre>
<p>I connected it to a button in a dialog. And catch stdout, stderr
and the exit code of the subprocess so I can show the user what is
happening.<br>
<br>
Have not yet tried on other platforms than Linux. But
sys.executable is there to solve the ambiguity of python
executable path.<br>
<br>
<br>
Best regards,<br>
Aron<br>
<br>
<br>
</p>
<div class="moz-cite-prefix">On 01-04-2022 14:07, Pedro Camargo via
QGIS-Developer wrote:<br>
</div>
<blockquote type="cite"
cite="mid:17fe5059408.23b5bb1f5402.6947602649214067570@margo.co">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<div
style="font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif;">Take
a look at how it is done in the AequilibraE plugin.<br>
<br>
I basically ship the plugin without the binaries and create a
menu item where the user can choose to download the binaries.<br>
<br>
Once downloaded, restarting the plugin allows it to identify the
binaries and deactivate that menu item. <br>
<br>
Cheers,<br>
Pedro <br id="br3">
<div id="content"><br>
---- On Fri, 01 Apr 2022 05:00:02 +1000 <b>
<a class="moz-txt-link-abbreviated" href="mailto:qgis-developer-request@lists.osgeo.org">qgis-developer-request@lists.osgeo.org</a> </b> wrote ----<br>
<br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204);
padding-left: 6px; margin-left: 5px;">
<div>Send QGIS-Developer mailing list submissions to
<br>
<a href="mailto:qgis-developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer@lists.osgeo.org</a>
<br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit
<br>
<a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
<br>
or, via email, send a message with subject or body 'help'
to
<br>
<a
href="mailto:qgis-developer-request@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer-request@lists.osgeo.org</a>
<br>
<br>
You can reach the person managing the list at
<br>
<a href="mailto:qgis-developer-owner@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer-owner@lists.osgeo.org</a>
<br>
<br>
When replying, please edit your Subject line so it is more
specific
<br>
than "Re: Contents of QGIS-Developer digest..."
<br>
<br>
<br>
Today's Topics:
<br>
<br>
1. Plugin dependency with binaries: 'best' way to guide
user to
<br>
install? (Aron Gergely)
<br>
2. Unexpected results from GPKG table query using
executeSql()
<br>
(Raymond Nijssen)
<br>
3. Re: Unexpected results from GPKG table query using
<br>
executeSql() (Alessandro Pasotti)
<br>
4. Re: Unexpected results from GPKG table query using
<br>
executeSql() (Raymond Nijssen)
<br>
<br>
<br>
----------------------------------------------------------------------
<br>
<br>
Message: 1
<br>
Date: Thu, 31 Mar 2022 14:09:21 +0200
<br>
From: Aron Gergely <<a
href="mailto:aron.gergely@rasterra.nl" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">aron.gergely@rasterra.nl</a>>
<br>
To: qgis-dev <<a
href="mailto:qgis-developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer@lists.osgeo.org</a>>
<br>
Subject: [QGIS-Developer] Plugin dependency with binaries:
'best' way
<br>
to guide user to install?
<br>
Message-ID: <5e3173ec<a
href="mailto:-7b7e-64da-47d1-79d39edc1c10@rasterra.nl"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">-7b7e-64da-47d1-79d39edc1c10@rasterra.nl</a>>
<br>
Content-Type: text/plain; charset=UTF-8; format=flowed
<br>
<br>
Hi All,
<br>
<br>
What would be a good practice to handle 3rd party libs
which can't be <br>
shipped together with a plugin?
<br>
I am looking for the most user-friendly way and have an
idea.
<br>
But thought I would bounce it off the collective wisdom
here and see if <br>
there are other/better ways.
<br>
<br>
If we find a 'best' method I could PR an update to the
QGIS docs or <br>
PyQGIS cookbook, etc to preserve that knowledge.
<br>
<br>
Bit of context:
<br>
I have a plugin that uses a 3rd party python library which
has binaries.
<br>
I would like to submit this plugin to the official plugin
repository.
<br>
According to <a href="https://plugins.qgis.org/publish/"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://plugins.qgis.org/publish/</a>
it's not allowed to ship <br>
binaries it with the plugin.
<br>
In such case the above webpage recommends telling the end
user to run <br>
"pip.main(...)" from the python console to install missing
libraries.
<br>
<br>
I thought that's not user friendly and it's a pip hack
(pip.main() is <br>
meant to be internal).
<br>
Also, I want to handle the missing python module in my
plugin <br>
gracefully: check on plugin load if missing, if so, guide
user to <br>
resolve, preferably without having them write or copy any
commands.
<br>
<br>
The idea:
<br>
Using python's subprocess module from within the plugin to
call the pip <br>
CLI, which would install the package the usual pip way.
Here's why:
<br>
- pip project recommends this way as best practice, warns
against the <br>
pip.main()
<br>
- user would not need to write or copy-paste commands
<br>
- could make this user friendly: wire it in the plugin
code to a push <br>
button and build it into a dialog e.g.;? if lib is missing
on plugin load,
<br>
? show a QMessageBox and let user open a dialog to
resolve. In that <br>
dialog would be the push button to trigger the pip install
via subprocess.
<br>
<br>
How would this play out multi-platform via subprocess, I
have no idea of <br>
yet - thought if the idea survived this thread, I'd go
find out ;)
<br>
<br>
Do you think this subprocess + pip is a good idea?
<br>
Would it be allowed for plugins in the official repository
to behave as <br>
such?
<br>
Anyone has other user-friendly ways of doing this?
<br>
<br>
Best regards,
<br>
Aron
<br>
<br>
<br>
<br>
------------------------------
<br>
<br>
Message: 2
<br>
Date: Thu, 31 Mar 2022 18:09:25 +0200
<br>
From: Raymond Nijssen <<a
href="mailto:r.nijssen@terglobo.nl" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">r.nijssen@terglobo.nl</a>>
<br>
To: qgis-developer <<a
href="mailto:qgis-developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer@lists.osgeo.org</a>>
<br>
Subject: [QGIS-Developer] Unexpected results from GPKG
table query
<br>
using executeSql()
<br>
Message-ID: <bba11f52<a
href="mailto:-a64a-6502-fbce-dbc986ba9391@terglobo.nl"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">-a64a-6502-fbce-dbc986ba9391@terglobo.nl</a>>
<br>
Content-Type: text/plain; charset=UTF-8; format=flowed
<br>
<br>
Hi devs,
<br>
<br>
I'm working on a plugin that connects to a custom table
(without <br>
geometry) in a GPKG. When I'm sending queries to it, I
keep on getting <br>
unexpected results. Somehow the id field is missing,
sometimes it <br>
appears twice (!). And this seems to be different between
QGIS 3.10 and <br>
3.25. (I think it changed since 3.22).
<br>
<br>
Here is a piece of my code:
<br>
<br>
<br>
fn = '/path/to/test.gpkg'
<br>
md =
QgsProviderRegistry.instance().providerMetadata('ogr')
<br>
conn = md.createConnection(fn, {})
<br>
<br>
q = 'select * from test_table;'
<br>
qr = conn.executeSql(q)
<br>
print(qr) # No id field in result
<br>
<br>
<br>
<br>
Before diving into the QGIS code I'd like to check if this
is the way to <br>
go. Or should i use another way to query that GPKG
(SQLite) db?
<br>
<br>
<br>
Kind regards,
<br>
Raymond
<br>
<br>
<br>
------------------------------
<br>
<br>
Message: 3
<br>
Date: Thu, 31 Mar 2022 18:15:00 +0200
<br>
From: Alessandro Pasotti <<a
href="mailto:apasotti@gmail.com" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">apasotti@gmail.com</a>>
<br>
To: Raymond Nijssen <<a
href="mailto:r.nijssen@terglobo.nl" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">r.nijssen@terglobo.nl</a>>
<br>
Cc: qgis-developer <<a
href="mailto:qgis-developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer@lists.osgeo.org</a>>
<br>
Subject: Re: [QGIS-Developer] Unexpected results from GPKG
table query
<br>
using executeSql()
<br>
Message-ID:
<br>
<CAL5Q670rrD--ZvEVDTtCWEqU1vZgUe7Nh<a
href="mailto:+e58MLMDMQNPF9h1w@mail.gmail.com"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">+e58MLMDMQNPF9h1w@mail.gmail.com</a>>
<br>
Content-Type: text/plain; charset="utf-8"
<br>
<br>
Hi Raymond,
<br>
<br>
your code looks good.
<br>
<br>
Can you provide a test file?
<br>
<br>
There are some test in core here:
<br>
<a
href="https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py</a>
<br>
<br>
<br>
On Thu, Mar 31, 2022 at 6:09 PM Raymond Nijssen via
QGIS-Developer <
<br>
<a href="mailto:qgis-developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer@lists.osgeo.org</a>>
wrote:
<br>
<br>
> Hi devs,
<br>
>
<br>
> I'm working on a plugin that connects to a custom
table (without
<br>
> geometry) in a GPKG. When I'm sending queries to it,
I keep on getting
<br>
> unexpected results. Somehow the id field is missing,
sometimes it
<br>
> appears twice (!). And this seems to be different
between QGIS 3.10 and
<br>
> 3.25. (I think it changed since 3.22).
<br>
>
<br>
> Here is a piece of my code:
<br>
>
<br>
>
<br>
> fn = '/path/to/test.gpkg'
<br>
> md =
QgsProviderRegistry.instance().providerMetadata('ogr')
<br>
> conn = md.createConnection(fn, {})
<br>
>
<br>
> q = 'select * from test_table;'
<br>
> qr = conn.executeSql(q)
<br>
> print(qr) # No id field in result
<br>
>
<br>
>
<br>
>
<br>
> Before diving into the QGIS code I'd like to check if
this is the way to
<br>
> go. Or should i use another way to query that GPKG
(SQLite) db?
<br>
>
<br>
>
<br>
> Kind regards,
<br>
> Raymond
<br>
> _______________________________________________
<br>
> QGIS-Developer mailing list
<br>
> <a href="mailto:QGIS-Developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">QGIS-Developer@lists.osgeo.org</a>
<br>
> List info: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
<br>
> Unsubscribe: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
<br>
>
<br>
<br>
<br>
-- <br>
Alessandro Pasotti
<br>
QCooperative: <a class="moz-txt-link-abbreviated" href="http://www.qcooperative.net">www.qcooperative.net</a>
<br>
ItOpen: <a class="moz-txt-link-abbreviated" href="http://www.itopen.it">www.itopen.it</a>
<br>
-------------- next part --------------
<br>
An HTML attachment was scrubbed...
<br>
URL: <<a
href="http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220331/ad1ec7b7/attachment-0001.html"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220331/ad1ec7b7/attachment-0001.html</a>>
<br>
<br>
------------------------------
<br>
<br>
Message: 4
<br>
Date: Thu, 31 Mar 2022 18:52:48 +0200
<br>
From: Raymond Nijssen <<a
href="mailto:r.nijssen@terglobo.nl" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">r.nijssen@terglobo.nl</a>>
<br>
To: Alessandro Pasotti <<a
href="mailto:apasotti@gmail.com" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">apasotti@gmail.com</a>>
<br>
Cc: qgis-developer <<a
href="mailto:qgis-developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer@lists.osgeo.org</a>>
<br>
Subject: Re: [QGIS-Developer] Unexpected results from GPKG
table query
<br>
using executeSql()
<br>
Message-ID: <87330c53<a
href="mailto:-a8a5-6e07-dd6e-006fcdd7710f@terglobo.nl"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">-a8a5-6e07-dd6e-006fcdd7710f@terglobo.nl</a>>
<br>
Content-Type: text/plain; charset=UTF-8; format=flowed
<br>
<br>
Hi Alessandro,
<br>
<br>
Thanks for your reply. Will share data and a test script
with you privately.
<br>
<br>
Raymond
<br>
<br>
<br>
On 31-03-2022 18:15, Alessandro Pasotti wrote:
<br>
> Hi Raymond,
<br>
> <br>
> your code looks good.
<br>
> <br>
> Can you provide a test file?
<br>
> <br>
> There are some test in core here: <br>
> <a
href="https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py</a>
<br>
> <<a
href="https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py</a>>
<br>
> <br>
> <br>
> On Thu, Mar 31, 2022 at 6:09 PM Raymond Nijssen via
QGIS-Developer <br>
> <<a href="mailto:qgis-developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer@lists.osgeo.org</a>
<mailto:<a href="mailto:qgis-developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer@lists.osgeo.org</a>>>
<br>
> wrote:
<br>
> <br>
> Hi devs,
<br>
> <br>
> I'm working on a plugin that connects to a custom
table (without
<br>
> geometry) in a GPKG. When I'm sending queries to it,
I keep on getting
<br>
> unexpected results. Somehow the id field is missing,
sometimes it
<br>
> appears twice (!). And this seems to be different
between QGIS 3.10 and
<br>
> 3.25. (I think it changed since 3.22).
<br>
> <br>
> Here is a piece of my code:
<br>
> <br>
> <br>
> fn = '/path/to/test.gpkg'
<br>
> md =
QgsProviderRegistry.instance().providerMetadata('ogr')
<br>
> conn = md.createConnection(fn, {})
<br>
> <br>
> q = 'select * from test_table;'
<br>
> qr = conn.executeSql(q)
<br>
> print(qr) # No id field in result
<br>
> <br>
> <br>
> <br>
> Before diving into the QGIS code I'd like to check if
this is the
<br>
> way to
<br>
> go. Or should i use another way to query that GPKG
(SQLite) db?
<br>
> <br>
> <br>
> Kind regards,
<br>
> Raymond
<br>
> _______________________________________________
<br>
> QGIS-Developer mailing list
<br>
> <a href="mailto:QGIS-Developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">QGIS-Developer@lists.osgeo.org</a>
<mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">QGIS-Developer@lists.osgeo.org</a>>
<br>
> List info: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
<br>
> <<a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>>
<br>
> Unsubscribe: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
<br>
> <<a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>>
<br>
> <br>
> <br>
> <br>
> -- <br>
> Alessandro Pasotti
<br>
> QCooperative: <a class="moz-txt-link-abbreviated" href="http://www.qcooperative.net">www.qcooperative.net</a> <<a
href="https://www.qcooperative.net" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">https://www.qcooperative.net</a>>
<br>
> ItOpen: <a class="moz-txt-link-abbreviated" href="http://www.itopen.it">www.itopen.it</a> <<a
href="http://www.itopen.it" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">http://www.itopen.it</a>>
<br>
<br>
<br>
------------------------------
<br>
<br>
Subject: Digest Footer
<br>
<br>
_______________________________________________
<br>
QGIS-Developer mailing list
<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">QGIS-Developer@lists.osgeo.org</a>
<br>
List info: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
<br>
Unsubscribe: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
<br>
<br>
<br>
------------------------------
<br>
<br>
End of QGIS-Developer Digest, Vol 197, Issue 39
<br>
***********************************************
<br>
</div>
</blockquote>
</div>
</div>
<br>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
</pre>
</blockquote>
<div class="moz-signature">-- <br>
<title>Email Signature</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
Kind Regards,<br>
<br>
Aron Gergely<br>
+31 (0) 6 38 70 97 66<br>
<br>
<b>Rasterra</b> | <ahref="https: www.rasterra.nl"=""><a class="moz-txt-link-abbreviated" href="http://www.rasterra.nl">www.rasterra.nl</a><a><br>
</a></ahref="https:></div>
</body>
</html>