Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5119 from mvdbeek/dev_toolshed_install_improvemen…
…ts_2 Improve tool validation and metadata generation
- Loading branch information
Showing
19 changed files
with
478 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Provides a subset of app for verifying tools.""" | ||
import os | ||
import shutil | ||
import tempfile | ||
from contextlib import contextmanager | ||
|
||
from galaxy.datatypes.registry import Registry | ||
from galaxy.tools.data import ToolDataTableManager | ||
from galaxy.util.bunch import Bunch | ||
from galaxy.util.dbkeys import GenomeBuilds | ||
|
||
|
||
class ValidationContext(object): | ||
"""Minimal App object for tool validation.""" | ||
|
||
def __init__(self, app_name, | ||
security, | ||
model, | ||
tool_data_path, | ||
shed_tool_data_path, | ||
tool_data_tables=None, | ||
registry=None, | ||
hgweb_config_manager=None): | ||
self.name = app_name | ||
self.security = security | ||
self.model = model | ||
self.config = Bunch() | ||
self.config.tool_data_path = tool_data_path | ||
self.config.shed_tool_data_path = shed_tool_data_path | ||
_, self.config.tool_data_table_config = tempfile.mkstemp() | ||
_, self.config.shed_tool_data_table_config = tempfile.mkstemp() | ||
self.tool_data_tables = tool_data_tables | ||
self.datatypes_registry = registry or Registry() | ||
self.hgweb_config_manager = hgweb_config_manager | ||
_, self.config.len_file_path = tempfile.mkstemp() | ||
_, self.config.builds_file_path = tempfile.mkstemp() | ||
self.genome_builds = GenomeBuilds(self) | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
cleanup_paths = {self.config.builds_file_path, | ||
self.config.len_file_path, | ||
self.config.tool_data_table_config, | ||
self.config.shed_tool_data_table_config} | ||
for path in cleanup_paths: | ||
try: | ||
os.remove(path) | ||
except Exception: | ||
pass | ||
|
||
@staticmethod | ||
@contextmanager | ||
def from_app(app, work_dir=None): | ||
cleanup = False | ||
if not work_dir: | ||
work_dir = tempfile.mkdtemp() | ||
cleanup = True | ||
tool_data_tables = ToolDataTableManager(work_dir) | ||
with ValidationContext(app_name=app.name, | ||
security=app.security, | ||
model=app.model, | ||
tool_data_path=work_dir, | ||
shed_tool_data_path=work_dir, | ||
tool_data_tables=tool_data_tables, | ||
hgweb_config_manager=getattr(app, 'hgweb_config_manager', None) | ||
) as app: | ||
yield app | ||
if cleanup: | ||
shutil.rmtree(work_dir, ignore_errors=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Safely write file to temporary file and then move file into place.""" | ||
# Copied from https://stackoverflow.com/a/12007885. | ||
import os | ||
import tempfile | ||
|
||
|
||
class RenamedTemporaryFile(object): | ||
""" | ||
A temporary file object which will be renamed to the specified | ||
path on exit. | ||
""" | ||
def __init__(self, final_path, **kwargs): | ||
tmpfile_dir = kwargs.pop('dir', None) | ||
|
||
# Put temporary file in the same directory as the location for the | ||
# final file so that an atomic move into place can occur. | ||
|
||
if tmpfile_dir is None: | ||
tmpfile_dir = os.path.dirname(final_path) | ||
|
||
self.tmpfile = tempfile.NamedTemporaryFile(dir=tmpfile_dir, **kwargs) | ||
self.final_path = final_path | ||
|
||
def __getattr__(self, attr): | ||
""" | ||
Delegate attribute access to the underlying temporary file object. | ||
""" | ||
return getattr(self.tmpfile, attr) | ||
|
||
def __enter__(self): | ||
self.tmpfile.__enter__() | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
if exc_type is None: | ||
self.tmpfile.delete = False | ||
result = self.tmpfile.__exit__(exc_type, exc_val, exc_tb) | ||
os.rename(self.tmpfile.name, self.final_path) | ||
else: | ||
result = self.tmpfile.__exit__(exc_type, exc_val, exc_tb) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.