Skip to content

Commit

Permalink
Python utilities: avoid UseExceptions() related deprecation warning w…
Browse files Browse the repository at this point in the history
…hen launched from launcher shell scripts

Fixes OSGeo#10010

The launcher shell scripts generated by setuptools don't use our
gdal-utils/scripts/{script_name}.py scripts, but directly the gdal-utils/osgeo_utils/{script_name}.py one.
Hence let's move the call to UseExceptions() from the former to the
later.
  • Loading branch information
rouault committed May 27, 2024
1 parent be42556 commit 0de28a1
Show file tree
Hide file tree
Showing 36 changed files with 50 additions and 59 deletions.
2 changes: 2 additions & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

Options = Any

gdal.UseExceptions()

try:
import numpy
from PIL import Image
Expand Down
1 change: 1 addition & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal2xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def doit(self, **kwargs):


def main(argv=sys.argv):
gdal.UseExceptions()
return GDAL2XYZ().main(argv)


Expand Down
1 change: 1 addition & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ def augment_kwargs(self, kwargs) -> dict:


def main(argv=sys.argv):
gdal.UseExceptions()
return GDALCalc().main(argv)


Expand Down
1 change: 1 addition & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ def gdal_edit(argv):


def main(argv=sys.argv):
gdal.UseExceptions()
return gdal_edit(argv)


Expand Down
1 change: 1 addition & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal_fillnodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def doit(self, **kwargs):


def main(argv=sys.argv):
gdal.UseExceptions()
return GDALFillNoData().main(argv)


Expand Down
1 change: 1 addition & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ def gdal_merge(argv=None):


def main(argv=sys.argv):
gdal.UseExceptions()
return gdal_merge(argv)


Expand Down
3 changes: 3 additions & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal_pansharpen.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def Usage(isError):


def main(argv=sys.argv):

gdal.UseExceptions()

argv = gdal.GeneralCmdLineProcessor(argv)
if argv is None:
return 0
Expand Down
1 change: 1 addition & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal_polygonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ def doit(self, **kwargs):


def main(argv=sys.argv):
gdal.UseExceptions()
return GDALPolygonize().main(argv)


Expand Down
2 changes: 2 additions & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal_proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def main(argv=sys.argv):
creation_type = "Float32"
quiet = False

gdal.UseExceptions()

argv = gdal.GeneralCmdLineProcessor(argv)
if argv is None:
return 0
Expand Down
3 changes: 3 additions & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal_retile.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,9 @@ def Usage(isError):


def main(args=None, g=None):

gdal.UseExceptions()

if g is None:
g = RetileGlobals()

Expand Down
2 changes: 2 additions & 0 deletions swig/python/gdal-utils/osgeo_utils/gdal_sieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def main(argv=sys.argv):

mask = "default"

gdal.UseExceptions()

argv = gdal.GeneralCmdLineProcessor(argv)
if argv is None:
return 0
Expand Down
3 changes: 3 additions & 0 deletions swig/python/gdal-utils/osgeo_utils/gdalattachpct.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def Usage(isError=True):


def main(argv=sys.argv):

gdal.UseExceptions()

pct_filename = None
src_filename = None
dst_filename = None
Expand Down
3 changes: 3 additions & 0 deletions swig/python/gdal-utils/osgeo_utils/gdalcompare.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ def Usage(isError=True):


def main(argv=sys.argv):

gdal.UseExceptions()

# Default GDAL argument parsing.
argv = gdal.GeneralCmdLineProcessor(argv)
if argv is None:
Expand Down
4 changes: 3 additions & 1 deletion swig/python/gdal-utils/osgeo_utils/gdalmove.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ def Usage(isError=True):


def main(argv=sys.argv):
# Default GDAL argument parsing.

gdal.UseExceptions()

# Default GDAL argument parsing.
argv = gdal.GeneralCmdLineProcessor(argv)
if argv is None:
return 0
Expand Down
2 changes: 2 additions & 0 deletions swig/python/gdal-utils/osgeo_utils/ogr_layer_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def main(argv=sys.argv):
srs_name = None
srs = None

gdal.UseExceptions()

