Skip to content

Commit

Permalink
Merge branch 'dev' of git://github.com/galaxyproject/galaxy into repo…
Browse files Browse the repository at this point in the history
…_queue_sharing
  • Loading branch information
davebx committed Sep 13, 2016
2 parents aae40ca + 63f758f commit 0baf22c
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/galaxy/jobs/__init__.py
Expand Up @@ -755,6 +755,7 @@ def __init__( self, job, queue, use_persisted_destination=False ):
self.sa_session = self.app.model.context
self.extra_filenames = []
self.command_line = None
self.dependencies = []
# Tool versioning variables
self.write_version_cmd = None
self.version_string = ""
Expand Down Expand Up @@ -902,6 +903,7 @@ def get_special( ):
# We need command_line persisted to the db in order for Galaxy to re-queue the job
# if the server was stopped and restarted before the job finished
job.command_line = unicodify(self.command_line)
job.dependencies = self.tool.dependencies
self.sa_session.add( job )
self.sa_session.flush()
# Return list of all extra files
Expand Down
7 changes: 7 additions & 0 deletions lib/galaxy/model/__init__.py
Expand Up @@ -393,6 +393,7 @@ def __init__( self ):
self.tool_id = None
self.tool_version = None
self.command_line = None
self.dependencies = []
self.param_filename = None
self.parameters = []
self.input_datasets = []
Expand Down Expand Up @@ -450,6 +451,9 @@ def get_tool_version( self ):
def get_command_line( self ):
return self.command_line

def get_dependencies(self):
return self.dependencies

def get_param_filename( self ):
return self.param_filename

Expand Down Expand Up @@ -530,6 +534,9 @@ def set_tool_version( self, tool_version ):
def set_command_line( self, command_line ):
self.command_line = command_line

def set_dependencies( self, dependencies ):
self.dependencies = dependencies

def set_param_filename( self, param_filename ):
self.param_filename = param_filename

Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/model/mapping.py
Expand Up @@ -445,6 +445,7 @@
Column( "state", String( 64 ), index=True ),
Column( "info", TrimmedString( 255 ) ),
Column( "command_line", TEXT ),
Column( "dependencies", JSONType, nullable=True),
Column( "param_filename", String( 1024 ) ),
Column( "runner_name", String( 255 ) ),
Column( "stdout", TEXT ),
Expand Down
@@ -0,0 +1,49 @@
"""
Add dependencies column to jobs table
"""
from __future__ import print_function

import logging

from sqlalchemy import Column, MetaData, Table

from galaxy.model.custom_types import JSONType

log = logging.getLogger( __name__ )
jobs_dependencies_column = Column( "dependencies", JSONType, nullable=True )


def display_migration_details():
print("")
print("This migration adds dependencies column to job table")


def upgrade(migrate_engine):
print(__doc__)
metadata = MetaData()
metadata.bind = migrate_engine
metadata.reflect()

# Add the dependencies column to the job table
try:
jobs_table = Table( "job", metadata, autoload=True )
jobs_dependencies_column.create( jobs_table )
assert jobs_dependencies_column is jobs_table.c.dependencies
except Exception as e:
print(str(e))
log.error( "Adding column 'dependencies' to job table failed: %s" % str( e ) )
return


def downgrade(migrate_engine):
metadata = MetaData()
metadata.bind = migrate_engine
metadata.reflect()

