diff --git a/.ci/flake8_lint_include_list.txt b/.ci/flake8_lint_include_list.txt index 05a81fcdd66..c59a8c9da66 100644 --- a/.ci/flake8_lint_include_list.txt +++ b/.ci/flake8_lint_include_list.txt @@ -79,9 +79,7 @@ lib/galaxy/visualization/__init__.py lib/galaxy/visualization/plugins/__init__.py lib/galaxy/visualization/plugins/utils.py lib/galaxy/visualization/tracks/ -lib/galaxy/web/base/controllers/__init__.py -lib/galaxy/web/base/__init__.py -lib/galaxy/web/base/interactive_environments.py +lib/galaxy/web/base/ lib/galaxy/web/buildapp.py lib/galaxy/web/formatting.py lib/galaxy/web/framework/base.py diff --git a/.ci/py3_sources.txt b/.ci/py3_sources.txt index 676a2225f6c..dae37277b5b 100644 --- a/.ci/py3_sources.txt +++ b/.ci/py3_sources.txt @@ -27,6 +27,7 @@ lib/galaxy/tools/ lib/galaxy/tours/ lib/galaxy/util/ lib/galaxy/visualization/ +lib/galaxy/web/base/ lib/galaxy/web/buildapp.py lib/galaxy/web/framework/base.py lib/galaxy/web/framework/decorators.py diff --git a/lib/galaxy/web/base/controller.py b/lib/galaxy/web/base/controller.py index cdd2a007166..7e9dca28a2e 100644 --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -2,40 +2,63 @@ Contains functionality needed in every web interface """ import logging -import operator import re -from six import string_types, text_type +from paste.httpexceptions import ( + HTTPBadRequest, + HTTPInternalServerError, + HTTPNotImplemented, + HTTPRequestRangeNotSatisfiable +) +from six import ( + string_types, + text_type +) from sqlalchemy import true -from paste.httpexceptions import HTTPBadRequest, HTTPInternalServerError -from paste.httpexceptions import HTTPNotImplemented, HTTPRequestRangeNotSatisfiable -from galaxy import exceptions -from galaxy import web -from galaxy import model -from galaxy import security -from galaxy import util - -from galaxy.web import error, url_for -from galaxy.web.form_builder import AddressField, CheckboxField, SelectField, TextArea, TextField -from galaxy.web.form_builder import build_select_field, HistoryField, PasswordField, WorkflowField, WorkflowMappingField -from galaxy.workflow.modules import WorkflowModuleInjector -from galaxy.security.validate_user_input import validate_publicname -from galaxy.util.sanitize_html import sanitize_html -from galaxy.model.item_attrs import UsesAnnotations -from galaxy.util.dictifiable import Dictifiable - +from galaxy import ( + exceptions, + model, + security, + util, + web +) from galaxy.datatypes.interval import ChromatinInteractions - -from galaxy.model import ExtendedMetadata, ExtendedMetadataIndex, LibraryDatasetDatasetAssociation, HistoryDatasetAssociation - -from galaxy.managers import api_keys -from galaxy.managers import tags -from galaxy.managers import workflows -from galaxy.managers import base as managers_base -from galaxy.managers import users -from galaxy.managers import configuration - +from galaxy.managers import ( + api_keys, + base as managers_base, + configuration, + tags, + users, + workflows +) +from galaxy.model import ( + ExtendedMetadata, + ExtendedMetadataIndex, + HistoryDatasetAssociation, + LibraryDatasetDatasetAssociation +) +from galaxy.model.item_attrs import UsesAnnotations +from galaxy.security.validate_user_input import validate_publicname +from galaxy.util.dictifiable import Dictifiable +from galaxy.util.sanitize_html import sanitize_html +from galaxy.web import ( + error, + url_for +) +from galaxy.web.form_builder import ( + AddressField, + build_select_field, + CheckboxField, + HistoryField, + PasswordField, + SelectField, + TextArea, + TextField, + WorkflowField, + WorkflowMappingField +) +from galaxy.workflow.modules import WorkflowModuleInjector log = logging.getLogger( __name__ ) @@ -132,7 +155,7 @@ class BaseController( object ): values = [ values ] # TODO: it may be more helpful to the consumer if we error on incomplete 3-tuples # (instead of relying on zip to shorten) - return zip( attrs, ops, values ) + return list(zip( attrs, ops, values )) def parse_limit_offset( self, qdict ): """ @@ -211,8 +234,8 @@ class BaseAPIController( BaseController ): msg = "The following value(s) for associated users and/or groups could not be parsed: %s." % ', '.join( invalid ) msg += " Valid values are email addresses of users, names of groups, or IDs of both." raise Exception( msg ) - payload['in_users'] = map( str, new_in_users ) - payload['in_groups'] = map( str, new_in_groups ) + payload['in_users'] = list(map( str, new_in_users )) + payload['in_groups'] = list(map( str, new_in_groups )) def not_implemented( self, trans, **kwd ): raise HTTPNotImplemented() @@ -2311,6 +2334,6 @@ def sort_by_attr( seq, attr ): # (seq[i].attr, i, seq[i]) and sort it. The second item of tuple is needed not # only to provide stable sorting, but mainly to eliminate comparison of objects # (which can be expensive or prohibited) in case of equal attribute values. - intermed = map( None, map( getattr, seq, ( attr, ) * len( seq ) ), xrange( len( seq ) ), seq ) + intermed = [(getattr(v, attr), i, v) for i, v in enumerate(seq)] intermed.sort() - return map( operator.getitem, intermed, ( -1, ) * len( intermed ) ) + return [_[-1] for _ in intermed] diff --git a/lib/galaxy/web/base/interactive_environments.py b/lib/galaxy/web/base/interactive_environments.py index 7beee84b52a..00dd3197b0a 100644 --- a/lib/galaxy/web/base/interactive_environments.py +++ b/lib/galaxy/web/base/interactive_environments.py @@ -1,4 +1,3 @@ -import ConfigParser import json import logging import os @@ -6,11 +5,11 @@ import random import stat import tempfile import uuid - from subprocess import PIPE, Popen from sys import platform as _platform import yaml +from six.moves import configparser from galaxy import model, web from galaxy.containers import build_container_interfaces @@ -121,7 +120,7 @@ class InteractiveEnvironmentRequest(object): def load_deploy_config(self, default_dict={}): # For backwards compat, any new variables added to the base .ini file - # will need to be recorded here. The ConfigParser doesn't provide a + # will need to be recorded here. The configparser doesn't provide a # .get() that will ignore missing sections, so we must make use of # their defaults dictionary instead. default_dict = { @@ -133,7 +132,7 @@ class InteractiveEnvironmentRequest(object): 'docker_galaxy_temp_dir': None, 'docker_connect_port': None, } - viz_config = ConfigParser.SafeConfigParser(default_dict) + viz_config = configparser.SafeConfigParser(default_dict) conf_path = os.path.join( self.attr.our_config_dir, self.attr.viz_id + ".ini" ) if not os.path.exists( conf_path ): conf_path = "%s.sample" % conf_path @@ -253,7 +252,7 @@ class InteractiveEnvironmentRequest(object): env_override = {} conf = self.get_conf_dict() conf.update(env_override) - return dict([(key.upper(), item) for key, item in conf.items()]) + return dict((key.upper(), item) for key, item in conf.items()) def _get_import_volume_for_run(self): if self.use_volumes and self.attr.import_volume: @@ -271,8 +270,8 @@ class InteractiveEnvironmentRequest(object): volumes = [] env = self._get_env_for_run(env_override) import_volume_def = self._get_import_volume_for_run() - env_str = ' '.join(['-e "%s=%s"' % (key, item) for key, item in env.items()]) - volume_str = ' '.join(['-v "%s"' % volume for volume in volumes]) if self.use_volumes else '' + env_str = ' '.join('-e "%s=%s"' % (key, item) for key, item in env.items()) + volume_str = ' '.join('-v "%s"' % volume for volume in volumes) if self.use_volumes else '' import_volume_str = '-v "{import_volume}"'.format(import_volume=import_volume_def) if import_volume_def else '' name = None # This is the basic docker command such as "sudo -u docker docker {docker_args}" diff --git a/lib/galaxy/web/base/pluginframework.py b/lib/galaxy/web/base/pluginframework.py index 704830716eb..eb85d3047e1 100644 --- a/lib/galaxy/web/base/pluginframework.py +++ b/lib/galaxy/web/base/pluginframework.py @@ -7,17 +7,19 @@ and base class for plugins that: * serve templated html * have some configuration at startup """ - +import imp +import logging import os.path import sys -import imp - -from galaxy import util -from galaxy.util import odict -from galaxy.util import bunch import mako.lookup -import logging + +from galaxy import util +from galaxy.util import ( + bunch, + odict +) + log = logging.getLogger( __name__ )