|
3 | 3 | **自动Cython,使用Cython批量编译.py文件为.pyd文件!**
|
4 | 4 | ![py_pyd][1]
|
5 | 5 |
|
6 |
| -这是一个轮子,大多数情况下,你只需要这样就可以很快的把.py编译为.pyd! |
| 6 | +## 安装 |
7 | 7 |
|
8 |
| - from AutoCython import AutoCython |
| 8 | +从 **[releases][9]** 中下载 AutoCython-1.2.8-py3-none-any.whl 后使用 pip 安装. |
| 9 | + |
| 10 | + pip install AutoCython-1.2.8-py3-none-any.whl |
| 11 | + |
| 12 | +## 使用 |
| 13 | + |
| 14 | +这是一个轮子,大多数情况下,你只需要这样就可以很快的把 `.py` 编译为 `.pyd` ! |
| 15 | + |
| 16 | + import AutoCython |
9 | 17 | AutoCython().compile()
|
10 | 18 |
|
11 | 19 | ![AutoCython][2]
|
@@ -42,7 +50,7 @@ vs安装简便,占用空间大,配置简单;gcc安装简便,占用空间
|
42 | 50 |
|
43 | 51 | 编译当前目录下能找到的所有py文件:
|
44 | 52 |
|
45 |
| - from AutoCython import AutoCython |
| 53 | + import AutoCython |
46 | 54 | ac = AutoCython()
|
47 | 55 | ac.compile()
|
48 | 56 |
|
@@ -70,39 +78,44 @@ AutoCython类接受4个参数,默认为:compile_path='.', exclude=[], mode='
|
70 | 78 |
|
71 | 79 | **例子:**
|
72 | 80 |
|
73 |
| -编译目录 D:/python_code/ProjectPath 下的所有.py文件; |
| 81 | +编译目录 `D:/python_code/ProjectPath` 下的所有 `.py` 文件; |
74 | 82 |
|
75 |
| -排除所有名为 tmp.py 的文件,排除 ./ProjectPath/print_cy.py 文件,排除 ./ProjectPath/data/tmp 目录下的文件不编译; |
| 83 | +排除所有名为 `tmp.py` 的文件,排除 `./ProjectPath/print_cy.py` 文件,排除 `./ProjectPath/data/tmp` 目录下的文件不编译; |
76 | 84 |
|
77 | 85 | 使用8个CPU核心;
|
78 | 86 |
|
79 |
| -只删除编译后产生的build文件夹和中间文件setup_file,保留C代码。 |
| 87 | +只删除编译后产生的 `build` 文件夹和中间文件 `setup_file` ,保留 `C` 代码。 |
80 | 88 |
|
81 |
| - from AutoCython import AutoCython |
82 |
| - ac = AutoCython(compile_path='D:/python_code/ProjectPath', exclude=['tmp.py','./ProjectPath/print_cy.py','./ProjectPath/data/tmp'], mode='8', delete=['b', 'p']) |
| 89 | + import AutoCython |
| 90 | + ac = AutoCython( |
| 91 | + compile_path='D:/python_code/ProjectPath', |
| 92 | + exclude=['tmp.py','./ProjectPath/print_cy.py','./ProjectPath/data/tmp'], |
| 93 | + mode='8', |
| 94 | + delete=['b', 'p'] |
| 95 | + ) |
83 | 96 | ac.compile()
|
84 | 97 |
|
85 |
| -AutoCython类里compile和compile_file函数的使用和函数参数请参考源代码,参数功能为控制阻塞,并发处理等。 |
| 98 | +`AutoCython` 类里 `compile` 和 `compile_file` 函数的使用和函数参数请参考源代码,参数功能为控制阻塞,并发处理等。 |
86 | 99 |
|
87 | 100 | ### 错误处理
|
88 | 101 |
|
89 | 102 | 在这个目录下:
|
90 | 103 | ![文件目录][3]
|
91 | 104 |
|
92 |
| -运行如下代码只编译目录 build_test\ 下的.py文件; |
| 105 | +运行如下代码只编译目录 `build_test\` 下的 `.py` 文件; |
93 | 106 |
|
94 |
| - from AutoCython import AutoCython |
| 107 | + import AutoCython |
95 | 108 | ac = AutoCython('./build_test/')
|
96 | 109 | ac.compile()
|
97 | 110 |
|
98 | 111 | **程序默认会打印出错误文件的错误日志**
|
99 | 112 | ![错误编译][4]
|
100 | 113 |
|
101 |
| -可以看到 .\build_test\新建文本文档.py 和 .\build_test\test1\test2.py 发生错误,如何手动查看错误信息? |
102 |
| -在ipython下直接打.ac按TAB,选择 **compile_result**: |
| 114 | +可以看到 `.\build_test\新建文本文档.py` 和 `.\build_test\test1\test2.py` 发生错误,如何手动查看错误信息? |
| 115 | +在`ipython`下直接打`.ac`按`TAB`,选择 `compile_result`: |
103 | 116 | ![compile_result][5]
|
104 | 117 |
|
105 |
| -再按TAB,好了,这时候所有的编译任务都调出来了,错误的任务名称以 **ERR_** 开头,正确的以 **OK_** 开头: |
| 118 | +再按 `TAB`,好了,这时候所有的编译任务都调出来了,错误的任务名称以 **ERR_** 开头,正确的以 **OK_** 开头: |
106 | 119 | ![错误任务][6]
|
107 | 120 |
|
108 | 121 | 选择编号为**2**,错误文件名为test2的任务:
|
@@ -131,12 +144,7 @@ AutoCython类里compile和compile_file函数的使用和函数参数请参考源
|
131 | 144 |
|
132 | 145 | 与上面功能一样的命令行写法:
|
133 | 146 |
|
134 |
| - python AutoCython.py -C D:/python_code/ProjectPath -E tmp.py;./ProjectPath/print_cy.py;./ProjectPath/data/tmp -M 8 -D bp |
135 |
| -**强烈推荐使用EXE命令行,比较方便** |
136 |
| - |
137 |
| -除了AutoCython.py外我在 **[releases][9]** 中也提供了exe程序可以直接在win下使用: |
138 |
| - |
139 |
| - AutoCython build_test |
| 147 | + AutoCython -C D:/python_code/ProjectPath -E tmp.py;./ProjectPath/print_cy.py;./ProjectPath/data/tmp -M 8 -D bp |
140 | 148 |
|
141 | 149 | ![命令行][11]
|
142 | 150 |
|
|
0 commit comments