From 6caa22be41f2a33ce47da069cdc57e528d2678fb Mon Sep 17 00:00:00 2001 From: kinegratii Date: Wed, 15 Nov 2017 21:13:50 +0800 Subject: [PATCH] Update code style with maxline=79 --- pyecharts/base.py | 22 ---------------------- pyecharts/conf.py | 6 ++++-- pyecharts/constants.py | 4 ---- pyecharts/custom/page.py | 21 ++------------------- pyecharts/engine.py | 17 +++++++++++------ pyecharts/template.py | 6 ++---- test/test_conf.py | 27 ++++++++++++++++++--------- test/test_custom_render.py | 5 ++++- test/test_template_function.py | 9 ++++++--- 9 files changed, 47 insertions(+), 70 deletions(-) diff --git a/pyecharts/base.py b/pyecharts/base.py index d7a6bcb2..18002198 100644 --- a/pyecharts/base.py +++ b/pyecharts/base.py @@ -94,28 +94,6 @@ class Base(object): html = tpl.render(**context) utils.write_utf8_html_file(path, html) - # - # def _render(self, path="render.html"): - # """ 渲染配置项并生成 html 文件 - # - # :param path: - # 文件保存路径 - # """ - # _tmp = "local.html" - # my_option = utils.json_dumps(self._option, indent=4) - # default_engine = template.create_buildin_template_engine() - # tmp = default_engine.get_template(_tmp) - # script_list = template.produce_html_script_list(self._js_dependencies) - # html = tmp.render( - # my_option=my_option, - # chart_id=self._chart_id, - # script_list=script_list, - # page_title=self._page_title, - # my_width=self.width, - # my_height=self.height) - # html = utils.freeze_js(html) - # utils.write_utf8_html_file(path, html) - @staticmethod def cast(seq): """ 转换数据序列,将带字典和元组类型的序列转换为 k_lst,v_lst 两个列表 diff --git a/pyecharts/conf.py b/pyecharts/conf.py index a38654dd..2c86add6 100644 --- a/pyecharts/conf.py +++ b/pyecharts/conf.py @@ -2,11 +2,13 @@ # coding=utf-8 from __future__ import unicode_literals -from pyecharts.constants import SCRIPT_LOCAL_JSHOST, JUPYTER_LOCAL_JSHOST, DEFAULT_HOST +from pyecharts.constants import SCRIPT_LOCAL_JSHOST, JUPYTER_LOCAL_JSHOST, \ + DEFAULT_HOST class PyEchartsConfig(object): - def __init__(self, echarts_template_dir='.', jshost=None, force_js_embed=False): + def __init__(self, echarts_template_dir='.', jshost=None, + force_js_embed=False): self.echarts_template_dir = echarts_template_dir jshost = jshost or SCRIPT_LOCAL_JSHOST self._jshost = PyEchartsConfig.convert_jshost_string(jshost) diff --git a/pyecharts/constants.py b/pyecharts/constants.py index 6582b954..5efe031c 100644 --- a/pyecharts/constants.py +++ b/pyecharts/constants.py @@ -17,10 +17,6 @@ JUPYTER_LOCAL_JSHOST = '/nbextensions/echarts' DEFAULT_TEMPLATE_DIR = get_resource_dir('templates') -# CONFIGURATION = dict( -# HOST=JUPYTER_LOCAL_JSHOST # TODO Delete this key from the dictionary -# ) - # Load js & map file index into a dictionary. DEFAULT_ECHARTS_REGISTRY = os.path.join( diff --git a/pyecharts/custom/page.py b/pyecharts/custom/page.py index 5fe7fb7e..126b32d0 100644 --- a/pyecharts/custom/page.py +++ b/pyecharts/custom/page.py @@ -32,30 +32,13 @@ class Page(list): template_name='simple_page.html', object_name='page', extra_context=None): - tpl = template.create_buildin_template_engine().get_template(template_name) + tpl = template.create_buildin_template_engine().get_template( + template_name) context = {object_name: self} context.update(extra_context or {}) html = tpl.render(**context) utils.write_utf8_html_file(path, html) - # def _render(self, path="render.html"): - # """ - # Produce rendered charts in a html file - # - # :param path: - # :return: - # """ - # template_name = "multicharts.html" - # chart_content = self.render_embed() - # dependencies = self._merge_dependencies() - # script_list = template.produce_html_script_list(dependencies) - # tmp = template.create_buildin_template_engine().get_template(template_name) - # html = tmp.render(multi_chart_content=chart_content, - # page_title=self._page_title, - # script_list=script_list) - # html = utils.freeze_js(html) - # utils.write_utf8_html_file(path, html) - def render_embed(self): """ Produce rendered charts in html for embedding purpose diff --git a/pyecharts/engine.py b/pyecharts/engine.py index c978a122..3e925817 100644 --- a/pyecharts/engine.py +++ b/pyecharts/engine.py @@ -58,11 +58,13 @@ def echarts_js_dependencies(env, *args): if current_config.js_embed: contents = Helpers.read_file_contents_from_local(js_names) - return '\n'.join([''.format(c) for c in contents]) + embed_script_tpl_str = '' + return '\n'.join([embed_script_tpl_str.format(c) for c in contents]) else: jshost = current_config.jshost js_links = Helpers.generate_js_link(jshost, js_names) - return '\n'.join([''.format(j) for j in js_links]) + link_script_tpl_str = '' + return '\n'.join([link_script_tpl_str.format(j) for j in js_links]) @environmentfunction @@ -76,7 +78,8 @@ def echarts_js_dependencies_embed(env, *args): dependencies = Helpers.merge_js_dependencies(*args) js_names = [constants.DEFAULT_JS_LIBRARIES.get(x, x) for x in dependencies] contents = Helpers.read_file_contents_from_local(js_names) - return '\n'.join([''.format(c) for c in contents]) + embed_script_tpl_str = '' + return '\n'.join([embed_script_tpl_str.format(c) for c in contents]) @environmentfunction @@ -90,7 +93,7 @@ def echarts_container(env, chart): def ex_wh(x): """ - Extend width/height to all values.See http://www.w3school.com.cn/cssref/pr_dim_width.asp + Extend width/height to all values. :param x: :return: """ @@ -136,7 +139,8 @@ def echarts_js_content(env, *charts): :param chart: :return: """ - return ''.format(generate_js_content(*charts)) + return ''.format( + generate_js_content(*charts)) @environmentfunction @@ -159,7 +163,8 @@ class EchartsEnvironment(Environment): self._pyecharts_config = pyecharts_config or PyEchartsConfig() loader = kwargs.pop('loader', None) if loader is None: - loader = FileSystemLoader(self._pyecharts_config.echarts_template_dir) + loader = FileSystemLoader( + self._pyecharts_config.echarts_template_dir) super(EchartsEnvironment, self).__init__( keep_trailing_newline=True, trim_blocks=True, diff --git a/pyecharts/template.py b/pyecharts/template.py index c606e909..9416e655 100644 --- a/pyecharts/template.py +++ b/pyecharts/template.py @@ -2,8 +2,6 @@ # coding=utf-8 from __future__ import unicode_literals -import warnings - from jinja2 import FileSystemLoader import pyecharts.constants as constants @@ -37,14 +35,14 @@ def configure( def online(host=constants.DEFAULT_HOST): - warnings.warn('The online will be deprecated,use "pyecharts.configure" instead.', DeprecationWarning) CURRENT_CONFIG.jshost = host def create_buildin_template_engine(): return EchartsEnvironment( pyecharts_config=CURRENT_CONFIG, - loader=FileSystemLoader([CURRENT_CONFIG.echarts_template_dir, DEFAULT_TEMPLATE_DIR]) + loader=FileSystemLoader( + [CURRENT_CONFIG.echarts_template_dir, DEFAULT_TEMPLATE_DIR]) ) diff --git a/test/test_conf.py b/test/test_conf.py index 36e201b8..2d8789d8 100644 --- a/test/test_conf.py +++ b/test/test_conf.py @@ -9,7 +9,8 @@ from __future__ import unicode_literals from nose.tools import eq_ from pyecharts.conf import PyEchartsConfig -from pyecharts.constants import DEFAULT_HOST, SCRIPT_LOCAL_JSHOST, JUPYTER_LOCAL_JSHOST +from pyecharts.constants import DEFAULT_HOST, SCRIPT_LOCAL_JSHOST, \ + JUPYTER_LOCAL_JSHOST def test_with_default_value(): @@ -28,9 +29,12 @@ def test_with_default_value(): def test_pyecharts_remote_jshost(): target_config = PyEchartsConfig(jshost=DEFAULT_HOST) eq_('https://chfw.github.io/jupyter-echarts/echarts', target_config.jshost) - eq_('https://chfw.github.io/jupyter-echarts/echarts', target_config.get_current_jshost_for_script()) - eq_('https://chfw.github.io/jupyter-echarts/echarts', target_config.get_current_jshost_for_jupyter()) - eq_('/static/js/echarts', target_config.get_current_jshost_for_jupyter('/static/js/echarts')) + eq_('https://chfw.github.io/jupyter-echarts/echarts', + target_config.get_current_jshost_for_script()) + eq_('https://chfw.github.io/jupyter-echarts/echarts', + target_config.get_current_jshost_for_jupyter()) + eq_('/static/js/echarts', + target_config.get_current_jshost_for_jupyter('/static/js/echarts')) assert target_config.js_embed @@ -44,7 +48,8 @@ def test_custom_local_jshost(): eq_('/static/js', target_config.jshost) eq_('/static/js', target_config.get_current_jshost_for_script()) eq_('/static/js', target_config.get_current_jshost_for_jupyter()) - eq_('/static/js/echarts', target_config.get_current_jshost_for_jupyter('/static/js/echarts')) + eq_('/static/js/echarts', + target_config.get_current_jshost_for_jupyter('/static/js/echarts')) assert not target_config.js_embed @@ -54,11 +59,15 @@ def test_custom_local_jshost(): def test_custom_remote_jshost(): - target_config = PyEchartsConfig(jshost='https://cdn.bootcss.com/echarts/3.7.2/') + target_config = PyEchartsConfig( + jshost='https://cdn.bootcss.com/echarts/3.7.2/') eq_('https://cdn.bootcss.com/echarts/3.7.2', target_config.jshost) - eq_('https://cdn.bootcss.com/echarts/3.7.2', target_config.get_current_jshost_for_script()) - eq_('https://cdn.bootcss.com/echarts/3.7.2', target_config.get_current_jshost_for_jupyter()) - eq_('/static/js/echarts', target_config.get_current_jshost_for_jupyter('/static/js/echarts')) + eq_('https://cdn.bootcss.com/echarts/3.7.2', + target_config.get_current_jshost_for_script()) + eq_('https://cdn.bootcss.com/echarts/3.7.2', + target_config.get_current_jshost_for_jupyter()) + eq_('/static/js/echarts', + target_config.get_current_jshost_for_jupyter('/static/js/echarts')) assert not target_config.js_embed diff --git a/test/test_custom_render.py b/test/test_custom_render.py index 73f05622..a19249fd 100644 --- a/test/test_custom_render.py +++ b/test/test_custom_render.py @@ -31,7 +31,10 @@ def create_three(): def test_custom_templates(): - configure(jshost='https://chfw.github.io/jupyter-echarts/echarts', force_js_embed=False) + configure( + jshost='https://chfw.github.io/jupyter-echarts/echarts', + force_js_embed=False + ) page = create_three() # page.js_dependencies = ['echarts.min'] page.render(path='new_version_page.html') diff --git a/test/test_template_function.py b/test/test_template_function.py index ab6b3bce..b93e4365 100644 --- a/test/test_template_function.py +++ b/test/test_template_function.py @@ -28,14 +28,17 @@ def test_echarts_js_dependencies(): def test_echarts_js_dependencies_embed(): - ECHARTS_ENV.configure_pyecharts(jshost=get_resource_dir('templates', 'js', 'echarts')) - tpl = ECHARTS_ENV.from_string('{{ echarts_js_dependencies_embed("echarts.min") }}') + ECHARTS_ENV.configure_pyecharts( + jshost=get_resource_dir('templates', 'js', 'echarts')) + tpl = ECHARTS_ENV.from_string( + '{{ echarts_js_dependencies_embed("echarts.min") }}') bar = create_demo_bar() html = tpl.render(bar=bar) assert len(html) > 0 # echarts_js_dependencies equals echarts_js_dependencies_embed when use local host. - tpl2 = ECHARTS_ENV.from_string('{{ echarts_js_dependencies("echarts.min") }}') + tpl2 = ECHARTS_ENV.from_string( + '{{ echarts_js_dependencies("echarts.min") }}') html2 = tpl2.render(bar=bar) assert len(html2) > 0 assert html == html2