交叉平台赛昂/蟒蛇编译器

Cyther的Python项目详细描述


repopythonimplementationstatus

licenseformatdownloads

traviscodacy

我们都知道cython的美丽:

  1. Writing C extensions is just as easy as Python
  2. Almost any valid Python is valid Cython, as Cython is a super-set of Python
  3. It has the readability of Python, but the speed of C
  4. Minimal effort has to be taken in order to speed up some programs by two to four orders of magnitude

然而,编译并不总是那么容易。有几个地方不使用setup.py会被绊倒。

  1. ^{tt2}$ error
  2. gcc: undefined reference to…
  3. Other errors basically referring to ^{tt3}$

Cython可能几乎和Python一样容易编写,但有时没有 接近运行python所需的轻松程度。这里 赛瑟上场了。cyther是一个跨平台的尝试 同时使用标准cython编译器和gcc来make的编译器 确保这些错误不会发生

使用方法:

cyther非常容易使用。可以从 命令行,或导入cyther并从 模块级。

from cyther import core
core('example_file.pyx')

同样可以使用:

$ cytherize example_file.pyx

如所料,可以为所有参数调用$ cytherize -h。 他们需要帮助。见下文。

几个漂亮的例子:

编译Python文件这是cyther最简单的用法

core('example_file.py')

编译cython文件,同时就地生成c文件(-l),并且仅在源文件已更新(-s)时编译
core('example_file.pyx -s -l')

运行无限循环,观察给定文件的更改,并在检测到更改时自动编译它们(-w)

core('example_file.pyx -w')

别忘了,这也可以从终端完成!

$ cytherize example_file.py
$ cytherize example_file.pyx -s -l
$ cytherize example_file.pyx -w

选项-w的命令行界面
$ cytherize example_file.pyx -w

cython -a -p -o X:\Cyther\__cythercache__\example_file.c X:\Cyther\example_file.pyx
gcc -fPIC -shared -w -O3 -ID:\Python35\include -LD:\Python35\libs -o X:\Cyther\example_file.pyd X:\Cyther\__cythercache__\example_file.c -lpython35
Compiled the file

...<iterations:1, compiles:1, errors:0, polls:12>...

Compiled the file

...<iterations:2, compiles:2, errors:0, polls:19>...


Error compiling Cython file:
------------------------------------------------------------
...

def inverse_triangular(n):
    x = (sqrt(8 * n + 1) - 1) / 2
    n = int(x)
    if x - n > 0:
        return Flse
                  ^
------------------------------------------------------------

example_file.pyx:15:19: undeclared name not builtin: Flse
Cyther will wait for you to fix this error before it tries to compile again...

...<iterations:3, compiles:2, errors:1, polls:31>...


Compiled the file

...<iterations:4, compiles:3, errors:1, polls:51>...

编译这两个文件并在使用gcc

$ cytherize example_file.pyx another_file.py -l -w -cython _l

您还可以编写类似的代码,以便在生成过程之后直接执行测试

# example_file.pyx
from math import sqrt

cdef int triangular(int n):
    cdef:
        double q
        int r
    q = (n * (n + 1)) / 2
    r = int(q)
    return r

def inverse_triangular(n):
    x = (sqrt(8 * n + 1) - 1) / 2
    n = int(x)
    if x - n > 0:
        return False
    return int(x)

'''
@Cyther
a = ''.join([str(x) for x in range(10)])
print(a)
'''

@Cyther行告诉cyther应该在 它在单引号的多行字符串中,如果生成 通过。还可以告诉cyther计时@Cyther代码,返回 一个伊普顿式的计时信息下面是一些如何使用 这些特点。

美妙的-x选项,以及输出到stdout

$ cytherize example_file.pyx -x
0123456789

选项-t也非常有用

$ cytherize example_file.pyx -t
10000 loops, best of 3: (2.94e-06) sec per loop

cytherize

的帮助文本
$ cytherize -h

usage: cytherize.py [-h] [-c] [-p PRESET] [-s] [-o OUTPUT_NAME] [-i INCLUDE]
                    [-l] [-w] [-e] [-x | -t] [-X | -T]
                    [-cython CYTHON_ARGS [CYTHON_ARGS ...]]
                    [-gcc GCC_ARGS [GCC_ARGS ...]]
                    filenames [filenames ...]

