Codebase list branca / 2ab0f36
New upstream version 0.4.1 Georges Khaznadar 4 years ago
13 changed file(s) with 56 addition(s) and 105 deletion(s). Raw diff Collapse all Expand all
5757
5858 script:
5959 - if [[ $TRAVIS_JOB_NAME == python-* ]]; then
60 cp -r tests/ /tmp ;
60 cp -r tests/ examples/ /tmp ;
6161 pushd /tmp && pytest -n 2 -rxs --cov=branca -vv tests && popd ;
6262 fi
6363
0 0.4.1
1 ~~~~~
2 - Prompt Jupyter users to trust notebook (@conengmo #75)
3 - Removed Python 2 specific code (@ocefpaf #69)
4
05 0.4.0
16 ~~~~~
27 - Dropped Python 2 support
0 # -*- coding: utf-8 -*-
1
2 from __future__ import absolute_import
3
4 import sys
5
60 import branca.colormap as colormap
71 import branca.element as element
82
93 from ._version import get_versions
4
105 __version__ = get_versions()['version']
116 del get_versions
12
13 if sys.version_info < (3, 0):
14 raise ImportError(
15 """You are running branca {} on Python 2
16
17 branca 0.4 and above are no longer compatible with Python 2, but somehow
18 you got this version anyway. Make sure you have pip >= 9.0 to avoid this
19 kind of issue, as well as setuptools >= 24.2:
20
21 $ pip install pip setuptools --upgrade
22
23 Your choices:
24
25 - Upgrade to Python 3.
26
27 - Install an older version of branca:
28
29 $ pip install 'branca<0.4.0'
30
31 """.format(__version__)) # noqa
327
338
349 __all__ = [
2222 # setup.py/versioneer.py will grep for the variable names, so they must
2323 # each be defined on a line of their own. _version.py will just call
2424 # get_keywords().
25 git_refnames = " (HEAD -> master, tag: v0.4.0)"
26 git_full = "cd2224538aac5aeb6c0dfa145af3886f192f3537"
27 git_date = "2020-02-17 15:46:35 +0100"
25 git_refnames = " (HEAD -> master, tag: v0.4.1)"
26 git_full = "75abed2d3daeb31776081ae5e4f3c78f67c9d609"
27 git_date = "2020-05-01 21:25:25 +0200"
2828 keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
2929 return keywords
3030
55
66 """
77
8 from __future__ import absolute_import
9
108 import json
119 import math
1210 import os
1311
12 from jinja2 import Template
13
1414 from branca.element import ENV, Figure, JavascriptLink, MacroElement
1515 from branca.utilities import legend_scaler
16
17 from jinja2 import Template
18
19 from six import binary_type, text_type
20
2116
2217 rootpath = os.path.abspath(os.path.dirname(__file__))
2318
4136 def _parse_color(x):
4237 if isinstance(x, (tuple, list)):
4338 color_tuple = tuple(x)[:4]
44 elif isinstance(x, (text_type, binary_type)) and _is_hex(x):
39 elif isinstance(x, (str, bytes)) and _is_hex(x):
4540 color_tuple = _parse_hex(x)
46 elif isinstance(x, (text_type, binary_type)):
41 elif isinstance(x, (str, bytes)):
4742 cname = _cnames.get(x.lower(), None)
4843 if cname is None:
4944 raise ValueError('Unknown color {!r}.'.format(cname))
99 import json
1010 import warnings
1111 from collections import OrderedDict
12 from urllib.request import urlopen
1213 from uuid import uuid4
1314
1415 from jinja2 import Environment, PackageLoader, Template
1516
16 from six import binary_type, text_type
17 from six.moves.urllib.request import urlopen
18
1917 from .utilities import _camelify, _parse_size, none_max, none_min
20
2118
2219 ENV = Environment(loader=PackageLoader('branca', 'templates'))
2320
159156 close_file : bool, default True
160157 Whether the file has to be closed after write.
161158 """
162 if isinstance(outfile, text_type) or isinstance(outfile, binary_type):
159 if isinstance(outfile, str) or isinstance(outfile, bytes):
163160 fid = open(outfile, 'wb')
164161 else:
165162 fid = outfile
337334 iframe = (
338335 '<div style="width:{width};">'
339336 '<div style="position:relative;width:100%;height:0;padding-bottom:{ratio};">' # noqa
337 '<span style="color:#565656">Make this Notebook Trusted to load map: File -> Trust Notebook</span>' # noqa
340338 '<iframe src="about:blank" style="position:absolute;width:100%;height:100%;left:0;top:0;' # noqa
341339 'border:none !important;" '
342340 'data-html={html} onload="{onload}" '
558556 self.width = str(60*figsize[0])+'px'
559557 self.height = str(60*figsize[1])+'px'
560558
561 if isinstance(html, text_type) or isinstance(html, binary_type):
559 if isinstance(html, str) or isinstance(html, bytes):
562560 self.add_child(Element(html))
563561 elif html is not None:
564562 self.add_child(html)
0 # -*- coding: utf-8 -*-
10 """
21 Utilities
32 -------
54 Utility module for Folium helper functions.
65
76 """
8
9 from __future__ import absolute_import, division, print_function
107
118 import base64
129 import json
1613 import zlib
1714
1815 from jinja2 import Environment, PackageLoader
19
20
21 from six import binary_type, text_type
2216
2317 try:
2418 import pandas as pd
243237 fileformat = 'png'
244238 url = 'data:image/{};base64,{}'.format(
245239 fileformat, base64.b64encode(image.read()).decode('utf-8'))
246 elif (not (isinstance(image, text_type) or
247 isinstance(image, binary_type))) and hasattr(image, '__iter__'):
240 elif (not (isinstance(image, str) or
241 isinstance(image, bytes))) and hasattr(image, '__iter__'):
248242 # We got an array-like object.
249243 png = write_png(image, origin=origin, colormap=colormap)
250244 url = 'data:image/png;base64,' + base64.b64encode(png).decode('utf-8')
2323 author = 'Filipe Fernandes'
2424
2525 from branca._version import get_versions
26
2627 version = release = get_versions()['version']
2728 del get_versions
2829
177178 epub_exclude_files = ['search.html']
178179
179180
180 # -- Extension configuration -------------------------------------------------
181 # -- Extension configuration -------------------------------------------------
0 black
01 check-manifest
12 flake8
23 flake8-builtins
34 flake8-comprehensions
4 flake8-import-order
55 flake8-mutable
66 flake8-print
7 isort
8 jupyter
79 nbsphinx
810 pylint
911 pytest
00 jinja2
1 six
00 import os
1 import sys
21
32 from setuptools import setup
43
2120 data_files.append(os.path.join(sub_dir, f))
2221 return data_files
2322
24
25 if sys.version_info < (3, 5):
26 error = """
27 branca 0.4+ supports Python 3.5 and above.
28 When using Python 2.7, please install branca 0.3.*.
29
30 See branca `README.rst` file for more information:
31
32 https://github.com/python-visualization/branca/blob/master/README.rst
33
34 Python {py} detected.
35
36 Try upgrading pip and retry.
37 """.format(
38 py=".".join([str(v) for v in sys.version_info[:3]])
39 )
40 print(error, file=sys.stderr) # noqa
41 sys.exit(1)
4223
4324 pkg_data = {
4425 "": [
7354 url="https://github.com/python-visualization/branca",
7455 keywords="data visualization",
7556 classifiers=[
57 "Programming Language :: Python :: 3",
7658 "Programming Language :: Python :: 3.5",
7759 "Programming Language :: Python :: 3.6",
7860 "Programming Language :: Python :: 3.7",
61 "Programming Language :: Python :: 3.8",
7962 "License :: OSI Approved :: MIT License",
8063 "Development Status :: 5 - Production/Stable",
8164 ],
44 ----------------------
55 """
66
7 import branca.element as elem
8
97 import pytest
10
118 from selenium.webdriver import Firefox
129 from selenium.webdriver.firefox.options import Options
10
11 import branca.element as elem
1312
1413
1514 def test_create_empty_iframe():
0 # -*- coding: utf-8 -*-
10 """
21 Branca Notebooks Tests
32 ----------------------
65 """
76
87 import os
9 import sys
8
9 import nbconvert
1010
1111 import branca.utilities
1212
13 if sys.version_info[:2] == (3, 4):
14 import nbconvert
13 rootpath = os.path.abspath(os.path.dirname(__file__))
1514
16 rootpath = os.path.abspath(os.path.dirname(__file__))
1715
18 class NotebookTester(object):
19 def __init__(self, filename):
20 self.filename = filename
16 class NotebookTester(object):
17 def __init__(self, filename):
18 self.filename = filename
2119
22 def __call__(self, exporter=None, filename=None):
23 raw_nb = nbconvert.exporters.Exporter().from_filename(self.filename)
24 raw_nb[0].metadata.setdefault('kernelspec', {})['name'] = 'python'
25 exec_nb = nbconvert.preprocessors.ExecutePreprocessor().preprocess(*raw_nb)
20 def __call__(self, exporter=None, filename=None):
21 raw_nb = nbconvert.exporters.Exporter().from_filename(self.filename)
22 raw_nb[0].metadata.setdefault('kernelspec', {})['name'] = 'python'
23 exec_nb = nbconvert.preprocessors.ExecutePreprocessor().preprocess(*raw_nb)
2624
27 if exporter is not None:
28 out_nb = nbconvert.exporters.MarkdownExporter().from_notebook_node(*exec_nb)
29 if filename is None:
30 assert self.filename.endswith('.ipynb')
31 filename = self.filename[:-6] + exporter.file_extension
32 open(filename, 'w').write(out_nb[0].encode('utf-8'))
25 if exporter is not None:
26 out_nb = nbconvert.exporters.MarkdownExporter().from_notebook_node(*exec_nb)
27 if filename is None:
28 assert self.filename.endswith('.ipynb')
29 filename = self.filename[:-6] + exporter.file_extension
30 open(filename, 'w').write(out_nb[0].encode('utf-8'))
3331
34 class TestNotebooks(object):
35 _filepath = rootpath.rstrip('/')+'/../examples/'
36 _nblist = [x for x in os.listdir(_filepath) if x.endswith('.ipynb')]
3732
38 for fn in TestNotebooks._nblist:
39 setattr(
40 TestNotebooks,
41 'test_'+branca.utilities._camelify(fn[:-6]),
42 NotebookTester(TestNotebooks._filepath+fn).__call__
43 )
33 class TestNotebooks(object):
34 _filepath = rootpath.rstrip('/')+'/../examples/'
35 _nblist = [x for x in os.listdir(_filepath) if x.endswith('.ipynb')]
36
37
38 for fn in TestNotebooks._nblist:
39 setattr(
40 TestNotebooks,
41 'test_'+branca.utilities._camelify(fn[:-6]),
42 NotebookTester(TestNotebooks._filepath+fn).__call__
43 )