# Drop the job table's dependencies column.
try:
jobs_table = Table( "job", metadata, autoload=True )
jobs_dependencies = jobs_table.c.dependencies
jobs_dependencies.drop()
except Exception as e:
log.debug( "Dropping 'dependencies' column from job table failed: %s" % ( str( e ) ) )
5 changes: 4 additions & 1 deletion lib/galaxy/tools/__init__.py
Expand Up @@ -304,6 +304,7 @@ def __init__( self, config_file, tool_source, app, guid=None, repository_id=None
self.guid = guid
self.old_id = None
self.version = None
self.dependencies = []
# Enable easy access to this tool's version lineage.
self.lineage_ids = []
# populate toolshed repository info, if available
Expand Down Expand Up @@ -1284,13 +1285,15 @@ def validate_inputs( input, value, error, parent, context, prefixed_name, prefix

def build_dependency_shell_commands( self, job_directory=None, metadata=False ):
"""Return a list of commands to be run to populate the current environment to include this tools requirements."""
return self.app.toolbox.dependency_manager.dependency_shell_commands(
requirements_to_dependencies = self.app.toolbox.dependency_manager.requirements_to_dependencies(
self.requirements,
installed_tool_dependencies=self.installed_tool_dependencies,
tool_dir=self.tool_dir,
job_directory=job_directory,
metadata=metadata,
)
self.dependencies = [dep.to_dict() for dep in requirements_to_dependencies.values()]
return [dep.shell_commands(req) for req, dep in requirements_to_dependencies.items()]

@property
def installed_tool_dependencies(self):
Expand Down
22 changes: 13 additions & 9 deletions lib/galaxy/tools/deps/__init__.py
Expand Up @@ -88,21 +88,25 @@ def __init__( self, default_base_path, conf_file=None, **extra_config ):
self.dependency_resolvers = self.__build_dependency_resolvers( conf_file )

def dependency_shell_commands( self, requirements, **kwds ):
commands = []
requirement_to_dependency = self.requirements_to_dependencies(requirements, **kwds)
return [dependency.shell_commands(requirement) for requirement, dependency in requirement_to_dependency.items()]

def requirements_to_dependencies(self, requirements, **kwds):
"""
Takes a list of requirements and returns a dictionary
with requirements as key and dependencies as value.
"""
requirement_to_dependency = dict()
for requirement in requirements:
log.debug( "Building dependency shell command for dependency '%s'", requirement.name )
dependency = NullDependency(version=requirement.version, name=requirement.name)
if requirement.type in [ 'package', 'set_environment' ]:
dependency = self.find_dep( name=requirement.name,
version=requirement.version,
type=requirement.type,
**kwds )
dependency_commands = dependency.shell_commands( requirement )
if not dependency_commands:
log.warning( "Failed to resolve dependency on '%s', ignoring", requirement.name )
else:
commands.append( dependency_commands )
return commands
log.debug(dependency.resolver_msg)
if dependency.dependency_type:
requirement_to_dependency[requirement] = dependency
return requirement_to_dependency

def uses_tool_shed_dependencies(self):
return any( map( lambda r: isinstance( r, ToolShedPackageDependencyResolver ), self.dependency_resolvers ) )
Expand Down
14 changes: 14 additions & 0 deletions lib/galaxy/tools/deps/resolvers/__init__.py
Expand Up @@ -91,6 +91,13 @@ def exact( self ):
the dependency.
"""

@property
def resolver_msg(self):
"""
Return a message describing this dependency
"""
return "Using dependency %s version %s of type %s" % (self.name, self.version, self.dependency_type)


class NullDependency( Dependency ):
dependency_type = None
Expand All @@ -100,5 +107,12 @@ def __init__(self, version=None, name=None):
self.version = version
self.name = name

@property
def resolver_msg(self):
"""
Return a message describing this dependency
"""
return "Dependency %s not found." % self.name

def shell_commands( self, requirement ):
return None
24 changes: 24 additions & 0 deletions templates/show_params.mako
Expand Up @@ -205,6 +205,30 @@
${ render_msg( 'One or more of your original parameters may no longer be valid or displayed properly.', status='warning' ) }
%endif

%if job and job.dependencies:
<br>
<table class="tabletip">
<thead>
<tr>
<th>Dependency</th>
<th>Dependency Type</th>
<th>Version</th>
</tr>
</thead>
<tbody>

%for dependency in job.dependencies:
<tr><td>${ dependency['name'] | h }</td>
<td>${ dependency['dependency_type'] | h }</td>
<td>${ dependency['version'] | h }</td>
</tr>
%endfor

</tbody>
</table>
<br />
%endif

<script type="text/javascript">
$(function(){
$( '.input-dataset-show-params' ).on( 'click', function( ev ){
Expand Down
1 change: 1 addition & 0 deletions test/unit/jobs/test_job_wrapper.py
Expand Up @@ -157,6 +157,7 @@ class MockTool(object):

def __init__(self, app):
self.version_string_cmd = TEST_VERSION_COMMAND
self.dependencies = []

def build_dependency_shell_commands(self, job_directory):
return TEST_DEPENDENCIES_COMMANDS
Expand Down

0 comments on commit 0baf22c

Please sign in to comment.