Skip to content

Commit

Permalink
Add cabspecs dict
Browse files Browse the repository at this point in the history
  • Loading branch information
SpheMakh committed May 22, 2020
1 parent 2fc3683 commit 24382fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
67 changes: 46 additions & 21 deletions stimela/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,34 +225,59 @@ def setup_job(self, image, config,
self.setup_output_wranglers(_cab.wranglers)
cont.IODEST = CONT_IO
cont.cabname = _cab.task
# Pick tag/version to use. The tag gets priority because it is more precise.
if self.tag:
try:
tvi = _cab.tag.index(self.tag)
except ValueError:
pass
elif self.version:
try:
tvi = _cab.tag.index(self.tag)
except ValueError:
self.log.error("The version you have selected is unknown")
raise SystemExit
else:
tvi = None
if tvi:

#
#Example
# ----------------
# casa_listobs:
# tag: <tag> ## optional
# version: <version> ## optional. If version is a dict, then ignore tag and priority and use <tag>:<version> pairs in dict
# force: true ## Continue even if tag is specified in the parameters.json file

cabspecs = self.recipe.cabspecs.get(cont.cabname, None)
if cabspecs:
_tag = cabspecs.get("tag", None)
_version = cabspecs.get("version", None)
_force_tag = cabspecs.get("force", False)
if isinstance(_version, dict):
if self.version in _version:
self.tag = _version[self.version]
else:
self.tag = _tag
self.version = _version
if self.version not in _cab.version:
self.log.error(f"The version you have specified for cab '{_cab.base}' is unknown")
raise ValueError

self.force_tag = _force_tag
elif self.tag or self.version:
tvi = None
if self.tag:
try:
tvi = _cab.tag.index(self.tag)
except ValueError:
pass
elif self.version:
try:
tvi = _cab.version.index(self.version)
except ValueError:
self.log.error("The version you have selected is unknown")
raise ValueError

self.tag = _cab.tag[tvi]
self.version = _cab.version[tvi]
elif self.force_tag is None:
raise StimelaBaseImageError(f"The base image '{_cab.base}' with tag '{self.tag}' has not been verified. If you wish to continue with it, please add the 'force_tag' when adding it to your recipe")
elif self.tag and self.force_tag:
self.log.warn(f"You have chosen to use an unverfied base image '{_cab.base}:{tag}'. We wish you best on your jornery.")
else:
self.tag = _cab.tag[-1]
if self.tag not in _cab.tag:
if self.force_tag:
self.log.warn(f"You have chosen to use an unverfied base image '{_cab.base}:{self.tag}'. We wish you best on your jornery.")
else:
raise StimelaBaseImageError(f"The base image '{_cab.base}' with tag '{self.tag}' has not been verified. If you wish to continue with it, please add the 'force_tag' when adding it to your recipe")

if self.jtype == "singularity":
simage = _cab.base.replace("/", "_")
cont.image = '{0:s}/{1:s}_{2:s}{3:s}'.format(singularity_image_dir,
simage, tag, singularity.suffix)
simage, self.tag, singularity.suffix)
cont.image = os.path.abspath(cont.image)
if not os.path.exists(cont.image):
singularity.pull(":".join([_cab.base, self.tag]),
Expand Down Expand Up @@ -433,7 +458,7 @@ def __init__(self, name, data=None,
self.JOB_TYPE = script_context.get('_STIMELA_JOB_TYPE', None) or JOB_TYPE

self.cabpath = cabpath
self.cabspecs = cabspecs
self.cabspecs = cabspecs or {}

# set default name for task-level logfiles
self.logfile_task = "{0}/log-{1}-{{task}}".format(log_dir or ".", self.name_) \
Expand Down
5 changes: 3 additions & 2 deletions stimela/tests/acceptance_tests/stimela-test-kat7.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def testEndToEndReduction(self):
time_out=1200)

# Gain calibration - amplitude and phase - first for BPCAL.
recipe.add('cab/casa_gaincal:0.3.0-1', 'gaincal_bp', {
recipe.add('cab/casa_gaincal', 'gaincal_bp', {
"vis": MS,
"caltable": GAINCAL_TABLE,
"field": "{0:s},{1:s}".format(BPCAL, GCAL),
Expand All @@ -249,7 +249,8 @@ def testEndToEndReduction(self):
input=INPUT,
output=OUTPUT,
label="gaincal:: Gain calibration",
time_out=300)
time_out=300,
version="5.6.1-8")

# Set fluxscale
recipe.add('cab/casa_fluxscale', 'fluxscale', {
Expand Down

0 comments on commit 24382fb

Please sign in to comment.