argv = ogr.GeneralCmdLineProcessor(argv)
if argv is None:
return 0
Expand Down
5 changes: 1 addition & 4 deletions swig/python/gdal-utils/osgeo_utils/ogrmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,6 @@ def _gpkg_ogrmerge(
if dst_ds is None:
return 1

ogr.UseExceptions()
gdal.UseExceptions()
osr.UseExceptions()

class ThreadedProgress:
def __init__(self, dst_filename, estimated_final_size):
self.stop_thread = False
Expand Down Expand Up @@ -1207,6 +1203,7 @@ def are_sources_gpkg():


def main(argv=sys.argv):
gdal.UseExceptions()
argv = ogr.GeneralCmdLineProcessor(argv)
if argv is None:
return 0
Expand Down
1 change: 1 addition & 0 deletions swig/python/gdal-utils/osgeo_utils/pct2rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def doit(self, **kwargs):


def main(argv=sys.argv):
gdal.UseExceptions()
return PCT2RGB().main(argv)


Expand Down
1 change: 1 addition & 0 deletions swig/python/gdal-utils/osgeo_utils/rgb2pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def doit(self, **kwargs):


def main(argv=sys.argv):
gdal.UseExceptions()
return RGB2PCT().main(argv)


Expand Down
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
# Running main() must be protected that way due to use of multiprocessing on Windows:
# https://docs.python.org/3/library/multiprocessing.html#the-spawn-and-forkserver-start-methods
if __name__ == "__main__":
from osgeo.gdal import UseExceptions, deprecation_warn

UseExceptions()
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal2tiles as a convenience to use as a script
from osgeo_utils.gdal2tiles import * # noqa
Expand Down
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal2xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal2xyz as a convenience to use as a script
from osgeo_utils.gdal2xyz import * # noqa
from osgeo_utils.gdal2xyz import main

UseExceptions()

deprecation_warn("gdal2xyz")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal_calc as a convenience to use as a script
from osgeo_utils.gdal_calc import * # noqa
from osgeo_utils.gdal_calc import main

UseExceptions()

deprecation_warn("gdal_calc")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal_edit as a convenience to use as a script
from osgeo_utils.gdal_edit import * # noqa
from osgeo_utils.gdal_edit import main

UseExceptions()

deprecation_warn("gdal_edit")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal_fillnodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal_fillnodata as a convenience to use as a script
from osgeo_utils.gdal_fillnodata import * # noqa
from osgeo_utils.gdal_fillnodata import main

UseExceptions()

deprecation_warn("gdal_fillnodata")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal_merge as a convenience to use as a script
from osgeo_utils.gdal_merge import * # noqa
from osgeo_utils.gdal_merge import main

UseExceptions()

deprecation_warn("gdal_merge")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal_pansharpen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal_pansharpen as a convenience to use as a script
from osgeo_utils.gdal_pansharpen import * # noqa
from osgeo_utils.gdal_pansharpen import main

UseExceptions()

deprecation_warn("gdal_pansharpen")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal_polygonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal_polygonize as a convenience to use as a script
from osgeo_utils.gdal_polygonize import * # noqa
from osgeo_utils.gdal_polygonize import main

UseExceptions()

deprecation_warn("gdal_polygonize")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal_proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal_proximity as a convenience to use as a script
from osgeo_utils.gdal_proximity import * # noqa
from osgeo_utils.gdal_proximity import main

UseExceptions()

deprecation_warn("gdal_proximity")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal_retile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal_retile as a convenience to use as a script
from osgeo_utils.gdal_retile import * # noqa
from osgeo_utils.gdal_retile import main

UseExceptions()

deprecation_warn("gdal_retile")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdal_sieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdal_sieve as a convenience to use as a script
from osgeo_utils.gdal_sieve import * # noqa
from osgeo_utils.gdal_sieve import main

UseExceptions()

deprecation_warn("gdal_sieve")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdalattachpct.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdalattachpct as a convenience to use as a script
from osgeo_utils.gdalattachpct import * # noqa
from osgeo_utils.gdalattachpct import main

UseExceptions()

deprecation_warn("gdalattachpct")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdalcompare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdalcompare as a convenience to use as a script
from osgeo_utils.gdalcompare import * # noqa
from osgeo_utils.gdalcompare import main

UseExceptions()

deprecation_warn("gdalcompare")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/gdalmove.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.gdalmove as a convenience to use as a script
from osgeo_utils.gdalmove import * # noqa
from osgeo_utils.gdalmove import main

UseExceptions()

deprecation_warn("gdalmove")
sys.exit(main(sys.argv))
4 changes: 1 addition & 3 deletions swig/python/gdal-utils/scripts/ogr_layer_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import sys

from osgeo.gdal import UseExceptions, deprecation_warn
from osgeo.gdal import deprecation_warn

# import osgeo_utils.ogr_layer_algebra as a convenience to use as a script
from osgeo_utils.ogr_layer_algebra import * # noqa
from osgeo_utils.ogr_layer_algebra import main

UseExceptions()

deprecation_warn("ogr_layer_algebra")
sys.exit(main(sys.argv))
Loading

0 comments on commit 0de28a1

Please sign in to comment.