Skip to content

flake8 #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions folium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

from __future__ import absolute_import

from branca.colormap import (ColorMap, LinearColormap, StepColormap)
from branca.element import (CssLink, Div, Element, Figure, Html, IFrame,
JavascriptLink, Link, MacroElement)
from branca.colormap import (ColorMap, LinearColormap, StepColormap)

from ._version import get_versions

from .folium import Map
from .map import (
FeatureGroup, FitBounds, Icon, LayerControl, Marker, Popup, TileLayer
)
from .features import (
ClickForMarker, CustomIcon, DivIcon, GeoJson, LatLngPopup, CircleMarker,
MarkerCluster, PolyLine, Vega, RegularPolygonMarker,
TopoJson, WmsTileLayer
CircleMarker, ClickForMarker, CustomIcon, DivIcon, GeoJson, LatLngPopup,
MarkerCluster, PolyLine, RegularPolygonMarker, TopoJson, Vega, WmsTileLayer,
)

from .folium import Map

from ._version import get_versions
from .map import (
FeatureGroup, FitBounds, Icon, LayerControl, Marker, Popup, TileLayer
)

__version__ = get_versions()['version']
del get_versions
Expand Down
62 changes: 30 additions & 32 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@

import json

from jinja2 import Template
from six import text_type, binary_type

from branca.utilities import (
_parse_size, _locations_mirror, _locations_tolist, image_to_url,
none_min, none_max, iter_points
)
from branca.element import (Element, Figure, JavascriptLink, CssLink,
MacroElement)
from branca.colormap import LinearColormap
from branca.element import (CssLink, Element, Figure, JavascriptLink, MacroElement)
from branca.utilities import (_locations_mirror, _locations_tolist, _parse_size,
image_to_url, iter_points, none_max, none_min)

from jinja2 import Template

from six import binary_type, text_type

from .map import Layer, Icon, Marker, Popup, FeatureGroup
from .map import FeatureGroup, Icon, Layer, Marker, Popup


class WmsTileLayer(Layer):
Expand Down Expand Up @@ -56,7 +54,7 @@ class WmsTileLayer(Layer):
http://leafletjs.com/reference.html#tilelayer-wms

"""
def __init__(self, url, name=None, layers=None, styles=None, format=None,
def __init__(self, url, name=None, layers=None, styles=None, fmt=None,
transparent=True, version='1.1.1', attr=None, overlay=True,
control=True):
super(WmsTileLayer, self).__init__(overlay=overlay, control=control, name=name) # noqa
Expand All @@ -65,7 +63,7 @@ def __init__(self, url, name=None, layers=None, styles=None, format=None,
# Options.
self.layers = layers if layers else ''
self.styles = styles if styles else ''
self.format = format if format else 'image/jpeg'
self.format = fmt if fmt else 'image/jpeg'
self.transparent = transparent
self.version = version
self._template = Template(u"""
Expand Down Expand Up @@ -161,11 +159,11 @@ def render(self, **kwargs):
super(RegularPolygonMarker, self).render()

figure = self.get_root()
assert isinstance(figure, Figure), ("You cannot render this Element "
"if it's not in a Figure.")
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.3.0/leaflet-dvf.markers.min.js"), # noqa
JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.3.0/leaflet-dvf.markers.min.js'), # noqa
name='dvf_js')


Expand Down Expand Up @@ -199,7 +197,7 @@ class Vega(Element):

"""
def __init__(self, data, width=None, height=None,
left="0%", top="0%", position='relative'):
left='0%', top='0%', position='relative'):
super(Vega, self).__init__()
self._name = 'Vega'
self.data = data.to_json() if hasattr(data, 'to_json') else data
Expand All @@ -215,7 +213,7 @@ def __init__(self, data, width=None, height=None,
self.left = _parse_size(left)
self.top = _parse_size(top)
self.position = position
self._template = Template(u"")
self._template = Template(u'')

def render(self, **kwargs):
"""Renders the HTML representation of the element."""
Expand All @@ -230,8 +228,8 @@ def render(self, **kwargs):
""").render(this=self)), name=self.get_name())

