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 <[email protected]> : 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
_______________________________________________ gdal-dev mailing list [email protected] https://lists.osgeo.org/mailman/listinfo/gdal-dev
