[gdal-dev] moving swig\python\scripts\* into the osgeo package

Idan Miara idan at miara.com
Wed Oct 7 05:33:05 PDT 2020


Hi all,

I would like to get your opinion about making the code in the python
scripts more reusable so they can be imported as modules.

I'm working on improving gdal_calc.py:
https://github.com/OSGeo/gdal/pull/3016
Eventually I would need to import it as a module, since it's not in a
package it's not possible without copying it into a package.

>From a recent discussion with @Even Rouault <even.rouault at spatialys.com> :
https://github.com/OSGeo/gdal/pull/3016#issuecomment-704563723
The thing is that the scripts in swig/python/scripts are typically
installed in /usr/bin so they must be standalone, or use the content of the
"osgeo" module where the bindings are installed. If you wanted to use
helper methods/scripts, I guess they should go in the "osgeo" module as
well.

We might still need tiny wrapper scripts in swig/python/scripts for
maintaining backwards compatibility.

So I thought a good approach would be making a main function for each
script (as many already do have), For most scripts that was
fairly straightforward*:
https://github.com/OSGeo/gdal/compare/master...talos-gis:python_scripts_organize

* for gdal_retile.py, gdal_merge.py I needed also to replace all the global
variables with local variables so it would be easier to reuse these
functions (apparently I broke some things in  gdal_retile but I'll fix
that).

Then I made the tiny wrappers automatically using an auxiliary script.
https://github.com/OSGeo/gdal/compare/master...talos-gis:python_scripts
So essentially, each wrapper would be like:

from osgeo.gdal import deprecation_warn
deprecation_warn('gdal_calc')
from osgeo.gdal_calc import *
if __name__ == '__main__':
    sys.exit(main(sys.argv))

What do you think?

Idan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20201007/f69f6025/attachment.html>


More information about the gdal-dev mailing list