From fe5d5e284bad81bac5407b316ddacc34938a3827 Mon Sep 17 00:00:00 2001
From: Wouter Deconinck <wdconinc@gmail.com>
Date: Mon, 26 Jun 2023 15:37:30 -0500
Subject: [PATCH] feat: subprocess.run should check return code or check=True

---
 benchmarks/ecal/run_emcal_benchmarks.py                | 8 ++++----
 benchmarks/imaging_shower_ML/deprecated/sim_rec_tag.py | 6 +++---
 benchmarks/imaging_shower_ML/run_benchmark.py          | 6 +++---
 benchmarks/tracking/run_tracking_benchmarks.py         | 8 ++++----
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/benchmarks/ecal/run_emcal_benchmarks.py b/benchmarks/ecal/run_emcal_benchmarks.py
index b0c27a4f..5b0ae3e9 100755
--- a/benchmarks/ecal/run_emcal_benchmarks.py
+++ b/benchmarks/ecal/run_emcal_benchmarks.py
@@ -77,7 +77,7 @@ if 'sim' in procs:
             '--angmin', '{}'.format(args.amin), '--angmax', '{}'.format(args.amax),
             '--pmin', '{}'.format(args.pmin), '--pmax', '{}'.format(args.pmax),
             '--particles', args.particles]
-    subprocess.run(gen_cmd)
+    subprocess.run(gen_cmd, check=True)
     # simulation
     sim_cmd = ['ddsim',
             '--part.minimalKineticEnergy', '1*TeV',
@@ -94,7 +94,7 @@ if 'sim' in procs:
     if return_code is not None and return_code < 0:
         print("ERROR running simulation!")
         exit(1)
-    subprocess.run(['rootls', '-t', sim_file])
+    subprocess.run(['rootls', '-t', sim_file], check=True)
 
 
 if 'rec' in procs:
@@ -110,7 +110,7 @@ if 'rec' in procs:
         if return_code is not None and return_code < 0:
             print('ERROR running juggler ({})!'.format(opt))
             exit(1)
-    process = subprocess.run(['rootls', '-t', rec_file])
+    process = subprocess.run(['rootls', '-t', rec_file], check=True)
 
 
 if 'ana' in procs:
@@ -127,7 +127,7 @@ if 'ana' in procs:
 
 # upload generated data files if it was small enough (< 10 Mb)
 for upload in [rec_file]:
-    process = subprocess.run(['stat', '--format=%s', upload], stdout=subprocess.PIPE)
+    process = subprocess.run(['stat', '--format=%s', upload], check=True, stdout=subprocess.PIPE)
     size = int(process.stdout)/1024./1024.
     if size > args.uploadSizeLimit:
         print('Skip uploading file \"{}\" because its size ({:.2f} Mb) > {:.2f} Mb'\
diff --git a/benchmarks/imaging_shower_ML/deprecated/sim_rec_tag.py b/benchmarks/imaging_shower_ML/deprecated/sim_rec_tag.py
index 80234793..436fa582 100755
--- a/benchmarks/imaging_shower_ML/deprecated/sim_rec_tag.py
+++ b/benchmarks/imaging_shower_ML/deprecated/sim_rec_tag.py
@@ -50,7 +50,7 @@ if 'sim' in procs:
             '--angmin', '85', '--angmax', '95',
             '--pmin', '{}'.format(args.pmin), '--pmax', '{}'.format(args.pmax),
             '--particles', args.particles]
-    subprocess.run(gen_cmd)
+    subprocess.run(gen_cmd, check=True)
     # simulation
     sim_cmd = ['ddsim',
             '--part.minimalKineticEnergy', '1*TeV',
@@ -69,7 +69,7 @@ if 'sim' in procs:
     if return_code is not None and return_code < 0:
         print("ERROR running simulation!")
         exit(return_code)
-    subprocess.run(['rootls', '-t', sim_file])
+    subprocess.run(['rootls', '-t', sim_file], check=True)
 
 
 if 'rec' in procs:
@@ -93,7 +93,7 @@ if 'rec' in procs:
     if return_code is not None and return_code < 0:
         print("ERROR running juggler (reconstruction)!")
         exit(return_code)
-    process = subprocess.run(['rootls', '-t', rec_file])
+    process = subprocess.run(['rootls', '-t', rec_file], check=True)
 
 
 if 'tag' in procs:
diff --git a/benchmarks/imaging_shower_ML/run_benchmark.py b/benchmarks/imaging_shower_ML/run_benchmark.py
index 0620e040..451a91b2 100755
--- a/benchmarks/imaging_shower_ML/run_benchmark.py
+++ b/benchmarks/imaging_shower_ML/run_benchmark.py
@@ -61,7 +61,7 @@ def gen_sim_rec(**kwargs):
         '--particles {particles}',
         ]
     gen_cmd = ' '.join(gen_cmd).format(**kwargs).split(' ')
-    subprocess.run(gen_cmd)
+    subprocess.run(gen_cmd, check=True)
 
     # simulation
     sim_cmd = [
@@ -81,7 +81,7 @@ def gen_sim_rec(**kwargs):
     if return_code is not None and return_code < 0:
         print("ERROR running simulation!")
         exit(return_code)
-    subprocess.run(['rootls', '-t', kwargs['sim_file']])
+    subprocess.run(['rootls', '-t', kwargs['sim_file']], check=True)
 
     # reconstruction with juggler
     # export to environment variables (used to pass arguments to the option file)
@@ -102,7 +102,7 @@ def gen_sim_rec(**kwargs):
     if return_code is not None and return_code < 0:
         print("ERROR running juggler (reconstruction)!")
         exit(return_code)
-    process = subprocess.run(['rootls', '-t', kwargs['rec_file']])
+    process = subprocess.run(['rootls', '-t', kwargs['rec_file']], check=True)
 
 
 
diff --git a/benchmarks/tracking/run_tracking_benchmarks.py b/benchmarks/tracking/run_tracking_benchmarks.py
index 754338bb..0cb70daa 100755
--- a/benchmarks/tracking/run_tracking_benchmarks.py
+++ b/benchmarks/tracking/run_tracking_benchmarks.py
@@ -54,7 +54,7 @@ if 'sim' in procs:
             '--etamin', '{}'.format(args.etamin), '--etamax', '{}'.format(args.etamax),
             '--pmin', '{}'.format(args.pmin), '--pmax', '{}'.format(args.pmax),
             '--particles', args.particles]
-    subprocess.run(gen_cmd)
+    subprocess.run(gen_cmd, check=True)
     # simulation
     sim_cmd = ['ddsim',
             '--part.minimalKineticEnergy', '1*TeV',
@@ -71,7 +71,7 @@ if 'sim' in procs:
     if return_code is not None and return_code != 0:
         print("ERROR running simulation!")
         exit(1)
-    subprocess.run(['rootls', '-t', sim_file])
+    subprocess.run(['rootls', '-t', sim_file], check=True)
 
 
 if 'rec' in procs:
@@ -86,7 +86,7 @@ if 'rec' in procs:
     if return_code is not None and return_code != 0:
         print('ERROR running juggler ({})!'.format(rec_cmd))
         exit(1)
-    process = subprocess.run(['rootls', '-t', rec_file])
+    process = subprocess.run(['rootls', '-t', rec_file], check=True)
 
 
 if 'ana' in procs:
@@ -103,7 +103,7 @@ if 'ana' in procs:
 
 # upload generated data files if it was small enough (< 10 Mb)
 for upload in [rec_file]:
-    process = subprocess.run(['stat', '--format=%s', upload], stdout=subprocess.PIPE)
+    process = subprocess.run(['stat', '--format=%s', upload], check=True, stdout=subprocess.PIPE)
     size = int(process.stdout)/1024./1024.
     if size > args.uploadSizeLimit:
         print('Skip uploading file \"{}\" because its size ({:.2f} Mb) > {:.2f} Mb'\
-- 
GitLab