Skip to content

Commit

Permalink
Merge branch 'runr_free'
Browse files Browse the repository at this point in the history
  • Loading branch information
kiloRomeoAlpha committed May 8, 2019
2 parents c069c44 + bded37f commit 2134f69
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .jenkins/conda_venv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:
- cython
- future
- ipython
- sphinx_rtd_theme
- sphinx_rtd_theme
- pip
- pydocstyle
- pytest
Expand Down
57 changes: 19 additions & 38 deletions recipe_system/reduction/coreReduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Reduce {} provides one (1) public method:
import os
import sys
import inspect
import signal
import traceback

from importlib import import_module
Expand Down Expand Up @@ -153,25 +152,21 @@ def runr(self):
Returns
-------
xstat : <int> exit code
<void>
"""
xstat = 0
recipe = None

try:
ffiles = self._check_files(self.files)
except IOError as err:
xstat = signal.SIGIO
log.error(str(err))
return xstat
raise

try:
self.adinputs = self._convert_inputs(ffiles)
except IOError as err:
xstat = signal.SIGIO
log.error(str(err))
return xstat
raise

rm = RecipeMapper(self.adinputs, mode=self.mode, drpkg=self.drpkg,
recipename=self.recipename)
Expand All @@ -191,9 +186,8 @@ def runr(self):
try:
p = pm.get_applicable_primitives()
except PrimitivesNotFound as err:
xstat = signal.SIGIO
log.error(str(err))
return xstat
raise

# If the RecipeMapper was unable to find a specified user recipe,
# it is possible that the recipe passed was a primitive name.
Expand All @@ -202,50 +196,37 @@ def runr(self):
if recipe is None:
try:
primitive_as_recipe = getattr(p, self.recipename)
pname = primitive_as_recipe.__name__
log.stdinfo("Found '{}' as a primitive.".format(pname))
self._logheader(primitive_as_recipe.__name__)
except AttributeError as err:
err = "Recipe {} Not Found".format(self.recipename)
xstat = signal.SIGIO
log.error(str(err))
return xstat
raise

pname = primitive_as_recipe.__name__
log.stdinfo("Found '{}' as a primitive.".format(pname))
self._logheader(pname)
try:
primitive_as_recipe()
except AttributeError as err:
xstat = signal.SIGABRT
except Exception as err:
_log_traceback()
log.error(str(err))
return xstat
raise
else:
self._logheader(recipe)
try:
recipe(p)
except KeyboardInterrupt:
log.error("Caught KeyboardInterrupt (^C) signal")
xstat = signal.SIGINT
except IOError as err:
log.error(str(err))
xstat = signal.SIGABRT
except TypeError as err:
_log_traceback()
log.error(str(err))
xstat = signal.SIGABRT
except Exception as err:
log.error("runr() caught an unhandled exception.")
log.error("Reduce received an unhandled exception. Aborting ...")
_log_traceback()
log.error(str(err))
xstat = signal.SIGABRT
log.stdinfo("Writing final outputs ...")
self._write_final(p.streams['main'])
self.output_filenames = [ad.filename for ad in p.streams['main']]
raise

self._write_final(p.streams['main'])
self._output_filenames = [ad.filename for ad in p.streams['main']]

if xstat != 0:
msg = "reduce instance aborted."
else:
msg = "\nreduce completed successfully."
msg = "\nreduce completed successfully."
log.stdinfo(str(msg))
return xstat
return

# -------------------------------- prive -----------------------------------
def _check_files(self, ffiles):
Expand Down Expand Up @@ -393,7 +374,7 @@ def _write_final(self, outputs):
type: <void>
"""
outstr = "Wrote {} in output directory"
outstr = "\tWrote {} in output directory"
def _sname(name):
head, tail = os.path.splitext(name)
ohead = head.split("_")[0]
Expand Down
15 changes: 12 additions & 3 deletions recipe_system/scripts/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# ---------------------------- Package Import ----------------------------------
import os
import sys
import signal
import traceback

from gempy.utils import logutils

Expand All @@ -22,7 +24,6 @@
from recipe_system.cal_service import set_calservice
from recipe_system.cal_service import localmanager_available
# ------------------------------------------------------------------------------

def main(args):
"""
'main' is called with a Namespace 'args' parameter, or an object that
Expand Down Expand Up @@ -84,11 +85,19 @@ def main(args):
if localmanager_available:
set_calservice(local_db_dir=args.local_db_dir)


log.stdinfo("\n\t\t\t--- reduce v{} ---".format(rs_version))
log.stdinfo("\nRunning on Python {}".format(sys.version.split()[0]))
r_reduce = Reduce(args)
estat = r_reduce.runr()
try:
r_reduce.runr()
except KeyboardInterrupt:
log.error("Caught KeyboardInterrupt (^C) signal")
estat = signal.SIGINT
except Exception as err:
log.error("reduce caught an unhandled exception.")
log.error("\nReduce instance aborted.")
estat = signal.SIGABRT

if estat != 0:
log.stdinfo("\n\nreduce exit status: %d\n" % estat)
else:
Expand Down

0 comments on commit 2134f69

Please sign in to comment.