Skip to content

Commit

Permalink
Merge pull request #1489 from nsoranzo/flake8_fixes
Browse files Browse the repository at this point in the history
Fix all E731 "errors".
  • Loading branch information
dannon committed Jan 14, 2016
2 parents f41550f + 487ece0 commit 33a3ae4
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 48 deletions.
8 changes: 2 additions & 6 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,6 @@ def __filter_contents( self, content_class, **kwds ):
assert db_session is not None
query = db_session.query( content_class ).filter( content_class.table.c.history_id == self.id )
query = query.order_by( content_class.table.c.hid.asc() )
python_filter = None
deleted = galaxy.util.string_as_bool_or_none( kwds.get( 'deleted', None ) )
if deleted is not None:
query = query.filter( content_class.deleted == deleted )
Expand All @@ -1411,11 +1410,8 @@ def __filter_contents( self, content_class, **kwds ):
if len(ids) < max_in_filter_length:
query = query.filter( content_class.id.in_(ids) )
else:
python_filter = lambda content: content.id in ids
if python_filter:
return ifilter(python_filter, query)
else:
return query
query = ifilter(lambda content: content.id in ids, query)
return query

def __collection_contents_iter( self, **kwds ):
return self.__filter_contents( HistoryDatasetCollectionAssociation, **kwds )
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/model/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def total_size(o, handlers={}, verbose=False):
Recipe from: https://code.activestate.com/recipes/577504-compute-memory-footprint-of-an-object-and-its-cont/
"""
dict_handler = lambda d: chain.from_iterable(d.items())
def dict_handler(d):
return chain.from_iterable(d.items())
all_handlers = { tuple: iter,
list: iter,
deque: iter,
Expand Down
9 changes: 6 additions & 3 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ def to_dict( self, trans, view='collection', value_mapper=None, other_values={}
return d


DEFAULT_VALUE_MAP = lambda x: x
def DEFAULT_VALUE_MAP(x):
return x


def parse_dynamic_options(param, input_source):
Expand Down Expand Up @@ -1873,9 +1874,11 @@ def get_html_field( self, trans=None, value=None, other_values={} ):

def _get_select_dataset_collection_fields( self, history, dataset_matcher, multiple=False, suffix="|__collection_multirun__", reduction=False ):
if not reduction:
value_modifier = lambda x: x
def value_modifier(x):
return x
else:
value_modifier = lambda value: "__collection_reduce__|%s" % value
def value_modifier(value):
return "__collection_reduce__|%s" % value

value = dataset_matcher.value
if value is not None:
Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/tools/parser/output_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ def parse_cast_attribute( cast ):
elif cast == 'str':
cast = str
else:
cast = lambda x: x # return value as-is
# return value as-is
def cast(x):
return x
return cast


Expand Down
18 changes: 13 additions & 5 deletions lib/galaxy/tools/test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import logging
import os
import os.path
import galaxy.tools.parameters.basic
import galaxy.tools.parameters.grouping
from galaxy.util import string_as_bool

try:
from nose.tools import nottest
except ImportError:
nottest = lambda x: x
import logging
def nottest(x):
return x

log = logging.getLogger( __name__ )

Expand Down Expand Up @@ -74,11 +76,15 @@ def __matching_case_for_value( self, cond, declared_value ):
query_value = test_param.checked
else:
query_value = _process_bool_param_value( test_param, declared_value )
matches_declared_value = lambda case_value: _process_bool_param_value( test_param, case_value ) == query_value

def matches_declared_value(case_value):
return _process_bool_param_value( test_param, case_value ) == query_value
elif isinstance(test_param, galaxy.tools.parameters.basic.SelectToolParameter):
if declared_value is not None:
# Test case supplied explicit value to check against.
matches_declared_value = lambda case_value: case_value == declared_value

def matches_declared_value(case_value):
return case_value == declared_value
elif test_param.static_options:
# No explicit value in test case, not much to do if options are dynamic but
# if static options are available can find the one specified as default or
Expand All @@ -90,7 +96,9 @@ def __matching_case_for_value( self, cond, declared_value ):
first_option = test_param.static_options[0]
first_option_value = first_option[1]
default_option = first_option_value
matches_declared_value = lambda case_value: case_value == default_option

def matches_declared_value(case_value):
return case_value == default_option
else:
# No explicit value for this param and cannot determine a
# default - give up. Previously this would just result in a key
Expand Down
9 changes: 5 additions & 4 deletions lib/galaxy/tools/toolbox/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ class ToolSection( Dictifiable, HasPanelItems, object ):
def __init__( self, item=None ):
""" Build a ToolSection from an ElementTree element or a dictionary.
"""
f = lambda item, val: item is not None and item.get( val ) or ''
self.name = f( item, 'name' )
self.id = f( item, 'id' )
self.version = f( item, 'version' )
if item is None:
item = dict()
self.name = item.get('name') or ''
self.id = item.get('id') or ''
self.version = item.get('version') or ''
self.elems = ToolPanelElements()

def copy( self ):
Expand Down
5 changes: 4 additions & 1 deletion lib/galaxy/tools/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
# remote ComputeEnvironments (such as one used by Pulsar) determine what values to
# rewrite or transfer...
PATH_ATTRIBUTES = [ "path" ]


# ... by default though - don't rewrite anything (if no ComputeEnviornment
# defined or ComputeEnvironment doesn't supply a rewriter).
DEFAULT_PATH_REWRITER = lambda x: x
def DEFAULT_PATH_REWRITER(x):
return x


class ToolParameterValueWrapper( object ):
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/util/object_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@

if sys.version_info > (3, 0):
# __coerce__ doesn't do anything under Python anyway.
coerce = lambda x, y: x
def coerce(x, y):
return x


def sanitize_lists_to_string( values, valid_characters=VALID_CHARACTERS, character_map=CHARACTER_MAP, invalid_character=INVALID_CHARACTER ):
Expand Down
9 changes: 3 additions & 6 deletions lib/galaxy/util/pastescript/loadwsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

import inspect
import os
import sys
import re
import sys

from galaxy.util.properties import NicerConfigParser

import pkg_resources
from six import iteritems

__all__ = ['loadapp', 'loadserver', 'loadfilter', 'appconfig']

Expand All @@ -31,15 +32,11 @@ def print_(template, *args, **kwargs):

if sys.version_info < (3, 0):
from urllib import unquote
iteritems = lambda d: d.iteritems()
dictkeys = lambda d: d.keys()

def reraise(t, e, tb):
exec('raise t, e, tb', dict(t=t, e=e, tb=tb))
else:
from urllib.parse import unquote
iteritems = lambda d: d.items()
dictkeys = lambda d: list(d.keys())

def reraise(t, e, tb):
exec('raise e from tb', dict(e=e, tb=tb))
Expand Down Expand Up @@ -703,7 +700,7 @@ def find_egg_entry_point(self, object_type, name=None):
dist.location,
', '.join(_flatten(object_type.egg_protocols)),
', '.join(_flatten([
dictkeys(pkg_resources.get_entry_info(self.spec, prot, name) or {})
list((pkg_resources.get_entry_info(self.spec, prot, name) or {}).keys())
for prot in protocol_options] or '(no entry points)'))))
if len(possible) > 1:
raise LookupError(
Expand Down
7 changes: 5 additions & 2 deletions lib/galaxy/visualization/genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@ def get_dbkeys( self, trans, chrom_info=False, **kwd ):
# Add app keys to dbkeys.

# If chrom_info is True, only include keys with len files (which contain chromosome info).
filter_fn = lambda b: True
if chrom_info:
filter_fn = lambda b: b.len_file is not None
def filter_fn(b):
return b.len_file is not None
else:
def filter_fn(b):
return True

dbkeys.extend( [ ( genome.description, genome.key ) for key, genome in self.genomes.items() if filter_fn( genome ) ] )

Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/web/framework/openid_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
oidutil = None

class FakeConsumer( object ):
__getattr__ = lambda x, y: None
def __getattr__(x, y):
return None
consumer = FakeConsumer()


Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
# 203 whitespace before ':'
# 402 module level import not at top of file # TODO, we would like to improve this.
# 501 is line length
# E731 is inline assigned lambdas -- #TODO this should be revisited to see if we want to change our usage.
ignore = E128,E201,E202,E203,E501,E402,E731
ignore = E128,E201,E202,E203,E501,E402
10 changes: 7 additions & 3 deletions test/api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,15 @@ def list_identifiers( self, history_id, contents=None ):
# 2-tuples of form (name, dataset_content).
if contents and isinstance(contents[0], tuple):
hdas = self.__datasets( history_id, count=count, contents=[c[1] for c in contents] )
hda_to_identifier = lambda ( i, hda ): dict( name=contents[i][0], src="hda", id=hda[ "id" ] )

def hda_to_identifier(i, hda):
return dict(name=contents[i][0], src="hda", id=hda["id"])
else:
hdas = self.__datasets( history_id, count=count, contents=contents )
hda_to_identifier = lambda ( i, hda ): dict( name="data%d" % ( i + 1 ), src="hda", id=hda[ "id" ] )
element_identifiers = map( hda_to_identifier, enumerate( hdas ) )

def hda_to_identifier(i, hda):
return dict(name="data%d" % (i + 1), src="hda", id=hda["id"])
element_identifiers = [hda_to_identifier(i, hda) for (i, hda) in enumerate(hdas)]
return element_identifiers

def __create( self, payload ):
Expand Down
9 changes: 3 additions & 6 deletions test/casperjs/casperjs_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,12 @@ def browser_error_to_exception( self, script_path, stdout_output ):
"""Converts the headless' error from JSON into a more informative
python HeadlessJSJavascriptError.
"""
get_error = lambda d: d[ 'errors' ][0]
get_msg = lambda err: err[ 'msg' ]
get_trace = lambda err: err[ 'backtrace' ]
try:
# assume it's json and located in errors (and first)
js_test_results = json.loads( stdout_output )
last_error = get_error( js_test_results )
err_string = ( "%s\n%s" % ( get_msg( last_error ),
self.browser_backtrace_to_string( get_trace( last_error ) ) ) )
last_error = js_test_results['errors'][0]
err_string = ( "%s\n%s" % ( last_error['msg'],
self.browser_backtrace_to_string( last_error['backtrace'] ) ) )

# if we couldn't parse json from what's returned on the error, dump stdout
except ValueError, val_err:
Expand Down
6 changes: 4 additions & 2 deletions test/functional/test_toolbox.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import new
import sys
from base.twilltestcase import TwillTestCase
Expand All @@ -6,11 +7,12 @@
from base.instrument import register_job_data
from galaxy.tools import DataManagerTool
from galaxy.util import bunch
import logging

try:
from nose.tools import nottest
except ImportError:
nottest = lambda x: x
def nottest(x):
return x

log = logging.getLogger( __name__ )

Expand Down
8 changes: 4 additions & 4 deletions test/unit/tools/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ def __history_dataset_collection_for( self, hdas, collection_type="list", id=123
collection = galaxy.model.DatasetCollection(
collection_type=collection_type,
)
to_element = lambda hda: galaxy.model.DatasetCollectionElement(
collection=collection,
element=hda,
)

def to_element(hda):
return galaxy.model.DatasetCollectionElement(collection=collection,
element=hda)
elements = map(to_element, hdas)
if collection_type == "list:paired":
paired_collection = galaxy.model.DatasetCollection(
Expand Down

0 comments on commit 33a3ae4

Please sign in to comment.