Auto compile and build .pyx or .py files in place.

positional arguments:
  filenames             The Cython source files

optional arguments:
  -h, --help            show this help message and exit
  -c, --concise         Get cyther to NOT print what it is thinking. Only use
                        if you like to live on the edge
  -p PRESET, --preset PRESET
                        The preset options for using cython and gcc (ninja,
                        beast, minimal, swift)
  -s, --timestamp       If this flag is provided, cyther will not compile
                        files that have a modifiedtime before that of your
                        compiled .pyd or .so files
  -o OUTPUT_NAME, --output_name OUTPUT_NAME
                        Change the name of the output file, default is
                        basename plus .pyd
  -i INCLUDE, --include INCLUDE
                        The names of the python modules that have an include
                        library that needs to be passed to gcc
  -l, --local           When not flagged, builds in __cythercache__, when
                        flagged, it builds locally in the same directory
  -w, --watch           When given, cyther will watch the directory with the
                        't' option implied and compile,when necessary, the
                        files given
  -e, --error           Raise a CytherError exception instead of printing out
                        stderr when -w is not specified
  -x, --execute         Run the @Cyther code in multi-line single quoted
                        strings, and comments
  -t, --timeit          Time the @Cyther code in multi-line single quoted
                        strings, and comments
  -X                    A 'super flag' that implies these flags: '-x', '-s',
                        '-p swift'
  -T                    A 'super flag' that implies these flags: '-t', '-s',
                        '-p swift'
  -cython CYTHON_ARGS [CYTHON_ARGS ...]
                        Arguments to pass to Cython
  -gcc GCC_ARGS [GCC_ARGS ...]
                        Arguments to pass to gcc

System:
        Python (D:\Python35\python.EXE):
                Version: 3.5
                Operating System: Windows-10-10.0.10586-SP0
                        OS is Windows: True
                Default Output Extension: .pyd
                Installation Directory: D:\Python35
        Cython (D:\Python35\Scripts\cython.EXE):
                Nothing Here Yet
        GCC (D:\MinGW\bin\gcc.EXE):
                Nothing Here Yet

(Use '_' or '__' instead of '-' or '--' when passing args to gcc or Cython)
(The '-x' and '-b' Boolean flags are mutually exclusive)

Cyther对你的系统的假设:

赛瑟还不是很完美,所以所有的不相容和 赛瑟的假设如下我们强烈建议 你甚至在考虑使用前都要检查一下。在附近 我希望将来能把赛瑟弄得尽可能漂亮,把名单带来 下面列出的假设为零。

  1. Cython and gcc are both installed, and accessible from the terminal
  2. Your Python version supports ^{tt17}$
  3. Your environment path variable is able to be found by ^{tt17}$
  4. ‘distutils’ is able to find the Python runtime static library (usually ^{tt19}$ or ^{tt20}$)
  5. Windows will support gcc compiled C code

嘿,你!是的,你。如果您发现任何错误或特殊之处,请报告 给我们的虫子追踪器,它会帮我们很多!

https://github.com/nickpandolfi/Cyther/issues

如果你有任何问题或担忧,甚至有任何建议,不要 不客气,请发电子邮件给我:

npandolfi@wpi.edu

编译愉快-尼克

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
多线程试图找出线程和Java   java字符串池(字符串和字符串缓冲区)   java如何通过entryid从kaltura获取文件url   java如何通过Oracle服务总线重定向请求   java RecyclerView我最多只能添加一行   java如何防止Paho在处理来自代理的消息后发送ACK?   java从泛型方法调用重载方法   java如何使javac编译我的多语言程序   java Log4j不会在删除时重新创建文件   java如何设置Zk会话(org.zkoss.Zk.ui),以便对扩展GenericForwardComposer的控制器类进行单元测试   Java:为什么可以对通配符集合进行强制转换?   java如何将数据更新到从自定义视图类创建的对象,以便可以在自定义视图上绘制数据?   java如何解决在片段中使用意图时应用程序崩溃的问题?   java如何使来自JSP的Servlet调用更安全?   java在Lucene中索引正则表达式并搜索输入   java如何设置Jetty,使其与Tomcat对等,同时支持JSP和servlet?   java在检查和使用对话框输入时遇到问题   java Git可以在签出时更改文件吗?