Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python utilities: avoid UseExceptions() related deprecation warning when launched from launcher shell scripts #10039

Merged
merged 11 commits into from
May 28, 2024

Conversation

rouault
Copy link
Member

@rouault rouault commented May 27, 2024

Fixes #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.

…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.
@dbaston
Copy link
Member

dbaston commented May 27, 2024

Would it make sense for exceptions to be set via a context manager opened in each script's top-level function, e.g. gdal2xyz.gdal2xyz or gdalcalc.Calc ? That would make sure that exceptions are enabled however the utility is invoked and prevent side effects if for example, Calc is invoked from a script/test suite that is not using exceptions.

@rouault
Copy link
Member Author

rouault commented May 27, 2024

Would it make sense for exceptions to be set via a context manager opened in each script's top-level function, e.g. gdal2xyz.gdal2xyz or gdalcalc.Calc ?

done

)


def _Calc(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll attempt a decorator to avoid the need to duplicate all of these arguments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rouault rouault merged commit 9796216 into OSGeo:master May 28, 2024
35 checks passed
@rouault
Copy link
Member Author

rouault commented May 28, 2024

The backport to release/3.9 failed:

The process '/usr/bin/git' failed with exit code 128
stderr
error: commit 0187ae9dbeab5b0ffa69089434dd652302e17fc8 is a merge but no -m option was given.
fatal: cherry-pick failed

stdout
Auto-merging swig/python/gdal-utils/osgeo_utils/gdal_retile.py
[backport-10039-to-release/3.9 5ad2fbc8dc] Python utilities: avoid UseExceptions() related deprecation warning when launched from launcher shell scripts
 Author: Even Rouault <even.rouault@spatialys.com>
 Date: Mon May 27 20:00:55 2024 +0200
 36 files changed, 50 insertions(+), 59 deletions(-)
[backport-10039-to-release/3.9 09b375bd83] Python bindings: do not emit warnings about not having used [Dont]UseExceptions() if run under gdal.ExceptionMgr()
 Author: Even Rouault <even.rouault@spatialys.com>
 Date: Mon May 27 21:17:13 2024 +0200
 1 file changed, 1 insertion(+), 1 deletion(-)
Auto-merging autotest/gcore/basic_test.py
[backport-10039-to-release/3.9 490146e5db] Python bindings: avoid gdal.ExceptionMgr() to re-throw a GDAL exception already caught under it
 Author: Even Rouault <even.rouault@spatialys.com>
 Date: Mon May 27 21:53:10 2024 +0200
 2 files changed, 10 insertions(+), 1 deletion(-)
Auto-merging autotest/gcore/basic_test.py
[backport-10039-to-release/3.9 159590f8c6] Python bindings: avoid exception emitted and caught under gdal.ExceptionMgr() to cause later issues
 Author: Even Rouault <even.rouault@spatialys.com>
 Date: Mon May 27 22:22:09 2024 +0200
 2 files changed, 10 insertions(+), 3 deletions(-)
[backport-10039-to-release/3.9 1077e05e0d] gdaltest.run_py_script(): add a return_stderr: bool argument
 Author: Even Rouault <even.rouault@spatialys.com>
 Date: Mon May 27 22:25:09 2024 +0200
 1 file changed, 19 insertions(+), 6 deletions(-)
Auto-merging swig/python/gdal-utils/osgeo_utils/gdal_retile.py
[backport-10039-to-release/3.9 185b1b19b6] Python scripts: use local exception manager, instead of global UseExceptions()
 Author: Even Rouault <even.rouault@spatialys.com>
 Date: Mon May 27 23:01:46 2024 +0200
 18 files changed, 317 insertions(+), 82 deletions(-)
Auto-merging autotest/pyscripts/test_gdal_calc.py
Auto-merging autotest/pyscripts/test_gdal_edit.py
Auto-merging autotest/pyscripts/test_gdal_fillnodata.py
Auto-merging autotest/pyscripts/test_gdal_pansharpen.py
Auto-merging autotest/pyscripts/test_gdal_polygonize.py
Auto-merging autotest/pyscripts/test_gdal_proximity.py
Auto-merging autotest/pyscripts/test_gdal_sieve.py
Auto-merging autotest/pyscripts/test_ogrmerge.py
[backport-10039-to-release/3.9 42a0122db1] autotest/pyscripts: check that python scripts don't emit the FutureWarning about UseExceptions()
 Author: Even Rouault <even.rouault@spatialys.com>
 Date: Mon May 27 23:02:23 2024 +0200
 17 files changed, 64 insertions(+), 21 deletions(-)
[backport-10039-to-release/3.9 8ca99f5d70] test_gdal2xyz.py: skip on sanitize CI
 Author: Even Rouault <even.rouault@spatialys.com>
 Date: Mon May 27 23:03:20 2024 +0200
 1 file changed, 4 insertions(+)
Auto-merging swig/python/gdal-utils/osgeo_utils/gdal_retile.py
[backport-10039-to-release/3.9 5be220c1bb] Python scripts: Use decorator to enable exceptions
 Author: Daniel Baston <dbaston@gmail.com>
 Date: Tue May 28 08:48:17 2024 -0400
 18 files changed, 67 insertions(+), 272 deletions(-)

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-release/3.9 release/3.9
# Navigate to the new working tree
cd .worktrees/backport-release/3.9
# Create a new branch
git switch --create backport-10039-to-release/3.9
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick 0de28a155595961eea4e01d19fb55c75a7798f19,e36b6ac1f725554305dbf18edeafd1c984406c61,fcd8a3001ff43af82cfa91cc23446ed67c278983,c435c2180c06bddbdc4cb45b73a671ffa2e93f82,1aa4f0c1ee7244de66b94382bf266d4545631ea2,f079410180ab3d71b443d0040cdee8f386113e08,9bdb59888f0ab5ad5a6eccf754d0855a275cfcd0,39d5a57183fa13d306769a21e710c48fd13893bd,de9fd3194645fb751b191cab18476e9c7bc1cd5a,0187ae9dbeab5b0ffa69089434dd652302e17fc8,c263611070050c1ca06565399cdd670192fb899c
# Push it to GitHub
git push --set-upstream origin backport-10039-to-release/3.9
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-release/3.9

Then, create a pull request where the base branch is release/3.9 and the compare/head branch is backport-10039-to-release/3.9.

@rouault
Copy link
Member Author

rouault commented May 28, 2024

manual backport in #10044

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Neither gdal.UseExceptions() nor gdal.DontUseExceptions()...
2 participants