From de2bde9f69bd225f94af97b45b5682235b2ba86b Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Tue, 27 Oct 2015 16:54:11 -0400 Subject: [PATCH 1/2] Fix a regression introduced during egg smashing that broke the drmaa_library_path param to the drmaa runner (importing drmaa needs to be delayed until runner initialization so that the param to modify $DRMAA_LIBRARY_PATH can be evaluated). --- lib/galaxy/jobs/runners/drmaa.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/galaxy/jobs/runners/drmaa.py b/lib/galaxy/jobs/runners/drmaa.py index 98b020ea5cd..65a9a8199a3 100644 --- a/lib/galaxy/jobs/runners/drmaa.py +++ b/lib/galaxy/jobs/runners/drmaa.py @@ -10,22 +10,14 @@ import string import subprocess import time -try: - import drmaa - DRMAA_IMPORT_MESSAGE = None -except (ImportError, RuntimeError) as exc: - drmaa = None - DRMAA_IMPORT_MESSAGE = ('The Python drmaa package is required to use this ' - 'feature, please install it or correct the ' - 'following error:\n%s: %s' % - (exc.__class__.__name__, str(exc))) - from galaxy import model from galaxy.jobs import JobDestination from galaxy.jobs.handler import DEFAULT_JOB_PUT_FAILURE_MESSAGE from galaxy.jobs.runners import AsynchronousJobState, AsynchronousJobRunner from galaxy.util import asbool +drmaa = None + log = logging.getLogger( __name__ ) __all__ = [ 'DRMAAJobRunner' ] @@ -42,7 +34,7 @@ class DRMAAJobRunner( AsynchronousJobRunner ): def __init__( self, app, nworkers, **kwargs ): """Start the job runner""" - assert drmaa is not None, DRMAA_IMPORT_MESSAGE + global drmaa runner_param_specs = dict( drmaa_library_path=dict( map=str, default=os.environ.get( 'DRMAA_LIBRARY_PATH', None ) ), @@ -62,6 +54,14 @@ class DRMAAJobRunner( AsynchronousJobRunner ): log.info( 'Overriding DRMAA_LIBRARY_PATH due to runner plugin parameter: %s', self.runner_params.drmaa_library_path ) os.environ['DRMAA_LIBRARY_PATH'] = self.runner_params.drmaa_library_path + try: + drmaa = __import__( "drmaa" ) + except (ImportError, RuntimeError) as exc: + raise exc.__class__('The Python drmaa package is required to use this ' + 'feature, please install it or correct the ' + 'following error:\n%s: %s' % + (exc.__class__.__name__, str(exc))) + # Subclasses may need access to state constants self.drmaa_job_states = drmaa.JobState From 04a32c7864bdeb078916b90a0b70cb059cc6ab1b Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Wed, 28 Oct 2015 09:26:34 -0400 Subject: [PATCH 2/2] Add a comment explaining the strange import behavior in drmaa to guard against future regression --- lib/galaxy/jobs/runners/drmaa.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/galaxy/jobs/runners/drmaa.py b/lib/galaxy/jobs/runners/drmaa.py index 65a9a8199a3..b1dacde9c2b 100644 --- a/lib/galaxy/jobs/runners/drmaa.py +++ b/lib/galaxy/jobs/runners/drmaa.py @@ -54,6 +54,8 @@ class DRMAAJobRunner( AsynchronousJobRunner ): log.info( 'Overriding DRMAA_LIBRARY_PATH due to runner plugin parameter: %s', self.runner_params.drmaa_library_path ) os.environ['DRMAA_LIBRARY_PATH'] = self.runner_params.drmaa_library_path + # Import is delayed until runner initialization to allow for the + # drmaa_library_path plugin param to override $DRMAA_LIBRARY_PATH try: drmaa = __import__( "drmaa" ) except (ImportError, RuntimeError) as exc: