Giter VIP home page Giter VIP logo

Comments (11)

nyssance avatar nyssance commented on June 21, 2024 1

那就算了,为了这个极小众需求特地再去用复杂方式处理不值得,等哪天只支持3.10+再解决就行了。

from pyecharts.

sunhailin-Leo avatar sunhailin-Leo commented on June 21, 2024

@nyssance

  • 基于什么场景会存在这个问题?

from pyecharts.

nyssance avatar nyssance commented on June 21, 2024

@nyssance

  • 基于什么场景会存在这个问题?

双系统用户,生成的文件需要保存,mac下生成的文件是LF,windows下生成的是CRLF,内容没改动,但是git就不一样了。一般的写文件,输出前可以自己把output处理一遍再输出,但pyecharts的render是封装了。所以没法自己前置操作,要改成LF还要去生成后遍历已经生成的文件改。pandas/jinja会留个配置或者参数让用户自己改一下。

from pyecharts.

sunhailin-Leo avatar sunhailin-Leo commented on June 21, 2024

@nyssance

  • 基于什么场景会存在这个问题?

双系统用户,生成的文件需要保存,mac下生成的文件是LF,windows下生成的是CRLF,内容没改动,但是git就不一样了。一般的写文件,输出前可以自己把output处理一遍再输出,但pyecharts的render是封装了。所以没法自己前置操作,要改成LF还要去生成后遍历已经生成的文件改。pandas/jinja会留个配置或者参数让用户自己改一下。

  • git 也是必须统一用一种的,切换系统势必会影响到格式。
  • 你说 jinja 留的配置指的是这个嘛?https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.Environment
    • 如果你说的是 jinja2.Environment 的话,目前 pyecharts 所有 render api 都有一个 env 参数用来传递 jinja2.Environment 的配置哈~

from pyecharts.

nyssance avatar nyssance commented on June 21, 2024

@nyssance

  • 基于什么场景会存在这个问题?

双系统用户,生成的文件需要保存,mac下生成的文件是LF,windows下生成的是CRLF,内容没改动,但是git就不一样了。一般的写文件,输出前可以自己把output处理一遍再输出,但pyecharts的render是封装了。所以没法自己前置操作,要改成LF还要去生成后遍历已经生成的文件改。pandas/jinja会留个配置或者参数让用户自己改一下。

  • git 也是必须统一用一种的,切换系统势必会影响到格式。

  • 你说 jinja 留的配置指的是这个嘛?https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.Environment

    • 如果你说的是 jinja2.Environment 的话,目前 pyecharts 所有 render api 都有一个 env 参数用来传递 jinja2.Environment 的配置哈~

是的我git用的是统一的,jinja它是这样的

template = env.get_template(template_name)
output = template.render(data=data)

jinja的env里面它不管LF还是CRLF,它只能控制utf8(这个也影响双平台,windows下默认不是utf8),但是它的output写入文件的时候,我用pathlib的Pathpath.write_text(output, newline="\n"),python给我一个机会去自己处理。
pyecharts的语法如果能类似 chart.render(f"../{html}", newline="\n"),也这样留个参数就能处理了。目前就是同样代码mac和windows下用生成的行尾不同。
pandas是这么处理的df.to_csv(path, index=False, lineterminator="\n"),把数据写入csv文件,直接提供一个参数,来保证双平台输出的统一。

from pyecharts.

sunhailin-Leo avatar sunhailin-Leo commented on June 21, 2024

@nyssance

  • 这个需求比较罕见,我们得考虑一下~
  • 另外,按你的说法,如果要在项目兼容 mac/linux 和 windows 的话,是不是得输出两种换行模式的文件?这样反而会让开发者感到疑惑吧?
  • 如果在多人协作中用 git 模式来开发或者编辑器统一换行模式,这种问题应该不会存在的。

from pyecharts.

nyssance avatar nyssance commented on June 21, 2024

@nyssance

  • 这个需求比较罕见,我们得考虑一下~
  • 另外,按你的说法,如果要在项目兼容 mac/linux 和 windows 的话,是不是得输出两种换行模式的文件?这样反而会让开发者感到疑惑吧?
  • 如果在多人协作中用 git 模式来开发或者编辑器统一换行模式,这种问题应该不会存在的。

有了参数才能保证输出一种,自己在代码里指定是\n还是\r\n。现在不处理,同样的代码在mac和windows下运行,会render出不同的文件,是两种。这也是为什么pandas和python官方的write_text都会留一个参数的原因。

from pyecharts.

nyssance avatar nyssance commented on June 21, 2024

具体来说,因为pyecharts已经是python3.6+了,所以把engine.py里的这段

def write_utf8_html_file(file_name: str, html_content: str):
    with open(file_name, "w+", encoding="utf-8") as html_file:
        html_file.write(html_content)

改成

from pathlib import Path

def write_utf8_html_file(file_name: str, html_content: str, newline: str | None = None):
    Path(file_name).write_text(html_content, encoding="utf-8", newline=newline)

然后把newline向上一层层都留出来就可以。用户不填,保持现在的默认行为,mac/windows不同行尾。用户填了,就指定。

from pyecharts.

sunhailin-Leo avatar sunhailin-Leo commented on June 21, 2024

具体来说,因为pyecharts已经是python3.6+了,所以把engine.py里的这段

def write_utf8_html_file(file_name: str, html_content: str):
    with open(file_name, "w+", encoding="utf-8") as html_file:
        html_file.write(html_content)

改成

from pathlib import Path

def write_utf8_html_file(file_name: str, html_content: str, newline: str | None = None):
    Path(file_name).write_text(html_content, encoding="utf-8", newline=newline)

然后把newline向上一层层都留出来就可以。用户不填,保持现在的默认行为,mac/windows不同行尾。用户填了,就指定。

from pyecharts.

sunhailin-Leo avatar sunhailin-Leo commented on June 21, 2024

@nyssance

  • 你的这个需求有个办法可以解决了。
  • 大概构造像这样子。open(file_name, "w+", encoding="utf-8", newline=os.linesep) 然后我这边做一个全局变量,类似 CurrentConfig 的设置,默认取值按照 os.linesep 来就可以了~

from pyecharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.