Thank you, I checked out your plugin - yes that seems also a good way.
I already had the logic to detect, throw message, guide to dialog, etc... implemented similar to yours.

But I wanted to let pip manage the actual package, so I went with the subprocess+pip route. Here is a minimum working example:

import subprocess
import sys


try:
    subprocess.check_call((sys.executable, '-m', 'pip', 'install', 'h3<=3.99'))
except subprocess.CalledProcessErroras e:
    raise e# handle any errors here instead

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.

Have not yet tried on other platforms than Linux. But sys.executable is there to solve the ambiguity of python executable path.


Best regards,
Aron


On 01-04-2022 14:07, Pedro Camargo via QGIS-Developer wrote:
Take a look at how it is done in the AequilibraE plugin.

I basically ship the plugin without the binaries and create a menu item where the user can choose to download the binaries.

Once downloaded, restarting the plugin allows it to identify the binaries and deactivate that menu item.

Cheers,
Pedro

---- On Fri, 01 Apr 2022 05:00:02 +1000 *qgis-developer-requ...@lists.osgeo.org * wrote ----

    Send QGIS-Developer mailing list submissions to
    qgis-developer@lists.osgeo.org

    To subscribe or unsubscribe via the World Wide Web, visit
    https://lists.osgeo.org/mailman/listinfo/qgis-developer
    or, via email, send a message with subject or body 'help' to
    qgis-developer-requ...@lists.osgeo.org

    You can reach the person managing the list at
    qgis-developer-ow...@lists.osgeo.org

    When replying, please edit your Subject line so it is more specific
    than "Re: Contents of QGIS-Developer digest..."


    Today's Topics:

    1. Plugin dependency with binaries: 'best' way to guide user to
    install? (Aron Gergely)
    2. Unexpected results from GPKG table query using executeSql()
    (Raymond Nijssen)
    3. Re: Unexpected results from GPKG table query using
    executeSql() (Alessandro Pasotti)
    4. Re: Unexpected results from GPKG table query using
    executeSql() (Raymond Nijssen)


    ----------------------------------------------------------------------


    Message: 1
    Date: Thu, 31 Mar 2022 14:09:21 +0200
    From: Aron Gergely <aron.gerg...@rasterra.nl>
    To: qgis-dev <qgis-developer@lists.osgeo.org>
    Subject: [QGIS-Developer] Plugin dependency with binaries: 'best' way
        to guide user to install?
    Message-ID: <5e3173ec-7b7e-64da-47d1-79d39edc1...@rasterra.nl>
    Content-Type: text/plain; charset=UTF-8; format=flowed

    Hi All,

    What would be a good practice to handle 3rd party libs which can't be
    shipped together with a plugin?
    I am looking for the most user-friendly way and have an idea.
    But thought I would bounce it off the collective wisdom here and
    see if
    there are other/better ways.

    If we find a 'best' method I could PR an update to the QGIS docs or
    PyQGIS cookbook, etc to preserve that knowledge.

    Bit of context:
    I have a plugin that uses a 3rd party python library which has
    binaries.
    I would like to submit this plugin to the official plugin repository.
    According to https://plugins.qgis.org/publish/ it's not allowed to
    ship
    binaries it with the plugin.
    In such case the above webpage recommends telling the end user to run
    "pip.main(...)" from the python console to install missing libraries.

    I thought that's not user friendly and it's a pip hack (pip.main() is
    meant to be internal).
    Also, I want to handle the missing python module in my plugin
    gracefully: check on plugin load if missing, if so, guide user to
    resolve, preferably without having them write or copy any commands.

    The idea:
    Using python's subprocess module from within the plugin to call
    the pip
    CLI, which would install the package the usual pip way. Here's why:
    - pip project recommends this way as best practice, warns against the
    pip.main()
    - user would not need to write or copy-paste commands
    - could make this user friendly: wire it in the plugin code to a push
    button and build it into a dialog e.g.;? if lib is missing on
    plugin load,
    ? show a QMessageBox and let user open a dialog to resolve. In that
    dialog would be the push button to trigger the pip install via
    subprocess.

    How would this play out multi-platform via subprocess, I have no
    idea of
    yet - thought if the idea survived this thread, I'd go find out ;)

    Do you think this subprocess + pip is a good idea?
    Would it be allowed for plugins in the official repository to
    behave as
    such?
    Anyone has other user-friendly ways of doing this?

    Best regards,
    Aron



    ------------------------------

    Message: 2
    Date: Thu, 31 Mar 2022 18:09:25 +0200
    From: Raymond Nijssen <r.nijs...@terglobo.nl>
    To: qgis-developer <qgis-developer@lists.osgeo.org>
    Subject: [QGIS-Developer] Unexpected results from GPKG table query
        using executeSql()
    Message-ID: <bba11f52-a64a-6502-fbce-dbc986ba9...@terglobo.nl>
    Content-Type: text/plain; charset=UTF-8; format=flowed

    Hi devs,

    I'm working on a plugin that connects to a custom table (without
    geometry) in a GPKG. When I'm sending queries to it, I keep on
    getting
    unexpected results. Somehow the id field is missing, sometimes it
    appears twice (!). And this seems to be different between QGIS
    3.10 and
    3.25. (I think it changed since 3.22).

    Here is a piece of my code:


    fn = '/path/to/test.gpkg'
    md = QgsProviderRegistry.instance().providerMetadata('ogr')
    conn = md.createConnection(fn, {})

    q = 'select * from test_table;'
    qr = conn.executeSql(q)
    print(qr) # No id field in result



    Before diving into the QGIS code I'd like to check if this is the
    way to
    go. Or should i use another way to query that GPKG (SQLite) db?


    Kind regards,
    Raymond


    ------------------------------

    Message: 3
    Date: Thu, 31 Mar 2022 18:15:00 +0200
    From: Alessandro Pasotti <apaso...@gmail.com>
    To: Raymond Nijssen <r.nijs...@terglobo.nl>
    Cc: qgis-developer <qgis-developer@lists.osgeo.org>
    Subject: Re: [QGIS-Developer] Unexpected results from GPKG table
    query
        using executeSql()
    Message-ID:
        <cal5q670rrd--zvevdttcwequ1vzgue7nh+e58mlmdmqnpf9...@mail.gmail.com>

    Content-Type: text/plain; charset="utf-8"

    Hi Raymond,

    your code looks good.

    Can you provide a test file?

    There are some test in core here:
    
