Grumpy: Go running Python, python 很得 “人和”,对,说的是 CPython2.7

2017-01-05 07:31:30 +08:00
 Gem
目标:

Grumpy is a Python to Go source code transcompiler and runtime that is intended to be a near drop in replacement for CPython 2.7.



原理: python sc -> | Grumpy | -> go sc -> native

The key difference is that it compiles Python source code to Go source code which is then compiled to native code, rather than to bytecode. This means that Grumpy has no VM. The compiled Go source code is a series of calls to the Grumpy runtime, a Go library serving a similar purpose to the Python C API (although the C API is not directly supported).



关于库:

Python 标准库和 Grumpy 库分为两部分,具体看下面

Python 标准库 : Much of the Python standard library is written in Python and so it "just works" in Grumpy. These parts of the standard library are copied from CPython 2.7 (possibly with light modifications). For licensing reasons, these files are kept in the third_party/stdlib subdir.

The parts of the standard library that cannot be written in pure Python, e.g. file and directory operations, are kept in the lib subdir. In CPython these kinds of modules are written as C extensions. In Grumpy they are written in Python but they use native Go extensions to access facilities not otherwise available in Python.


关于Python3

看样子,貌似是后续可能会支持,或者单独fork一个python3的版本。


仓库地址:
https://github.com/google/grumpy
3927 次点击
所在节点    Python
30 条回复
j5shi
2017-01-05 07:35:31 +08:00
所以相当于一个编译器而不是解释器?
loading
2017-01-05 07:38:20 +08:00
但是我用了 flask ,能搞定?
wweir
2017-01-05 07:41:15 +08:00
@j5shi 源码翻译工具。

Python 在运维等几个场景很有优势,
go 在效率和部署方面有很大优势,
这二者结合,感觉有戏。

不爽的是 Google 弃坑的习俗……
j5shi
2017-01-05 07:45:32 +08:00
@wweir 我知道是源码翻译工具,但最终翻译成了 native code ,所以是二进制机器码?如果是,那就成了编译器了,速度应该会有显著提升
wweir
2017-01-05 08:11:49 +08:00
@j5shi 所以你觉得是 python 的编译工具喽?
抱歉,并不是。如果是的话,又和 go 有什么关系呢
bearqq
2017-01-05 08:17:07 +08:00
看见 go 第一反应已经是围棋了→_→
试试对二进制 c 扩展的库支持
echo1937
2017-01-05 08:59:31 +08:00
也有好处,运维脚本直接往服务器上一丢就行了,不用费心环境了。

当然前提是 Google 管生又管养,毕竟这不是 Go 这种大项目。
congeec
2017-01-05 09:03:04 +08:00
那为嘛不用 Nuikta 编译到 C++呢?
janxin
2017-01-05 09:08:58 +08:00
@congeec 你还需要编译环境,尤其是版本复杂的时候
WildCat
2017-01-05 09:18:59 +08:00
这个翻译器还不如 j2objc ,完全没可读性:
https://gist.github.com/imWildCat/b1c1caaa4e6258759c7748fb36a5a744
j5shi
2017-01-05 09:28:18 +08:00
@wweir 那你觉得这玩意儿的主要目地是什么?
congeec
2017-01-05 09:31:17 +08:00
@janxin 编译成 Go 也需要编译环境啊。‘版本复杂的时候’ 是啥意思?不好意思没看懂,有点懵
est
2017-01-05 09:43:23 +08:00
坐等有人搞出个 decorator

比如:


@grumpy
def aaa():
pass
wweir
2017-01-05 09:52:05 +08:00
@j5shi 说实话,这问题我十分不乐意回复,然而,强迫症……

我的第一个回复里面讲得很清楚了
j5shi
2017-01-05 10:13:21 +08:00
@wweir 正是因为看了你的第一个回复和第二个回复,我才觉得你说的非常有问题,你说不需要编译,那我问你如果把 python 翻译成 go 而速度得到提升,你觉得是什么原因?你懂编译原理不?
kappa
2017-01-05 10:35:59 +08:00
@janxin 跟版本什么关系?
```
tools/grumpc hello.py > hello.go
go build -o hello hello.go
```
只是把 Python 源码翻译成 Go 的
j5shi
2017-01-05 10:43:35 +08:00
@kappa 其实翻译不是终极目地,终极目的是用 go 的编译器
janxin
2017-01-05 10:57:16 +08:00
@congeec
@kappa
我是说 Nuikta 编译到 C++,如果遇到系统版本 /libc 版本复杂的时候就不好玩了,这个在一个多年公司里也是比较常见的情况。
编译成 Go 可以编译一次到处运行嘛。
aljun
2017-01-05 11:17:53 +08:00
- -我本还一直想拿 golang 给 py 写个 wsgi (结果一直没时间。。。。。看来。。。可以拿这个撸撸
mathgl
2017-01-05 11:58:53 +08:00
@congeec nuitka 这玩意有人在生产环境用过不?几乎找不到什么案例。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/332296

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX