Skip to content

Commit 65ec021

Browse files
committed
Merge pull request #261 from ocefpaf/pep8
Finished pep8ing
2 parents 11fc66d + b1902e2 commit 65ec021

File tree

12 files changed

+182
-132
lines changed

12 files changed

+182
-132
lines changed

folium/__init__.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
11
# -*- coding: utf-8 -*-
2+
23
from __future__ import absolute_import
34

45
__version__ = '0.2.0.dev'
56

67
from folium.folium import Map, initialize_notebook, CircleMarker
78

8-
from folium.map import FeatureGroup, FitBounds,Icon, LayerControl, Marker, Popup, TileLayer
9+
from folium.map import (FeatureGroup, FitBounds, Icon, LayerControl, Marker,
10+
Popup, TileLayer)
11+
12+
from folium.features import (ClickForMarker, ColorScale, CustomIcon, DivIcon,
13+
GeoJson, GeoJsonStyle, ImageOverlay, LatLngPopup,
14+
MarkerCluster, MultiPolyLine, PolyLine, Vega,
15+
RegularPolygonMarker, TopoJson, WmsTileLayer)
916

10-
from folium.features import (ClickForMarker, ColorScale, CustomIcon, DivIcon, GeoJson, GeoJsonStyle,
11-
ImageOverlay, LatLngPopup, MarkerCluster, MultiPolyLine, PolyLine,
12-
RegularPolygonMarker, TopoJson, Vega, WmsTileLayer)
17+
__all__ = ['Map',
18+
'initialize_notebook',
19+
'CircleMarker',
20+
'FeatureGroup',
21+
'FitBounds',
22+
'Icon',
23+
'LayerControl',
24+
'Marker',
25+
'Popup',
26+
'TileLayer',
27+
'ClickForMarker',
28+
'ColorScale',
29+
'CustomIcon',
30+
'DivIcon',
31+
'GeoJson',
32+
'GeoJsonStyle',
33+
'ImageOverlay',
34+
'LatLngPopup',
35+
'MarkerCluster',
36+
'MultiPolyLine',
37+
'PolyLine',
38+
'Vega',
39+
'RegularPolygonMarker',
40+
'TopoJson',
41+
'WmsTileLayer']

folium/element.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def to_dict(self, depth=-1, ordered=True, **kwargs):
6767
out['id'] = self._id
6868
if depth != 0:
6969
out['children'] = dict_fun([(name, child.to_dict(depth=depth-1))
70-
for name, child in self._children.items()])
70+
for name, child in self._children.items()]) # noqa
7171
return out
7272

7373
def to_json(self, depth=-1, **kwargs):
@@ -177,11 +177,11 @@ def __init__(self, url, download=False):
177177
('bootstrap',
178178
"https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"),
179179
('awesome_markers',
180-
"https://rawi.8713187.xyz/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.js"),
180+
"https://rawi.8713187.xyz/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.js"), # noqa
181181
('marker_cluster_src',
182-
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"),
182+
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"), # noqa
183183
('marker_cluster',
184-
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"),
184+
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"), # noqa
185185
]
186186

187187
_default_css = [
@@ -190,17 +190,17 @@ def __init__(self, url, download=False):
190190
("bootstrap_css",
191191
"https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"),
192192
("bootstrap_theme_css",
193-
"https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"),
193+
"https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"), # noqa
194194
("awesome_markers_font_css",
195-
"https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"),
195+
"https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"), # noqa
196196
("awesome_markers_css",
197-
"https://rawgit.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.css"),
197+
"https://rawgit.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.css"), # noqa
198198
("marker_cluster_default_css",
199-
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css"),
199+
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css"), # noqa
200200
("marker_cluster_css",
201-
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css"),
201+
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css"), # noqa
202202
("awesome_rotate_css",
203-
"https://raw.githubusercontent.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css"),
203+
"https://raw.githubusercontent.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css"), # noqa
204204
]
205205

206206

