Skip to content

Commit

Permalink
fix E201 whitespace after '('
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusHackspacher committed Jun 2, 2018
1 parent d34b679 commit 2b4b6a8
Show file tree
Hide file tree
Showing 33 changed files with 123 additions and 122 deletions.
2 changes: 1 addition & 1 deletion development/extract_strings_from_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def parse_token(token, token_klass):
if not token.startswith(token_klass):
return token
try:
return getattr( classes[token_klass], token.split(".", 2)[1])
return getattr(classes[token_klass], token.split(".", 2)[1])
except AttributeError as e: # token not defined here
err = "This means that you either have to add an entry in horizons/constants.py "\
"in the class {} for {},\nor {} is actually a typo." \
Expand Down
2 changes: 1 addition & 1 deletion development/extract_strings_from_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
conn = sqlite3.connect(filename)

for db_file in PATHS.DB_FILES:
conn.executescript( open(db_file, "r").read())
conn.executescript(open(db_file, "r").read())

conn.commit()

Expand Down
8 changes: 4 additions & 4 deletions horizons/world/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def _init_shallow_water_bodies(self):
self._recognize_water_bodies(self.shallow_water_body)

def init_fish_indexer(self):
radius = Entities.buildings[ BUILDINGS.FISHER ].radius
radius = Entities.buildings[BUILDINGS.FISHER].radius
buildings = self.provider_buildings.provider_by_resources[RES.FISH]
self.fish_indexer = BuildingIndexer(radius, self.full_map, buildings=buildings)

