Skip to content

Commit 65fd403

Browse files
committed
pep8 tests
1 parent 04ad72c commit 65fd403

24 files changed

+411
-284
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ before_install:
2525

2626
script:
2727
- python setup.py test
28-
- find . -type f -name "*.py" | xargs flake8 --max-line-length=100
28+
- find ./folium -type f -name "*.py" | xargs flake8 --max-line-length=100
29+
- find ./tests -type f -name "*.py" | xargs flake8 --max-line-length=100

folium/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import absolute_import
44

5-
__version__ = '0.2.0.dev'
6-
75
from folium.folium import Map, initialize_notebook, CircleMarker
86

97
from folium.map import (FeatureGroup, FitBounds, Icon, LayerControl, Marker,
@@ -14,6 +12,8 @@
1412
MarkerCluster, MultiPolyLine, PolyLine, Vega,
1513
RegularPolygonMarker, TopoJson, WmsTileLayer)
1614

15+
__version__ = '0.2.0.dev'
16+
1717
__all__ = ['Map',
1818
'initialize_notebook',
1919
'CircleMarker',

folium/colormap.py

Lines changed: 173 additions & 135 deletions
Large diffs are not rendered by default.

folium/element.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _get_self_bounds(self):
4444
"""Computes the bounds of the object itself (not including it's children)
4545
in the form [[lat_min, lon_min], [lat_max, lon_max]]
4646
"""
47-
return [[None,None],[None,None]]
47+
return [[None, None], [None, None]]
4848

4949
def get_bounds(self):
5050
"""Computes the bounds of the object and all it's children
@@ -480,8 +480,10 @@ def _repr_html_(self, **kwargs):
480480
out = self._parent._repr_html_(**kwargs)
481481
return out
482482

483+
483484
class IFrame(Element):
484-
def __init__(self, html=None, width="100%", height=None, ratio="60%", figsize=None):
485+
def __init__(self, html=None, width="100%", height=None, ratio="60%",
486+
figsize=None):
485487
"""Create a Figure object, to plot things into it.
486488
487489
Parameters
@@ -525,16 +527,16 @@ def render(self, **kwargs):
525527
----------
526528
527529
"""
528-
html = super(IFrame,self).render(**kwargs)
530+
html = super(IFrame, self).render(**kwargs)
529531
html = "data:text/html;base64," + base64.b64encode(html.encode('utf8')).decode('utf8') # noqa
530532

531533
if self.height is None:
532534
iframe = (
533535
'<div style="width:{width};">'
534-
'<div style="position:relative;width:100%;height:0;padding-bottom:{ratio};">'
535-
'<iframe src="{html}" style="position:absolute;width:100%;height:100%;left:0;top:0;">'
536+
'<div style="position:relative;width:100%;height:0;padding-bottom:{ratio};">' # noqa
537+
'<iframe src="{html}" style="position:absolute;width:100%;height:100%;left:0;top:0;">' # noqa
536538
'</iframe>'
537-
'</div></div>').format # noqa
539+
'</div></div>').format
538540
iframe = iframe(html=html,
539541
width=self.width,
540542
ratio=self.ratio)
@@ -544,6 +546,7 @@ def render(self, **kwargs):
544546
iframe = iframe(html=html, width=self.width, height=self.height)
545547
return iframe
546548

549+
547550
class MacroElement(Element):
548551
"""This is a parent class for Elements defined by a macro template.
549552
To compute your own element, all you have to do is:

folium/features.py

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .element import Element, Figure, JavascriptLink, CssLink, MacroElement
1818
from .map import Layer, Icon, Marker, Popup
1919

20+
2021
class WmsTileLayer(Layer):
2122
def __init__(self, url, name=None,
2223
format=None, layers=None, transparent=True,
@@ -49,6 +50,7 @@ def __init__(self, url, name=None,
4950
{% endmacro %}
5051
""") # noqa
5152

53+
5254
class RegularPolygonMarker(Marker):
5355
def __init__(self, location, color='black', opacity=1, weight=2,
5456
fill_color='blue', fill_opacity=1,
@@ -128,6 +130,7 @@ def render(self, **kwargs):
128130
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.2/leaflet-dvf.markers.min.js"), # noqa
129131
name='dvf_js')
130132

133+
131134
class Vega(Element):
132135
def __init__(self, data, width=None, height=None,
133136
left="0%", top="0%", position='relative'):
@@ -137,13 +140,13 @@ def __init__(self, data, width=None, height=None,
137140
"""
138141
super(Vega, self).__init__()
139142
self._name = 'Vega'
140-
self.data = data.to_json() if hasattr(data,'to_json') else data
141-
if isinstance(self.data,text_type) or isinstance(data,binary_type):
143+
self.data = data.to_json() if hasattr(data, 'to_json') else data
144+
if isinstance(self.data, text_type) or isinstance(data, binary_type):
142145
self.data = json.loads(self.data)
143146

144147
# Size Parameters.
145-
self.width = _parse_size(self.data.get('width','100%') if width is None else width)
146-
self.height = _parse_size(self.data.get('height','100%') if height is None else height)
148+
self.width = _parse_size(self.data.get('width', '100%') if width is None else width) # noqa
149+
self.height = _parse_size(self.data.get('height', '100%') if height is None else height) # noqa
147150
self.left = _parse_size(left)
148151
self.top = _parse_size(top)
149152
self.position = position
@@ -191,6 +194,7 @@ def render(self, **kwargs):
191194
vg.parse.spec(spec, function(chart) { chart({el:div}).update(); });}"""), # noqa
192195
name='vega_parse')
193196

197+
194198
class GeoJson(MacroElement):
195199
def __init__(self, data, style_function=None):
196200
"""
@@ -220,20 +224,23 @@ def __init__(self, data, style_function=None):
220224
>>> # Providing string.
221225
>>> GeoJson(open('foo.json').read())
222226
223-
>>> # Providing a style_function that put all states in green, but Alabama in blue.
224-
>>> style_function=lambda x: {'fillColor': '#0000ff' if x['properties']['name']=='Alabama' else '#00ff00'}
227+
>>> # Provide a style_function that color all states green but Alabama.
228+
>>> gree, blue = '#0000ff', '#00ff00'
229+
>>> style_function = lambda x: {'fillColor': greem if
230+
... x['properties']['name']=='Alabama' else
231+
... blue}
225232
>>> GeoJson(geojson, style_function=style_function)
226233
"""
227234
super(GeoJson, self).__init__()
228235
self._name = 'GeoJson'
229-
if hasattr(data,'read'):
236+
if hasattr(data, 'read'):
230237
self.embed = True
231238
self.data = json.load(data)
232-
elif isinstance(data,dict):
239+
elif isinstance(data, dict):
233240
self.embed = True
234241
self.data = data
235242
elif isinstance(data, text_type) or isinstance(data, binary_type):
236-
if data.lstrip()[0] in '[{': # This is a GeoJSON inline string
243+
if data.lstrip()[0] in '[{': # This is a GeoJSON inline string.
237244
self.embed = True
238245
self.data = json.loads(data)
239246
else: # This is a filename
@@ -242,18 +249,19 @@ def __init__(self, data, style_function=None):
242249
elif data.__class__.__name__ in ['GeoDataFrame', 'GeoSeries']:
243250
self.embed = True
244251
if hasattr(data, '__geo_interface__'):
245-
# We have a GeoPandas 0.2 object
246-
self.data = json.loads(json.dumps(data.to_crs(epsg='4326').__geo_interface__))
252+
# We have a GeoPandas 0.2 object.
253+
self.data = json.loads(json.dumps(data.to_crs(epsg='4326').__geo_interface__)) # noqa
247254
elif hasattr(data, 'columns'):
248255
# We have a GeoDataFrame 0.1
249256
self.data = json.loads(data.to_crs(epsg='4326').to_json())
250257
else:
251-
raise ValueError('Unable to transform this object to a GeoJSON.')
258+
msg = 'Unable to transform this object to a GeoJSON.'
259+
raise ValueError(msg)
252260
else:
253261
raise ValueError('Unhandled object {!r}.'.format(data))
254262

255263
if style_function is None:
256-
style_function = lambda x: {}
264+
def style_function(x): return {}
257265
self.style_function = style_function
258266

259267
self._template = Template(u"""
@@ -268,14 +276,13 @@ def __init__(self, data, style_function=None):
268276
def style_data(self):
269277
if 'features' not in self.data.keys():
270278
# Catch case when GeoJSON is just a single Feature or a geometry.
271-
if not (isinstance(self.data, dict) and 'geometry' in self.data.keys()):
279+
if not (isinstance(self.data, dict) and 'geometry' in self.data.keys()): # noqa
272280
# Catch case when GeoJSON is just a geometry.
273-
self.data = {'type' : 'Feature', 'geometry' : self.data}
274-
self.data = {'type' : 'FeatureCollection', 'features' : [self.data]}
281+
self.data = {'type': 'Feature', 'geometry': self.data}
282+
self.data = {'type': 'FeatureCollection', 'features': [self.data]}
275283

276284
for feature in self.data['features']:
277-
feature.setdefault('properties',{}).setdefault('style',{}).update(
278-
self.style_function(feature))
285+
feature.setdefault('properties', {}).setdefault('style', {}).update(self.style_function(feature)) # noqa
279286
return json.dumps(self.data)
280287

281288
def _get_self_bounds(self):
@@ -287,14 +294,14 @@ def _get_self_bounds(self):
287294

288295
if 'features' not in self.data.keys():
289296
# Catch case when GeoJSON is just a single Feature or a geometry.
290-
if not (isinstance(self.data, dict) and 'geometry' in self.data.keys()):
297+
if not (isinstance(self.data, dict) and 'geometry' in self.data.keys()): # noqa
291298
# Catch case when GeoJSON is just a geometry.
292-
self.data = {'type' : 'Feature', 'geometry' : self.data}
293-
self.data = {'type' : 'FeatureCollection', 'features' : [self.data]}
299+
self.data = {'type': 'Feature', 'geometry': self.data}
300+
self.data = {'type': 'FeatureCollection', 'features': [self.data]}
294301

295-
bounds = [[None,None],[None,None]]
302+
bounds = [[None, None], [None, None]]
296303
for feature in self.data['features']:
297-
for point in iter_points(feature.get('geometry',{}).get('coordinates',{})):
304+
for point in iter_points(feature.get('geometry', {}).get('coordinates', {})): # noqa
298305
bounds = [
299306
[
300307
none_min(bounds[0][0], point[1]),
@@ -307,6 +314,7 @@ def _get_self_bounds(self):
307314
]
308315
return bounds
309316

317+
310318
class TopoJson(MacroElement):
311319
def __init__(self, data, object_path):
312320
"""
@@ -357,10 +365,10 @@ def _get_self_bounds(self):
357365

358366
data = json.loads(self.data)
359367

360-
xmin,xmax,ymin,ymax = None, None, None, None
368+
xmin, xmax, ymin, ymax = None, None, None, None
361369

362370
for arc in data['arcs']:
363-
x,y = 0,0
371+
x, y = 0, 0
364372
for dx, dy in arc:
365373
x += dx
366374
y += dy
@@ -370,16 +378,17 @@ def _get_self_bounds(self):
370378
ymax = none_max(y, ymax)
371379
return [
372380
[
373-
data['transform']['translate'][0] + data['transform']['scale'][0] * xmin,
374-
data['transform']['translate'][1] + data['transform']['scale'][1] * ymin,
381+
data['transform']['translate'][0] + data['transform']['scale'][0] * xmin, # noqa
382+
data['transform']['translate'][1] + data['transform']['scale'][1] * ymin, # noqa
375383
],
376384
[
377-
data['transform']['translate'][0] + data['transform']['scale'][0] * xmax,
378-
data['transform']['translate'][1] + data['transform']['scale'][1] * ymax,
385+
data['transform']['translate'][0] + data['transform']['scale'][0] * xmax, # noqa
386+
data['transform']['translate'][1] + data['transform']['scale'][1] * ymax, # noqa
379387
]
380388

381389
]
382390

391+
383392
class ColorScale(MacroElement):
384393
def __init__(self, color_domain, color_code, caption=""):
385394
"""
@@ -409,6 +418,7 @@ def render(self, **kwargs):
409418
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"), # noqa
410419
name='d3')
411420

421+
412422
class MarkerCluster(Layer):
413423
"""Adds a MarkerCluster layer on the map."""
414424
def __init__(self, overlay=True, control=True):
@@ -533,6 +543,7 @@ def __init__(self, location, radius=500, color='black',
533543
{% endmacro %}
534544
""")
535545

546+
536547
class LatLngPopup(MacroElement):
537548
def __init__(self):
538549
"""
@@ -651,6 +662,7 @@ def _get_self_bounds(self):
651662
]
652663
return bounds
653664

665+
654666
class MultiPolyLine(MacroElement):
655667
def __init__(self, locations, color=None, weight=None,
656668
opacity=None, latlon=True, popup=None):
@@ -697,7 +709,9 @@ def __init__(self, locations, color=None, weight=None,
697709
{{this._parent.get_name()}}.addLayer({{this.get_name()}});
698710
{% endmacro %}
699711
""") # noqa
700-
def _get_self_bounds(self):
712+
713+
714+
def _get_self_bounds(self):
701715
"""Computes the bounds of the object itself (not including it's children)
702716
in the form [[lat_min, lon_min], [lat_max, lon_max]]
703717
"""
@@ -715,6 +729,7 @@ def _get_self_bounds(self):
715729
]
716730
return bounds
717731

732+
718733
class CustomIcon(Icon):
719734
def __init__(self, icon_image, icon_size=None, icon_anchor=None,
720735
shadow_image=None, shadow_size=None, shadow_anchor=None,

0 commit comments

Comments
 (0)