[Qgis-developer] (First?) API break

Anne Ghisla a.ghisla at gmail.com
Sun Dec 11 12:12:08 EST 2011


On Sun, 11 Dec 2011 15:26:55 +0100
Andreas Neumann <a.neumann at carto.net> wrote:

> in javascript there is try and catch for such problems. Ore one could
> test if an object/method/property is present. There are a lot of
> browser differencies - so in a web environment it is quite normal to
> test for capabilities.
> 
> How can one check if an object/method is present in Python?

Hello Andreas, all,

the check can be done during import:

"""
try:
    from qgis.core import newFunctionName as function
except:
    from qgis.core import oldFunctionName as function
"""

so that you can use "function" anywhere in the code without further
checks.
To keep the import code short, only the previous version of the API is
tested. If a plugin developer wants to extend support to even older
versions, I would recommend to create a separate "LTS" version.
What do you think?

Anne
-- 
http://gis.cri.fmach.it/ghisla/

> 
> Andreas
> 
> On 12/11/2011 02:10 PM, Paolo Cavallini wrote:
> > Il 11/12/2011 10:57, Ziegler Stefan ha scritto:
> >> Hi
> >>
> >> What is the best practice to deal with such API breaks (regarding
> >> python plugins)? 
> > 
> > Can we have a conditional fix (if api_version=2.0)? This way we
> > should not maintain two copies of the same plugins, much better if
> > someone works with qgis stable but also tests master.
> > All the best.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/qgis-developer/attachments/20111211/6e3b9207/signature.bin


More information about the Qgis-developer mailing list