Expand All @@ -409,7 +409,7 @@ def init_new_world(self, trader_enabled, pirate_enabled, natural_resource_multip

# workaround: the creation of all the objects causes a lot of logging output we don't need.
# therefore, reset the levels for now
loggers_to_silence = { 'world.production' : None }
loggers_to_silence = {'world.production': None}
for logger_name in loggers_to_silence:
logger = logging.getLogger(logger_name)
loggers_to_silence[logger_name] = logger.getEffectiveLevel()
Expand Down Expand Up @@ -533,7 +533,7 @@ def get_tile(self, point):
@param point: coords as Point
@return: instance of Ground at x, y
"""
return self.full_map.get( (point.x, point.y) )
return self.full_map.get((point.x, point.y))

@property
def settlements(self):
Expand Down Expand Up @@ -683,7 +683,7 @@ def get_checkup_hash(self):
# dicts usually aren't hashable, this makes them
# since defaultdicts appear, we discard values that can be autogenerated
# (those are assumed to default to something evaluating False)
dict_hash = lambda d : sorted(i for i in d.items() if i[1])
dict_hash = lambda d: sorted(i for i in d.items() if i[1])
for settlement in island.settlements:
storage_dict = settlement.get_component(StorageComponent).inventory._storage
entry = {
Expand Down
46 changes: 23 additions & 23 deletions horizons/world/building/buildable.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ class BuildableErrorTypes:
NO_FLAT_LAND = range(13)

text = {
NO_ISLAND : LazyT("This building must be built on an island."),
UNFIT_TILE : LazyT("This ground is not suitable for this building."),
NO_SETTLEMENT : LazyT("This building has to be built within your settlement."),
OTHER_PLAYERS_SETTLEMENT : LazyT("This area is already occupied by another player."),
OTHER_BUILDING_THERE : LazyT("This area is already occupied by another building."),
UNIT_THERE : LazyT("This area is already occupied by a unit."),
NO_COAST : LazyT("This building must be built on the coastline."),
NO_OCEAN_NEARBY : LazyT("This building has to be placed at the ocean."),
ONLY_NEAR_SHIP : LazyT("This spot is too far away from your ship."),
NEED_RES_SOURCE : LazyT("This building can only be built on a resource source."),
ISLAND_ALREADY_SETTLED : LazyT("You have already settled this island."),
NO_FLAT_LAND : LazyT("This building must be partly on flat land.")
NO_ISLAND: LazyT("This building must be built on an island."),
UNFIT_TILE: LazyT("This ground is not suitable for this building."),
NO_SETTLEMENT: LazyT("This building has to be built within your settlement."),
OTHER_PLAYERS_SETTLEMENT: LazyT("This area is already occupied by another player."),
OTHER_BUILDING_THERE: LazyT("This area is already occupied by another building."),
UNIT_THERE: LazyT("This area is already occupied by a unit."),
NO_COAST: LazyT("This building must be built on the coastline."),
NO_OCEAN_NEARBY: LazyT("This building has to be placed at the ocean."),
ONLY_NEAR_SHIP: LazyT("This spot is too far away from your ship."),
NEED_RES_SOURCE: LazyT("This building can only be built on a resource source."),
ISLAND_ALREADY_SETTLED: LazyT("You have already settled this island."),
NO_FLAT_LAND: LazyT("This building must be partly on flat land.")
}
# TODO: say res source which one we need, maybe even highlight those

Expand Down Expand Up @@ -181,7 +181,7 @@ def is_tile_buildable(cls, session, tile, ship, island=None, check_settlement=Tr
# area of the buildings is (x, y) + width/height, therefore all build positions that
# include (x, y) are (x, y) - ( [0..width], [0..height] )
return any(cls.check_build(session, Point(tile.x - x_off, tile.y - y_off), ship=ship)
for x_off, y_off in itertools.product(range(cls.size[0]), range(cls.size[1])) )
for x_off, y_off in itertools.product(range(cls.size[0]), range(cls.size[1])))
else:
return True

Expand All @@ -193,12 +193,12 @@ def check_build_fuzzy(cls, session, point, *args, **kwargs):

# this is some kind of case study of applied functional programming

def filter_duplicates(gen, transform=lambda x : x):
def filter_duplicates(gen, transform=lambda x: x):
"""
@param transform: transforms elements to hashable equivalent
"""
checked = set()
for elem in itertools.filterfalse(lambda e : transform(e) in checked, gen):
for elem in itertools.filterfalse(lambda e: transform(e) in checked, gen):
checked.add(transform(elem))
yield elem

Expand All @@ -208,9 +208,9 @@ def get_positions():
return itertools.chain.from_iterable(iters)

# generate positions and check for matches
check_pos = lambda pos : cls.check_build(session, pos, *args, **kwargs)
check_pos = lambda pos: cls.check_build(session, pos, *args, **kwargs)
checked = map(check_pos,
filter_duplicates(get_positions(), transform=lambda p : p.to_tuple()))
filter_duplicates(get_positions(), transform=lambda p: p.to_tuple()))

# filter positive solutions
result_generator = filter(lambda buildpos: buildpos.buildable, checked)
Expand Down Expand Up @@ -318,7 +318,7 @@ def check_build_line(cls, session, point1, point2, rotation=45, ship=None):
point2 = point2.copy() # only change copy
point2.x -= (cls.size[0] - 1) // 2
point2.y -= (cls.size[1] - 1) // 2
return [ cls.check_build_fuzzy(session, point2, rotation=rotation, ship=ship) ]
return [cls.check_build_fuzzy(session, point2, rotation=rotation, ship=ship)]


class BuildableSingleEverywhere(BuildableSingle):
Expand Down Expand Up @@ -380,7 +380,7 @@ def check_build_line(cls, session, point1, point2, rotation=45, ship=None):

# Pathfinding currently only supports buildingsize 1x1, so don't use it in this case
if cls.size != (1, 1):
return [ cls.check_build_fuzzy(session, point2, rotation=rotation, ship=ship) ]
return [cls.check_build_fuzzy(session, point2, rotation=rotation, ship=ship)]

# use pathfinding to get a path, then try to build along it
island = session.world.get_island(point1)
Expand Down Expand Up @@ -484,10 +484,10 @@ def _check_rotation(cls, session, position, rotation):
225
"""
coast_line_points_per_side = {
45: sum(coastline[(x, 0)] for x in range(0, cls.size[0]) ),
135: sum(coastline[(0, y)] for y in range(0, cls.size[1]) ),
225: sum(coastline[(x, cls.size[1] - 1)] for x in range(0, cls.size[0]) ),
315: sum(coastline[(cls.size[0] - 1, y)] for y in range(0, cls.size[1]) ),
45: sum(coastline[(x, 0)] for x in range(0, cls.size[0])),
135: sum(coastline[(0, y)] for y in range(0, cls.size[1])),
225: sum(coastline[(x, cls.size[1] - 1)] for x in range(0, cls.size[0])),
315: sum(coastline[(cls.size[0] - 1, y)] for y in range(0, cls.size[1])),
}

# return rotation with biggest value
Expand Down
4 changes: 2 additions & 2 deletions horizons/world/building/nature.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def initialize(self, **kwargs):

def _check_covered_by_farm(self):
"""Warn in case there is no farm nearby to cultivate the field"""
farm_in_range = any( (farm.position.distance( self.position ) <= farm.radius) for farm in
self.settlement.buildings_by_id[BUILDINGS.FARM] )
farm_in_range = any((farm.position.distance(self.position) <= farm.radius) for farm in
self.settlement.buildings_by_id[BUILDINGS.FARM])
if not farm_in_range and self.owner.is_local_player:
pos = self.position.origin
self.session.ingame_gui.message_widget.add(point=pos, string_id="FIELD_NEEDS_FARM",
Expand Down
2 changes: 1 addition & 1 deletion horizons/world/building/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def get_prebuild_data(cls, session, position):

def remove(self):
# build the deposit back here after remove() is finished
deposit_build_data = { 'inventory' : self.get_component(StorageComponent).inventory.get_dump() }
deposit_build_data = {'inventory': self.get_component(StorageComponent).inventory.get_dump()}
build_cmd = Build(self.__deposit_class, self.position.origin.x, self.position.origin.y,
self.island, rotation=self.rotation, ownerless=True, data=deposit_build_data)
Scheduler().add_new_object(build_cmd, build_cmd, run_in=0)
Expand Down
22 changes: 11 additions & 11 deletions horizons/world/building/settler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def initialize(self):
if happiness is not None:
self.get_component(StorageComponent).inventory.alter(RES.HAPPINESS, happiness)
if self.has_status_icon:
self.get_component(StorageComponent).inventory.add_change_listener( self._update_status_icon )
self.get_component(StorageComponent).inventory.add_change_listener(self._update_status_icon)
# give the user a month (about 30 seconds) to build a main square in range
if self.owner.is_local_player:
Scheduler().add_new_object(self._check_main_square_in_range, self, Scheduler().get_ticks_of_month(), loops=-1)
Expand Down Expand Up @@ -135,7 +135,8 @@ def _add_upgrade_production_line(self):
When the production finishes, it calls upgrade_materials_collected.
"""
upgrade_material_prodline = SettlerUpgradeData.get_production_line_id(self.level + 1)
self._upgrade_production = self.get_component(Producer).add_production_by_id( upgrade_material_prodline )
self._upgrade_production = self.get_component(
Producer).add_production_by_id(upgrade_material_prodline)
self._upgrade_production.add_production_finished_listener(self.level_up)

# drive the car out of the garage to make space for the building material
Expand Down Expand Up @@ -266,7 +267,8 @@ def inhabitant_check(self):

if change != 0:
# see http://wiki.unknown-horizons.org/w/Supply_citizens_with_resources
self.get_component(Producer).alter_production_time( 6.0 / 7.0 * math.log( 1.5 * (self.inhabitants + 1.2) ) )
self.get_component(Producer).alter_production_time(
6.0 / 7.0 * math.log(1.5 * (self.inhabitants + 1.2)))
self.inhabitants += change
SettlerInhabitantsChanged.broadcast(self, change)
self._changed()
Expand Down Expand Up @@ -426,7 +428,7 @@ class SettlerUpgradeData:
# basically, this is arbitrary as long as it's not the same as any of the regular
# production lines of the settler. We reuse data that has arbitrarily been set earlier
# to preserve savegame compatibility.
production_line_ids = { 1 : 24, 2 : 35, 3: 23451, 4: 34512, 5: 45123 }
production_line_ids = {1: 24, 2: 35, 3: 23451, 4: 34512, 5: 45123}

def __init__(self, producer_component, upgrade_material_data):
self.upgrade_material_data = upgrade_material_data
Expand All @@ -439,13 +441,11 @@ def get_production_lines(self):

def get_production_line_data(self, level):
"""Returns production line data for the upgrade to this level"""
prod_line_data = {
'time': 1,
'changes_animation' : 0,
'enabled_by_default' : False,
'save_statistics' : False,
'consumes' : self.upgrade_material_data[level]
}
prod_line_data = {'time': 1,
'changes_animation': 0,
'enabled_by_default': False,
'save_statistics': False,
'consumes': self.upgrade_material_data[level]}
return prod_line_data

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions horizons/world/building/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def __init__(self, *args, **kwargs):

def get_status_icons(self):
banned_classes = (InventoryFullStatus,)
return [ i for i in super().get_status_icons() if
i.__class__ not in banned_classes ]
return [i for i in super().get_status_icons() if
i.__class__ not in banned_classes]


class MainSquare(Path, StorageBuilding, ProductionBuilding):
Expand Down
2 changes: 1 addition & 1 deletion horizons/world/building/war.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class Tower(BuildableSingle, StationaryWeaponHolder, BasicBuilding):

POSSIBLE_WEAPONS = [ WEAPONS.CANNON ]
POSSIBLE_WEAPONS = [WEAPONS.CANNON]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion horizons/world/buildingowner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_settlements(self, rect, player=None):
for point in rect:
try:
if player is None or self.get_tile(point).settlement.owner == player:
settlements.add( self.get_tile(point).settlement )
settlements.add(self.get_tile(point).settlement)
except AttributeError:
# some tiles don't have settlements, we don't explicitly check for them cause
# its faster this way.
Expand Down
2 changes: 1 addition & 1 deletion horizons/world/ground.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _loadObject(cls, db):
img = load_image(list(data.keys())[0], tile_set_id, cls.shape, str(rotation))
# make the drawing origin correspond with the center of the groundpart of the image
# (instead of the center of the image)
img.setYShift(int(img.getWidth() / 4 - img.getHeight() / 2 ))
img.setYShift(int(img.getWidth() / 4 - img.getHeight() / 2))
visual.addStaticImage(rotation, img.getHandle())

# Save the object
Expand Down
8 changes: 4 additions & 4 deletions horizons/world/ingametype.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, id, yaml_data):

self._name = self._level_specific_names[start_tier] # default name: lowest available
else: # assume just one string
self._name = self._strip_translation_marks( name_data )
self._name = self._strip_translation_marks(name_data)
self.radius = yaml_data['radius']
self.component_templates = yaml_data['components']
self.action_sets = yaml_data['actionsets']
Expand Down Expand Up @@ -146,8 +146,8 @@ def __init__(self, id, yaml_data):

def _parse_component_templates(self):
"""Prepares misc data in self.component_templates"""
producer = [ comp for comp in self.component_templates if
isinstance(comp, dict) and next(iter(comp.keys())) == 'ProducerComponent' ]
producer = [comp for comp in self.component_templates if
isinstance(comp, dict) and next(iter(comp.keys())) == 'ProducerComponent']
if producer:
# we want to support string production line ids, the code should still only see integers
# therefore we do a deterministic string -> int conversion here
Expand All @@ -167,7 +167,7 @@ def _parse_component_templates(self):
# on this data type, so problems might occur, also with respect to performance.
# in principle, strings and longs should also be supported, but for the sake of
# safety, we use ints.
new_key = int( new_key % 2**31 ) # this ensures it's an integer on all reasonable platforms
new_key = int(new_key % 2**31) # this ensures it's an integer on all reasonable platforms
if new_key in new_data:
raise Exception('Error: production line id conflict.'
' Please change "{}" to anything else for "{}"'
Expand Down
10 changes: 5 additions & 5 deletions horizons/world/managers/statusiconmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def on_add_icon_message(self, message):
self.__render_status(icon_instance, self.icons[icon_instance][0])

if self.tooltip_instance is not None and self.tooltip_instance is icon_instance: # possibly have to update tooltip
self.on_hover_instances_changed( HoverInstancesChanged(self, [self.tooltip_instance]) )
self.on_hover_instances_changed(HoverInstancesChanged(self, [self.tooltip_instance]))

def on_worldobject_deleted_message(self, message):
assert isinstance(message, WorldObjectDeleted)
Expand All @@ -90,7 +90,7 @@ def on_worldobject_deleted_message(self, message):
del self.icons[message.worldobject]
# remove icon tooltip
if message.worldobject is self.tooltip_instance:
self.on_hover_instances_changed( HoverInstancesChanged(self, []) )
self.on_hover_instances_changed(HoverInstancesChanged(self, []))

def on_remove_icon_message(self, message):
"""Called by the MessageBus with RemoveStatusIcon messages."""
Expand All @@ -110,7 +110,7 @@ def on_remove_icon_message(self, message):
break

if self.tooltip_instance is not None and self.tooltip_instance is icon_instance: # possibly have to update tooltip
self.on_hover_instances_changed( HoverInstancesChanged(self, [self.tooltip_instance]) )
self.on_hover_instances_changed(HoverInstancesChanged(self, [self.tooltip_instance]))

def __render_status(self, instance, status):
status_string = self.get_status_string(instance)
Expand Down Expand Up @@ -151,7 +151,7 @@ def on_hover_instances_changed(self, msg):
instances = (i for i in instances if i in self.icons)
# and belong to the player
instances = [i for i in instances if
hasattr(i, "owner" ) and
hasattr(i, "owner") and
hasattr(i.owner, "is_local_player") and
i.owner.is_local_player]

Expand All @@ -169,5 +169,5 @@ def on_hover_instances_changed(self, msg):
self.tooltip_icon.helptext = icon.helptext

pos = NavigationTool.last_event_pos
self.tooltip_icon.position_tooltip( (pos.x, pos.y) )
self.tooltip_icon.position_tooltip((pos.x, pos.y))
self.tooltip_icon.show_tooltip()
8 changes: 4 additions & 4 deletions horizons/world/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def get_latest_stats(self):
@property
def settlements(self):
"""Calculate settlements dynamically to save having a redundant list here"""
return [ settlement for settlement in self.session.world.settlements if
settlement.owner == self ]
return [settlement for settlement in self.session.world.settlements if
settlement.owner == self]

def save(self, db):
super().save(db)
Expand Down Expand Up @@ -164,8 +164,8 @@ def get_statistics(self):
# can be used independently and the one here is always perfectly in sync
# with the other values here

get_sum = lambda l, attr : sum( getattr(obj, attr) for obj in l )
trade_posts = [ s.get_component(TradePostComponent) for s in self.settlements ]
get_sum = lambda l, attr: sum(getattr(obj, attr) for obj in l)
trade_posts = [s.get_component(TradePostComponent) for s in self.settlements]
return Data(
running_costs=get_sum(self.settlements, 'cumulative_running_costs'),
taxes=get_sum(self.settlements, 'cumulative_taxes'),
Expand Down
Loading

0 comments on commit 2b4b6a8

Please sign in to comment.