From a9d9dc48965b6715d5650f6c1de851a8d64b2744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sun, 30 Jun 2024 20:44:13 -0400 Subject: [PATCH] style: Fixes sys-exit-alias (PLR1722) (#3951) Using `ruff check --select "PLR1722" --unsafe-fixes --output-format=concise --fix`. --- man/build_keywords.py | 2 +- python/grass/temporal/extract.py | 7 ++++--- python/grass/temporal/mapcalc.py | 5 +++-- raster/r.topidx/arc_to_gridatb.py | 10 +++++----- raster/r.topidx/gridatb_to_arc.py | 8 ++++---- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/man/build_keywords.py b/man/build_keywords.py index 5b2b41359b1..34dcbaa691c 100644 --- a/man/build_keywords.py +++ b/man/build_keywords.py @@ -94,7 +94,7 @@ def get_module_man_html_file_path(module): except: pass if not key: - exit("Empty keyword from file %s line: %s" % (fname, lines[index_keys])) + sys.exit("Empty keyword from file %s line: %s" % (fname, lines[index_keys])) if key not in keywords.keys(): keywords[key] = [] keywords[key].append(fname) diff --git a/python/grass/temporal/extract.py b/python/grass/temporal/extract.py index 3f8c9cb0738..a8fc73a8312 100644 --- a/python/grass/temporal/extract.py +++ b/python/grass/temporal/extract.py @@ -9,6 +9,7 @@ :authors: Soeren Gebbert """ +import sys from .core import ( get_tgis_message_interface, get_current_mapset, @@ -320,7 +321,7 @@ def run_mapcalc2d(expr): "r.mapcalc", expression=expr, overwrite=gscript.overwrite(), quiet=True ) except CalledModuleError: - exit(1) + sys.exit(1) def run_mapcalc3d(expr): @@ -330,7 +331,7 @@ def run_mapcalc3d(expr): "r3.mapcalc", expression=expr, overwrite=gscript.overwrite(), quiet=True ) except CalledModuleError: - exit(1) + sys.exit(1) def run_vector_extraction(input, output, layer, type, where): @@ -347,4 +348,4 @@ def run_vector_extraction(input, output, layer, type, where): quiet=True, ) except CalledModuleError: - exit(1) + sys.exit(1) diff --git a/python/grass/temporal/mapcalc.py b/python/grass/temporal/mapcalc.py index 54edeab885d..ba7520382e9 100644 --- a/python/grass/temporal/mapcalc.py +++ b/python/grass/temporal/mapcalc.py @@ -9,6 +9,7 @@ :authors: Soeren Gebbert """ +import sys import copy from datetime import datetime from multiprocessing import Process @@ -412,7 +413,7 @@ def _run_mapcalc2d(expr): "r.mapcalc", expression=expr, overwrite=gscript.overwrite(), quiet=True ) except CalledModuleError: - exit(1) + sys.exit(1) ############################################################################### @@ -425,7 +426,7 @@ def _run_mapcalc3d(expr): "r3.mapcalc", expression=expr, overwrite=gscript.overwrite(), quiet=True ) except CalledModuleError: - exit(1) + sys.exit(1) ############################################################################### diff --git a/raster/r.topidx/arc_to_gridatb.py b/raster/r.topidx/arc_to_gridatb.py index 28b79a00d2f..17e49365697 100755 --- a/raster/r.topidx/arc_to_gridatb.py +++ b/raster/r.topidx/arc_to_gridatb.py @@ -16,18 +16,18 @@ def match(pattern, string): if len(sys.argv) != 3 or re.match("^-*help", sys.argv[1]): print("Usage: arc.to.gridatb.py arc_file gridatb_file") - exit() + sys.exit() infname = sys.argv[1] outfname = sys.argv[2] if not os.path.isfile(infname): print(f"{infname}: File not found") - exit() + sys.exit() if os.path.isfile(outfname): print(f"{outfname}: File already exists") - exit() + sys.exit() inf = open(infname) @@ -54,14 +54,14 @@ def match(pattern, string): else: print(f"{infname}: Invalid input file format") inf.close() - exit() + sys.exit() if head == 0x3F: break if head != 0x3F: print(f"{infname}: Invalid input file format") inf.close() - exit() + sys.exit() outf = open(outfname, "w") outf.write( diff --git a/raster/r.topidx/gridatb_to_arc.py b/raster/r.topidx/gridatb_to_arc.py index 3f2e30c8b4c..41111f3d6ba 100755 --- a/raster/r.topidx/gridatb_to_arc.py +++ b/raster/r.topidx/gridatb_to_arc.py @@ -10,7 +10,7 @@ or re.match("^-*help", sys.argv[1]) ): print("Usage: gridatb.to.arc.py gridatb_file arc_file [xllcorner yllcorner]") - exit() + sys.exit() xllcorner = 0 yllcorner = 0 @@ -23,11 +23,11 @@ if not os.path.isfile(infname): print(f"{infname}: File not found") - exit() + sys.exit() if os.path.isfile(outfname): print(f"{outfname}: File already exists") - exit() + sys.exit() inf = open(infname) @@ -37,7 +37,7 @@ if not m: print(f"{infname}: Invalid input file format") inf.close() - exit() + sys.exit() ncols = m.group(1) nrows = m.group(2)