https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py



    On Thu, Mar 31, 2022 at 6:09 PM Raymond Nijssen via QGIS-Developer <
    qgis-developer@lists.osgeo.org> wrote:

    > Hi devs,
    >
    > I'm working on a plugin that connects to a custom table (without
    > geometry) in a GPKG. When I'm sending queries to it, I keep on
    getting
    > unexpected results. Somehow the id field is missing, sometimes it
    > appears twice (!). And this seems to be different between QGIS
    3.10 and
    > 3.25. (I think it changed since 3.22).
    >
    > Here is a piece of my code:
    >
    >
    > fn = '/path/to/test.gpkg'
    > md = QgsProviderRegistry.instance().providerMetadata('ogr')
    > conn = md.createConnection(fn, {})
    >
    > q = 'select * from test_table;'
    > qr = conn.executeSql(q)
    > print(qr) # No id field in result
    >
    >
    >
    > Before diving into the QGIS code I'd like to check if this is
    the way to
    > go. Or should i use another way to query that GPKG (SQLite) db?
    >
    >
    > Kind regards,
    > Raymond
    > _______________________________________________
    > QGIS-Developer mailing list
    > QGIS-Developer@lists.osgeo.org
    > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
    > Unsubscribe:
    https://lists.osgeo.org/mailman/listinfo/qgis-developer
    >


-- Alessandro Pasotti
    QCooperative: www.qcooperative.net
    ItOpen: www.itopen.it
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL:
    
<http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220331/ad1ec7b7/attachment-0001.html>


    ------------------------------

    Message: 4
    Date: Thu, 31 Mar 2022 18:52:48 +0200
    From: Raymond Nijssen <r.nijs...@terglobo.nl>
    To: Alessandro Pasotti <apaso...@gmail.com>
    Cc: qgis-developer <qgis-developer@lists.osgeo.org>
    Subject: Re: [QGIS-Developer] Unexpected results from GPKG table
    query
        using executeSql()
    Message-ID: <87330c53-a8a5-6e07-dd6e-006fcdd77...@terglobo.nl>
    Content-Type: text/plain; charset=UTF-8; format=flowed

    Hi Alessandro,

    Thanks for your reply. Will share data and a test script with you
    privately.

    Raymond


    On 31-03-2022 18:15, Alessandro Pasotti wrote:
    > Hi Raymond,
    >
    > your code looks good.
    >
    > Can you provide a test file?
    >
    > There are some test in core here:
    >
    
https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py

    >
    
<https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsproviderconnection_ogr_gpkg.py>

    >
    >
    > On Thu, Mar 31, 2022 at 6:09 PM Raymond Nijssen via QGIS-Developer
    > <qgis-developer@lists.osgeo.org
    <mailto:qgis-developer@lists.osgeo.org>>
    > wrote:
    >
    > Hi devs,
    >
    > I'm working on a plugin that connects to a custom table (without
    > geometry) in a GPKG. When I'm sending queries to it, I keep on
    getting
    > unexpected results. Somehow the id field is missing, sometimes it
    > appears twice (!). And this seems to be different between QGIS
    3.10 and
    > 3.25. (I think it changed since 3.22).
    >
    > Here is a piece of my code:
    >
    >
    > fn = '/path/to/test.gpkg'
    > md = QgsProviderRegistry.instance().providerMetadata('ogr')
    > conn = md.createConnection(fn, {})
    >
    > q = 'select * from test_table;'
    > qr = conn.executeSql(q)
    > print(qr) # No id field in result
    >
    >
    >
    > Before diving into the QGIS code I'd like to check if this is the
    > way to
    > go. Or should i use another way to query that GPKG (SQLite) db?
    >
    >
    > Kind regards,
    > Raymond
    > _______________________________________________
    > QGIS-Developer mailing list
    > QGIS-Developer@lists.osgeo.org
    <mailto:QGIS-Developer@lists.osgeo.org>
    > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
    > <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
    > Unsubscribe:
    https://lists.osgeo.org/mailman/listinfo/qgis-developer
    > <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
    >
    >
    >
    > --
    > Alessandro Pasotti
    > QCooperative: www.qcooperative.net <https://www.qcooperative.net>
    > ItOpen: www.itopen.it <http://www.itopen.it>


    ------------------------------

    Subject: Digest Footer

    _______________________________________________
    QGIS-Developer mailing list
    QGIS-Developer@lists.osgeo.org
    List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
    Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


    ------------------------------

    End of QGIS-Developer Digest, Vol 197, Issue 39
    ***********************************************



_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer
--
Email Signature Kind Regards,

Aron Gergely
+31 (0) 6 38 70 97 66

*Rasterra* | www.rasterra.nl
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to