New upstream version 0.4.1
Georges Khaznadar
4 years ago
57 | 57 | |
58 | 58 | script: |
59 | 59 | - if [[ $TRAVIS_JOB_NAME == python-* ]]; then |
60 | cp -r tests/ /tmp ; | |
60 | cp -r tests/ examples/ /tmp ; | |
61 | 61 | pushd /tmp && pytest -n 2 -rxs --cov=branca -vv tests && popd ; |
62 | 62 | fi |
63 | 63 |
0 | 0.4.1 | |
1 | ~~~~~ | |
2 | - Prompt Jupyter users to trust notebook (@conengmo #75) | |
3 | - Removed Python 2 specific code (@ocefpaf #69) | |
4 | ||
0 | 5 | 0.4.0 |
1 | 6 | ~~~~~ |
2 | 7 | - Dropped Python 2 support |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | from __future__ import absolute_import | |
3 | ||
4 | import sys | |
5 | ||
6 | 0 | import branca.colormap as colormap |
7 | 1 | import branca.element as element |
8 | 2 | |
9 | 3 | from ._version import get_versions |
4 | ||
10 | 5 | __version__ = get_versions()['version'] |
11 | 6 | 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 | |
32 | 7 | |
33 | 8 | |
34 | 9 | __all__ = [ |
22 | 22 | # setup.py/versioneer.py will grep for the variable names, so they must |
23 | 23 | # each be defined on a line of their own. _version.py will just call |
24 | 24 | # 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" | |
28 | 28 | keywords = {"refnames": git_refnames, "full": git_full, "date": git_date} |
29 | 29 | return keywords |
30 | 30 |
5 | 5 | |
6 | 6 | """ |
7 | 7 | |
8 | from __future__ import absolute_import | |
9 | ||
10 | 8 | import json |
11 | 9 | import math |
12 | 10 | import os |
13 | 11 | |
12 | from jinja2 import Template | |
13 | ||
14 | 14 | from branca.element import ENV, Figure, JavascriptLink, MacroElement |
15 | 15 | from branca.utilities import legend_scaler |
16 | ||
17 | from jinja2 import Template | |
18 | ||
19 | from six import binary_type, text_type | |
20 | ||
21 | 16 | |
22 | 17 | rootpath = os.path.abspath(os.path.dirname(__file__)) |
23 | 18 | |
41 | 36 | def _parse_color(x): |
42 | 37 | if isinstance(x, (tuple, list)): |
43 | 38 | 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): | |
45 | 40 | color_tuple = _parse_hex(x) |
46 | elif isinstance(x, (text_type, binary_type)): | |
41 | elif isinstance(x, (str, bytes)): | |
47 | 42 | cname = _cnames.get(x.lower(), None) |
48 | 43 | if cname is None: |
49 | 44 | raise ValueError('Unknown color {!r}.'.format(cname)) |
9 | 9 | import json |
10 | 10 | import warnings |
11 | 11 | from collections import OrderedDict |
12 | from urllib.request import urlopen | |
12 | 13 | from uuid import uuid4 |
13 | 14 | |
14 | 15 | from jinja2 import Environment, PackageLoader, Template |
15 | 16 | |
16 | from six import binary_type, text_type | |
17 | from six.moves.urllib.request import urlopen | |
18 | ||
19 | 17 | from .utilities import _camelify, _parse_size, none_max, none_min |
20 | ||
21 | 18 | |
22 | 19 | ENV = Environment(loader=PackageLoader('branca', 'templates')) |
23 | 20 | |
159 | 156 | close_file : bool, default True |
160 | 157 | Whether the file has to be closed after write. |
161 | 158 | """ |
162 | if isinstance(outfile, text_type) or isinstance(outfile, binary_type): | |
159 | if isinstance(outfile, str) or isinstance(outfile, bytes): | |
163 | 160 | fid = open(outfile, 'wb') |
164 | 161 | else: |
165 | 162 | fid = outfile |
337 | 334 | iframe = ( |
338 | 335 | '<div style="width:{width};">' |
339 | 336 | '<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 | |
340 | 338 | '<iframe src="about:blank" style="position:absolute;width:100%;height:100%;left:0;top:0;' # noqa |
341 | 339 | 'border:none !important;" ' |
342 | 340 | 'data-html={html} onload="{onload}" ' |
558 | 556 | self.width = str(60*figsize[0])+'px' |
559 | 557 | self.height = str(60*figsize[1])+'px' |
560 | 558 | |
561 | if isinstance(html, text_type) or isinstance(html, binary_type): | |
559 | if isinstance(html, str) or isinstance(html, bytes): | |
562 | 560 | self.add_child(Element(html)) |
563 | 561 | elif html is not None: |
564 | 562 | self.add_child(html) |
0 | # -*- coding: utf-8 -*- | |
1 | 0 | """ |
2 | 1 | Utilities |
3 | 2 | ------- |
5 | 4 | Utility module for Folium helper functions. |
6 | 5 | |
7 | 6 | """ |
8 | ||
9 | from __future__ import absolute_import, division, print_function | |
10 | 7 | |
11 | 8 | import base64 |
12 | 9 | import json |
16 | 13 | import zlib |
17 | 14 | |
18 | 15 | from jinja2 import Environment, PackageLoader |
19 | ||
20 | ||
21 | from six import binary_type, text_type | |
22 | 16 | |
23 | 17 | try: |
24 | 18 | import pandas as pd |
243 | 237 | fileformat = 'png' |
244 | 238 | url = 'data:image/{};base64,{}'.format( |
245 | 239 | 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__'): | |
248 | 242 | # We got an array-like object. |
249 | 243 | png = write_png(image, origin=origin, colormap=colormap) |
250 | 244 | url = 'data:image/png;base64,' + base64.b64encode(png).decode('utf-8') |
23 | 23 | author = 'Filipe Fernandes' |
24 | 24 | |
25 | 25 | from branca._version import get_versions |
26 | ||
26 | 27 | version = release = get_versions()['version'] |
27 | 28 | del get_versions |
28 | 29 | |
177 | 178 | epub_exclude_files = ['search.html'] |
178 | 179 | |
179 | 180 | |
180 | # -- Extension configuration -------------------------------------------------⏎ | |
181 | # -- Extension configuration ------------------------------------------------- |
0 | black | |
0 | 1 | check-manifest |
1 | 2 | flake8 |
2 | 3 | flake8-builtins |
3 | 4 | flake8-comprehensions |
4 | flake8-import-order | |
5 | 5 | flake8-mutable |
6 | 6 | flake8-print |
7 | isort | |
8 | jupyter | |
7 | 9 | nbsphinx |
8 | 10 | pylint |
9 | 11 | pytest |
0 | 0 | import os |
1 | import sys | |
2 | 1 | |
3 | 2 | from setuptools import setup |
4 | 3 | |
21 | 20 | data_files.append(os.path.join(sub_dir, f)) |
22 | 21 | return data_files |
23 | 22 | |
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) | |
42 | 23 | |
43 | 24 | pkg_data = { |
44 | 25 | "": [ |
73 | 54 | url="https://github.com/python-visualization/branca", |
74 | 55 | keywords="data visualization", |
75 | 56 | classifiers=[ |
57 | "Programming Language :: Python :: 3", | |
76 | 58 | "Programming Language :: Python :: 3.5", |
77 | 59 | "Programming Language :: Python :: 3.6", |
78 | 60 | "Programming Language :: Python :: 3.7", |
61 | "Programming Language :: Python :: 3.8", | |
79 | 62 | "License :: OSI Approved :: MIT License", |
80 | 63 | "Development Status :: 5 - Production/Stable", |
81 | 64 | ], |
4 | 4 | ---------------------- |
5 | 5 | """ |
6 | 6 | |
7 | import branca.element as elem | |
8 | ||
9 | 7 | import pytest |
10 | ||
11 | 8 | from selenium.webdriver import Firefox |
12 | 9 | from selenium.webdriver.firefox.options import Options |
10 | ||
11 | import branca.element as elem | |
13 | 12 | |
14 | 13 | |
15 | 14 | def test_create_empty_iframe(): |
0 | # -*- coding: utf-8 -*- | |
1 | 0 | """ |
2 | 1 | Branca Notebooks Tests |
3 | 2 | ---------------------- |
6 | 5 | """ |
7 | 6 | |
8 | 7 | import os |
9 | import sys | |
8 | ||
9 | import nbconvert | |
10 | 10 | |
11 | 11 | import branca.utilities |
12 | 12 | |
13 | if sys.version_info[:2] == (3, 4): | |
14 | import nbconvert | |
13 | rootpath = os.path.abspath(os.path.dirname(__file__)) | |
15 | 14 | |
16 | rootpath = os.path.abspath(os.path.dirname(__file__)) | |
17 | 15 | |
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 | |
21 | 19 | |
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) | |
26 | 24 | |
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')) | |
33 | 31 | |
34 | class TestNotebooks(object): | |
35 | _filepath = rootpath.rstrip('/')+'/../examples/' | |
36 | _nblist = [x for x in os.listdir(_filepath) if x.endswith('.ipynb')] | |
37 | 32 | |
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 | ) |