Skip to content

Commit 08079f8

Browse files
committed
1.Package support
1 parent 56a90ae commit 08079f8

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed

AutoCython.py renamed to AutoCython/AutoCython.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ def __init__(self, po : Popen, py_path : str, pyd_path=None) -> None:
2727
self.PyPath = py_path
2828
self.PydPath = pyd_path
2929
if self._system == 'Windows':
30-
self.out = po.stdout.read().decode('gbk')
31-
self.err = po.stderr.read().decode('gbk')
30+
31+
self.out = po.stdout.read().decode('utf-8', errors='ignore')
32+
self.err = po.stderr.read().decode('utf-8', errors='ignore')
3233
else:
3334
# utf-8
3435
self.out = po.stdout.read().decode()
@@ -353,7 +354,7 @@ def __init__(self):
353354
self.file_path = ''
354355
self.a_file_flag = False
355356

356-
self.version = 'AutoCython V1.2.7'
357+
self.version = 'AutoCython V1.2.8'
357358
# 像这样写格式好看一点
358359
self.help_info =(
359360
"Usage: AutoCython [options] ...\n"+
@@ -422,7 +423,7 @@ def geto(self) -> Union[str, list, str, list]:
422423
if opt in ('-h', '-H','--help'):
423424
print(self.help_info + '\n' + self.version)
424425
sys.exit()
425-
elif opt in ('--ch'):
426+
elif opt in ('--ch', ):
426427
print(self.help_info_ch + '\n' + self.version)
427428
sys.exit()
428429
elif opt in ('-v', '-V','--version'):

AutoCython/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/use/bin/dev python
2+
# -*- coding: utf-8 -*-
3+
import sys
4+
from AutoCython.AutoCython import AutoCython, AC_getopt_argv
5+
6+
__version__ = "1.2.8"
7+
8+
class MyModuleCall(sys.modules[__name__].__class__):
9+
# module call
10+
def __call__(self, *args, **kwargs):
11+
return AutoCython(*args, **kwargs)
12+
13+
sys.modules[__name__].__class__ = MyModuleCall
14+
15+
def main():
16+
""" main """
17+
ac = AutoCython(*AC_getopt_argv().geto())
18+
19+
ac.compile()

README.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
**自动Cython,使用Cython批量编译.py文件为.pyd文件!**
44
![py_pyd][1]
55

6-
这是一个轮子,大多数情况下,你只需要这样就可以很快的把.py编译为.pyd!
6+
## 安装
77

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
917
AutoCython().compile()
1018

1119
![AutoCython][2]
@@ -42,7 +50,7 @@ vs安装简便,占用空间大,配置简单;gcc安装简便,占用空间
4250

4351
编译当前目录下能找到的所有py文件:
4452

45-
from AutoCython import AutoCython
53+
import AutoCython
4654
ac = AutoCython()
4755
ac.compile()
4856

@@ -70,39 +78,44 @@ AutoCython类接受4个参数,默认为:compile_path='.', exclude=[], mode='
7078

7179
**例子:**
7280

73-
编译目录 D:/python_code/ProjectPath 下的所有.py文件
81+
编译目录 `D:/python_code/ProjectPath` 下的所有 `.py` 文件
7482

75-
排除所有名为 tmp.py 的文件,排除 ./ProjectPath/print_cy.py 文件,排除 ./ProjectPath/data/tmp 目录下的文件不编译;
83+
排除所有名为 `tmp.py` 的文件,排除 `./ProjectPath/print_cy.py` 文件,排除 `./ProjectPath/data/tmp` 目录下的文件不编译;
7684

7785
使用8个CPU核心;
7886

79-
只删除编译后产生的build文件夹和中间文件setup_file,保留C代码
87+
只删除编译后产生的 `build` 文件夹和中间文件 `setup_file` ,保留 `C` 代码
8088

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+
)
8396
ac.compile()
8497

85-
AutoCython类里compile和compile_file函数的使用和函数参数请参考源代码,参数功能为控制阻塞,并发处理等。
98+
`AutoCython` 类里 `compile``compile_file` 函数的使用和函数参数请参考源代码,参数功能为控制阻塞,并发处理等。
8699

87100
### 错误处理
88101

89102
在这个目录下:
90103
![文件目录][3]
91104

92-
运行如下代码只编译目录 build_test\ 下的.py文件;
105+
运行如下代码只编译目录 `build_test\` 下的 `.py` 文件;
93106

94-
from AutoCython import AutoCython
107+
import AutoCython
95108
ac = AutoCython('./build_test/')
96109
ac.compile()
97110

98111
**程序默认会打印出错误文件的错误日志**
99112
![错误编译][4]
100113

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`
103116
![compile_result][5]
104117

105-
再按TAB,好了,这时候所有的编译任务都调出来了,错误的任务名称以 **ERR_** 开头,正确的以 **OK_** 开头:
118+
再按 `TAB`,好了,这时候所有的编译任务都调出来了,错误的任务名称以 **ERR_** 开头,正确的以 **OK_** 开头:
106119
![错误任务][6]
107120

108121
选择编号为**2**,错误文件名为test2的任务:
@@ -131,12 +144,7 @@ AutoCython类里compile和compile_file函数的使用和函数参数请参考源
131144

132145
与上面功能一样的命令行写法:
133146

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
140148

141149
![命令行][11]
142150

setup.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
from setuptools import setup
4+
5+
with open("README.md", "r", encoding="utf-8") as fd:
6+
long_description = fd.read()
7+
8+
setup(
9+
name = 'AutoCython',
10+
version = '1.2.8',
11+
author = 'jianjun',
12+
author_email = '[email protected]',
13+
url = 'https://github.com/EVA-JianJun/AutoCython',
14+
description = u'自动Cython,使用Cython批量编译.py文件为.pyd文件!',
15+
long_description = long_description,
16+
long_description_content_type = "text/markdown",
17+
packages = ["AutoCython"],
18+
install_requires = [],
19+
entry_points={
20+
'console_scripts': [
21+
'AutoCython=AutoCython:main'
22+
],
23+
},
24+
)

0 commit comments

Comments
 (0)