@@ -211,16 +211,19 @@ def __init__(self, width="100%", height=None, ratio="60%", figsize=None):
211211
Parameters
212212
----------
213213
width : str, default "100%"
214-
The width of the Figure. It may be a percentage or a distance (like "300px").
214+
The width of the Figure.
215+
It may be a percentage or pixel value (like "300px").
215216
height : str, default None
216-
The height of the Figure. It may be a percentage or a distance (like "300px").
217+
The height of the Figure.
218+
It may be a percentage or a pixel value (like "300px").
217219
ratio : str, default "60%"
218220
A percentage defining the aspect ratio of the Figure.
219221
It will be ignored if height is not None.
220222
figsize : tuple of two int, default None
221-
If you're a matplotlib addict, you can overwrite width and height.
222-
Values will be converted into pixels in using 60 dpi.
223-
For example figsize=(10,5) will result in width="600px", height="300px".
223+
If you're a matplotlib addict, you can overwrite width and
224+
height. Values will be converted into pixels in using 60 dpi.
225+
For example figsize=(10, 5) will result in
226+
width="600px", height="300px".
224227
"""
225228
super(Figure, self).__init__()
226229
self._name = 'Figure'
@@ -252,9 +255,9 @@ def __init__(self, width="100%", height=None, ratio="60%", figsize=None):
252255
</script>
253256
""")
254257

255-
# Create the meta tag
258+
# Create the meta tag.
256259
self.header.add_children(Element(
257-
'<meta http-equiv="content-type" content="text/html; charset=UTF-8" />'),
260+
'<meta http-equiv="content-type" content="text/html; charset=UTF-8" />'), # noqa
258261
name='meta_http')
259262

260263
# Import Javascripts
@@ -305,19 +308,18 @@ def _repr_html_(self, **kwargs):
305308
----------
306309
"""
307310
html = self.render(**kwargs)
308-
html = "data:text/html;base64," + base64.b64encode(html.encode('utf8')).decode('utf8')
311+
html = "data:text/html;base64," + base64.b64encode(html.encode('utf8')).decode('utf8') # noqa
309312

310313
if self.height is None:
311-
iframe = """
314+
iframe = ("""
312315
<div style="width:{width};">
313316
<div style="position:relative;width:100%;height:0;padding-bottom:{ratio};">
314317
<iframe src="{html}" style="position:absolute;width:100%;height:100%;left:0;top:0;">
315318
</iframe>
316-
</div></div>""".format(
317-
html=html,
318-
width=self.width,
319-
ratio=self.ratio,
320-
)
319+
</div></div>""") # noqa
320+
iframe.format(html=html,
321+
width=self.width,
322+
ratio=self.ratio)
321323
else:
322324
iframe = ('<iframe src="{html}" width="{width}" '
323325
'height="{height}"></iframe>').format
@@ -359,7 +361,7 @@ def __init__(self, data, width="100%", height="100%"):
359361
<div id="{{this.get_name()}}"
360362
style="width: {{this.width[0]}}{{this.width[1]}}; height: {{this.height[0]}}{{this.height[1]}};">
361363
{{this.data|e}}</div>
362-
""")
364+
""") # noqa
363365

364366

365367
class Div(Figure):

folium/features.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, url, name=None,
4848
).addTo({{this._parent.get_name()}});
4949
5050
{% endmacro %}
51-
""")
51+
""") # noqa
5252

5353

5454
class RegularPolygonMarker(MacroElement):
@@ -99,7 +99,7 @@ def render(self, **kwargs):
9999
"if it's not in a Figure.")
100100

101101
figure.header.add_children(
102-
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.2/leaflet-dvf.markers.min.js"),
102+
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.2/leaflet-dvf.markers.min.js"), # noqa
103103
name='dvf_js')
104104

105105

@@ -145,11 +145,11 @@ def render(self, **kwargs):
145145
""").render(this=self, **kwargs)), name=self.get_name())
146146

147147
figure.header.add_children(
148-
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"),
148+
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"), # noqa
149149
name='d3')
150150