figure = self.get_root()
assert isinstance(figure, Figure), ("You cannot render this Element "
"if it's not in a Figure.")
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(Element(Template("""
<style> #{{this.get_name()}} {
Expand All @@ -244,15 +242,15 @@ def render(self, **kwargs):
""").render(this=self, **kwargs)), name=self.get_name())

figure.header.add_child(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"), # noqa
JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js'),
name='d3')

figure.header.add_child(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/vega/1.4.3/vega.min.js"), # noqa
JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/vega/1.4.3/vega.min.js'),
name='vega')

figure.header.add_child(
JavascriptLink("https://code.jquery.com/jquery-2.1.0.min.js"),
JavascriptLink('https://code.jquery.com/jquery-2.1.0.min.js'),
name='jquery')

figure.script.add_child(
Expand Down Expand Up @@ -550,11 +548,11 @@ def render(self, **kwargs):
super(TopoJson, self).render(**kwargs)

figure = self.get_root()
assert isinstance(figure, Figure), ("You cannot render this Element "
"if it's not in a Figure.")
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"), # noqa
JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js'), # noqa
name='topojson')

def _get_self_bounds(self):
Expand Down Expand Up @@ -621,23 +619,23 @@ def render(self, **kwargs):
super(MarkerCluster, self).render()

figure = self.get_root()
assert isinstance(figure, Figure), ("You cannot render this Element "
"if it's not in a Figure.")
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')
figure.header.add_child(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.0.0/leaflet.markercluster-src.js"), # noqa
JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.0.0/leaflet.markercluster-src.js'), # noqa
name='marker_cluster_src')

figure.header.add_child(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.0.0/leaflet.markercluster.js"), # noqa
JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.0.0/leaflet.markercluster.js'), # noqa
name='marker_cluster')

figure.header.add_child(
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.0.0/MarkerCluster.css"), # noqa
CssLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.0.0/MarkerCluster.css'), # noqa
name='marker_cluster_css')

figure.header.add_child(
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.0.0/MarkerCluster.Default.css"), # noqa
name="marker_cluster_default_css")
CssLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.0.0/MarkerCluster.Default.css'), # noqa
name='marker_cluster_default_css')


class DivIcon(MacroElement):
Expand Down
21 changes: 11 additions & 10 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
from branca.colormap import StepColormap
from branca.utilities import color_brewer

from .map import LegacyMap, FitBounds
import requests

from .features import GeoJson, TopoJson
from .map import FitBounds, LegacyMap

import requests

class Map(LegacyMap):
"""Create a Map with Folium and Leaflet.js
Expand Down Expand Up @@ -144,7 +145,7 @@ def fit_bounds(self, bounds, padding_top_left=None,
def choropleth(self, geo_path=None, geo_str=None, data_out='data.json',
data=None, columns=None, key_on=None, threshold_scale=None,
fill_color='blue', fill_opacity=0.6, line_color='black',
line_weight=1, line_opacity=1, legend_name="",
line_weight=1, line_opacity=1, legend_name='',
topojson=None, reset=False, smooth_factor=None,
highlight=None):
"""
Expand Down Expand Up @@ -313,17 +314,17 @@ def color_scale_fun(x):

def style_function(x):
return {
"weight": line_weight,
"opacity": line_opacity,
"color": line_color,
"fillOpacity": fill_opacity,
"fillColor": color_scale_fun(x)
'weight': line_weight,
'opacity': line_opacity,
'color': line_color,
'fillOpacity': fill_opacity,
'fillColor': color_scale_fun(x)
}

def highlight_function(x):
return {
"weight": line_weight + 2,
"fillOpacity": fill_opacity + .2
'weight': line_weight + 2,
'fillOpacity': fill_opacity + .2
}

if topojson:
Expand Down
24 changes: 12 additions & 12 deletions folium/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

from __future__ import unicode_literals

import json
import os
import tempfile
import time

import json
from collections import OrderedDict

from branca.element import CssLink, Element, Figure, Html, JavascriptLink, MacroElement
from branca.utilities import _parse_size

from jinja2 import Environment, PackageLoader, Template

from branca.six import text_type, binary_type
from branca.utilities import _parse_size
from branca.element import (Element, Figure, MacroElement, Html,
JavascriptLink, CssLink)
from six import binary_type, text_type