151151
figure.header.add_children(
152-
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/vega/1.4.3/vega.min.js"),
152+
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/vega/1.4.3/vega.min.js"), # noqa
153153
name='vega')
154154

155155
figure.header.add_children(
@@ -158,7 +158,7 @@ def render(self, **kwargs):
158158

159159
figure.script.add_children(
160160
Template("""function vega_parse(spec, div) {
161-
vg.parse.spec(spec, function(chart) { chart({el:div}).update(); });}"""),
161+
vg.parse.spec(spec, function(chart) { chart({el:div}).update(); });}"""), # noqa
162162
name='vega_parse')
163163

164164

@@ -171,7 +171,7 @@ def __init__(self, data):
171171
----------
172172
data: file, dict or str.
173173
The geo-json data you want to plot.
174-
If file, then data will be read in the file and fully embedded in Leaflet's javascript.
174+
If file, then data will be read in the file and fully embedded in Leaflet's javascript. # noqa
175175
If dict, then data will be converted to JSON and embedded in the javascript.
176176
If str, then data will be passed to the javascript as-is.
177177
@@ -196,7 +196,7 @@ def __init__(self, data):
196196

197197
self._template = Template(u"""
198198
{% macro script(this, kwargs) %}
199-
var {{this.get_name()}} = L.geoJson({{this.data}}).addTo({{this._parent.get_name()}});
199+
var {{this.get_name()}} = L.geoJson({{this.data}}).addTo({{this._parent.get_name()}}); # noqa
200200
{% endmacro %}
201201
""")
202202

@@ -234,7 +234,7 @@ def render(self, **kwargs):
234234
"if it's not in a Figure.")
235235

236236
figure.header.add_children(
237-
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"),
237+
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"), # noqa
238238
name='topojson')
239239

240240

@@ -306,7 +306,7 @@ def render(self, **kwargs):
306306
"if it's not in a Figure.")
307307

308308
figure.header.add_children(
309-
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"),
309+
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"), # noqa
310310
name='d3')
311311

312312

@@ -334,7 +334,7 @@ def render(self, **kwargs):
334334
"if it's not in a Figure.")
335335

336336
figure.header.add_children(
337-
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"),
337+
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"), # noqa
338338
name='d3')
339339

340340

@@ -363,19 +363,19 @@ def render(self, **kwargs):
363363
assert isinstance(figure, Figure), ("You cannot render this Element "
364364
"if it's not in a Figure.")
365365
figure.header.add_children(
366-
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"),
366+
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"), # noqa
367367
name='marker_cluster_src')
368368

369369
figure.header.add_children(
370-
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"),
370+
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"), # noqa
371371
name='marker_cluster')
372372

373373
figure.header.add_children(
374-
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css"),
374+
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css"), # noqa
375375
name='marker_cluster_css')
376376

377377
figure.header.add_children(
378-
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css"),
378+
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css"), # noqa
379379
name="marker_cluster_default_css")
380380

381381

@@ -449,7 +449,7 @@ def __init__(self):
449449
}
450450
{{this._parent.get_name()}}.on('click', latLngPop);
451451
{% endmacro %}
452-
""")
452+
""") # noqa
453453

454454

455455
class ClickForMarker(MacroElement):
@@ -476,7 +476,7 @@ def __init__(self, popup=None):
476476
};
477477
{{this._parent.get_name()}}.on('click', newMarker);
478478
{% endmacro %}
479-
""")
479+
""") # noqa
480480

481481

482482
class PolyLine(MacroElement):
@@ -517,7 +517,7 @@ def __init__(self, locations, color=None, weight=None,
517517
});
518518
{{this._parent.get_name()}}.addLayer({{this.get_name()}});
519519
{% endmacro %}
520-
""")
520+
""") # noqa
521521

522522

523523
class MultiPolyLine(MacroElement):
@@ -558,7 +558,7 @@ def __init__(self, locations, color=None, weight=None,
558558
});
559559
{{this._parent.get_name()}}.addLayer({{this.get_name()}});
560560
{% endmacro %}
561-
""")
561+
""") # noqa
562562

563563

564564
class ImageOverlay(MacroElement):
@@ -572,10 +572,13 @@ def __init__(self, image, bounds, opacity=1., attribution=None,
572572
image: string, file or array-like object
573573
The data you want to draw on the map.
574574
* If string, it will be written directly in the output file.
575-
* If file, it's content will be converted as embedded in the output file.
576-
* If array-like, it will be converted to PNG base64 string and embedded in the output.
575+
* If file, it's content will be converted as embedded in the
576+
output file.
577+
* If array-like, it will be converted to PNG base64 string and
578+
embedded in the output.
577579
bounds: list
578-
Image bounds on the map in the form [[lat_min, lon_min], [lat_max, lon_max]]
580+
Image bounds on the map in the form
581+
[[lat_min, lon_min], [lat_max, lon_max]]
579582
opacity: float, default Leaflet's default (1.0)
580583
attr: string, default Leaflet's default ("")
581584
origin : ['upper' | 'lower'], optional, default 'upper'
@@ -584,9 +587,9 @@ def __init__(self, image, bounds, opacity=1., attribution=None,
584587
colormap : callable, used only for `mono` image.
585588
Function of the form [x -> (r,g,b)] or [x -> (r,g,b,a)]
586589
for transforming a mono image into RGB.
587-
It must output iterables of length 3 or 4, with values between 0. and 1.
588-
Hint : you can use colormaps from `matplotlib.cm`.
589-
mercator_project : bool, default False, used only for array-like image.
590+
It must output iterables of length 3 or 4, with values between
591+
0. and 1. Hint : you can use colormaps from `matplotlib.cm`.
592+
mercator_project : bool, default False, used for array-like image.
590593
Transforms the data to project (longitude, latitude)
591594
coordinates to the Mercator projection.
592595
"""
@@ -627,8 +630,10 @@ def __init__(self, icon_image, icon_size=None, icon_anchor=None,
627630
icon_image : string, file or array-like object
628631
The data you want to use as an icon.
629632
* If string, it will be written directly in the output file.
630-
* If file, it's content will be converted as embedded in the output file.
631-
* If array-like, it will be converted to PNG base64 string and embedded in the output.
633+
* If file, it's content will be converted as embedded in the
634+
output file.
635+
* If array-like, it will be converted to PNG base64 string and
636+
embedded in the output.
632637
icon_size : tuple of 2 int
633638
Size of the icon image in pixels.
634639
icon_anchor : tuple of 2 int
@@ -676,4 +681,4 @@ def __init__(self, icon_image, icon_size=None, icon_anchor=None,
676681
});
677682
{{this._parent.get_name()}}.setIcon({{this.get_name()}});
678683
{% endmacro %}
679-
""")
684+
""") # noqa

folium/folium.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,8 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
682682
colormap : callable, used only for `mono` image.
683683
Function of the form [x -> (r,g,b)] or [x -> (r,g,b,a)]
684684
for transforming a mono image into RGB.
685-
It must output iterables of length 3 or 4, with values between 0. and 1.
686-
Hint : you can use colormaps from `matplotlib.cm`.
685+
It must output iterables of length 3 or 4, with values between
686+
0. and 1. Hint : you can use colormaps from `matplotlib.cm`.
687687
688688
mercator_project : bool, default False, used only for array-like image.
689689
Transforms the data to project (longitude,latitude) coordinates

folium/map.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ def __init__(self, name=None, overlay=True):
235235
Parameters
236236
----------
237237
name : str, default None
238-
The name of the featureGroup layer. It will be displayed in the LayerControl.
239-
If None, get_name() will be called to get the object's technical (ugly) name.
238+
The name of the featureGroup layer.
239+
It will be displayed in the LayerControl.
240+
If None get_name() will be called to get the technical (ugly) name.
240241
overlay : bool, default True
241242
Whether your layer will be an overlay (ticked with a check box in
242243
LayerControls) or a base layer (ticked with a radio button).

0 commit comments

Comments
 (0)