ENV = Environment(loader=PackageLoader('folium', 'templates'))

Expand Down Expand Up @@ -150,7 +150,7 @@ class LegacyMap(MacroElement):
... attr='Mapbox attribution')
"""
def __init__(self, location=None, width='100%', height='100%',
left="0%", top="0%", position='relative',
left='0%', top='0%', position='relative',
tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=1,
zoom_start=10, continuous_world=False, world_copy_jump=False,
no_wrap=False, attr=None, min_lat=-90, max_lat=90,
Expand Down Expand Up @@ -257,14 +257,14 @@ def _to_png(self):
if self._png_image is None:
import selenium.webdriver

with tempfile.NamedTemporaryFile(suffix=".html") as f:
with tempfile.NamedTemporaryFile(suffix='.html') as f:
fname = f.name
self.save(fname)
driver = selenium.webdriver.PhantomJS(service_log_path=os.path.devnull)
driver.get('file://{}'.format(fname))
driver.maximize_window()
# Ignore user map size.
driver.execute_script("document.body.style.width = '100%';")
driver.execute_script("document.body.style.width = '100%';") # noqa
# We should probably monitor if some element is present,
# but this is OK for now.
time.sleep(3)
Expand Down Expand Up @@ -302,8 +302,8 @@ def add_tile_layer(self, tiles='OpenStreetMap', name=None,
def render(self, **kwargs):
"""Renders the HTML representation of the element."""
figure = self.get_root()
assert isinstance(figure, Figure), ("You cannot render this Element "
"if it's not in a Figure.")
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

# Set global switches
figure.header.add_child(self.global_switches, name='global_switches')
Expand Down Expand Up @@ -726,8 +726,8 @@ def render(self, **kwargs):
child.render(**kwargs)

figure = self.get_root()
assert isinstance(figure, Figure), ("You cannot render this Element "
"if it's not in a Figure.")
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.script.add_child(Element(
self._template.render(this=self, kwargs=kwargs)),
Expand Down
12 changes: 6 additions & 6 deletions folium/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
Add different objects/effects on a folium map.
"""

from .marker_cluster import MarkerCluster
from .scroll_zoom_toggler import ScrollZoomToggler
from .terminator import Terminator
from .boat_marker import BoatMarker
from .timestamped_geo_json import TimestampedGeoJson
from .float_image import FloatImage
from .fullscreen import Fullscreen
from .heat_map import HeatMap
from .image_overlay import ImageOverlay
from .fullscreen import Fullscreen
from .marker_cluster import MarkerCluster
from .polyline_text_path import PolyLineTextPath
from .float_image import FloatImage
from .scroll_zoom_toggler import ScrollZoomToggler
from .terminator import Terminator
from .timestamped_geo_json import TimestampedGeoJson

__all__ = [
'MarkerCluster',
Expand Down
14 changes: 9 additions & 5 deletions folium/plugins/boat_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
Optionally you can append a wind direction.

"""

import json
from jinja2 import Template

from branca.element import JavascriptLink, Figure

from branca.element import Figure, JavascriptLink

from folium.map import Marker

from jinja2 import Template


class BoatMarker(Marker):
"""Adds a BoatMarker layer on the map."""
Expand Down Expand Up @@ -57,9 +61,9 @@ def render(self, **kwargs):
super(BoatMarker, self).render(**kwargs)

figure = self.get_root()
assert isinstance(figure, Figure), ("You cannot render this Element "
"if it's not in a Figure.")
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink("https://thomasbrueggemann.github.io/leaflet.boatmarker/js/leaflet.boatmarker.min.js"), # noqa
JavascriptLink('https://thomasbrueggemann.github.io/leaflet.boatmarker/js/leaflet.boatmarker.min.js'), # noqa
name='markerclusterjs')
4 changes: 3 additions & 1 deletion folium/plugins/float_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

Adds a floating image in HTML canvas on top of the map.
"""
from jinja2 import Template


from branca.element import MacroElement

from jinja2 import Template


class FloatImage(MacroElement):
def __init__(self, image, bottom=75, left=75):
Expand Down
Loading