gl-py2pyd 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gl_py2pyd-0.1.0.dist-info → gl_py2pyd-0.2.0.dist-info}/METADATA +50 -48
- gl_py2pyd-0.2.0.dist-info/RECORD +9 -0
- {gl_py2pyd-0.1.0.dist-info → gl_py2pyd-0.2.0.dist-info}/WHEEL +1 -1
- module/fileConversion.py +58 -15
- module/single_py2pyd.py +9 -29
- py2pyd.py +100 -38
- gl_py2pyd-0.1.0.dist-info/RECORD +0 -9
- {gl_py2pyd-0.1.0.dist-info → gl_py2pyd-0.2.0.dist-info}/entry_points.txt +0 -0
- {gl_py2pyd-0.1.0.dist-info → gl_py2pyd-0.2.0.dist-info}/top_level.txt +0 -0
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gl-py2pyd
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: 将Python文件转换为pyd/so文件的工具
|
|
5
|
-
Home-page: https://github.com/
|
|
5
|
+
Home-page: https://github.com/youjunxiaji/py2pyd-arg
|
|
6
6
|
Author: gu lei
|
|
7
|
-
Author-email:
|
|
8
|
-
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.6
|
|
7
|
+
Author-email: youjunxiaji@gmail.com
|
|
8
|
+
Requires-Python: >=3.9
|
|
12
9
|
Description-Content-Type: text/markdown
|
|
13
10
|
Requires-Dist: cython
|
|
14
|
-
Requires-Dist:
|
|
11
|
+
Requires-Dist: rich
|
|
12
|
+
Requires-Dist: setuptools
|
|
15
13
|
Dynamic: author
|
|
16
|
-
Dynamic:
|
|
17
|
-
Dynamic: description
|
|
18
|
-
Dynamic: description-content-type
|
|
14
|
+
Dynamic: author-email
|
|
19
15
|
Dynamic: home-page
|
|
20
|
-
Dynamic: requires-dist
|
|
21
16
|
Dynamic: requires-python
|
|
22
|
-
Dynamic: summary
|
|
23
17
|
|
|
24
|
-
# Python转pyd/so工具
|
|
18
|
+
# py2pyd - Python转pyd/so工具
|
|
25
19
|
|
|
26
|
-
|
|
20
|
+
将Python文件(.py)转换为编译后的Python扩展模块(.pyd或.so),使用Cython进行编译。
|
|
27
21
|
|
|
28
22
|
## 功能特点
|
|
29
23
|
|
|
@@ -33,57 +27,61 @@ Dynamic: summary
|
|
|
33
27
|
- 转换后可选择是否删除原始Python文件
|
|
34
28
|
- 保留`__init__.py`文件内容处理
|
|
35
29
|
- 自动检测依赖并提供错误处理
|
|
36
|
-
- 针对不同操作系统自动选择正确的扩展名(Windows为.pyd,Linux/
|
|
37
|
-
-
|
|
30
|
+
- 针对不同操作系统自动选择正确的扩展名(Windows为.pyd,Linux/macOS为.so)
|
|
31
|
+
- 美观的进度条显示
|
|
38
32
|
|
|
39
|
-
##
|
|
40
|
-
|
|
41
|
-
在使用此工具前,请确保已安装以下依赖:
|
|
33
|
+
## 安装
|
|
42
34
|
|
|
43
35
|
```bash
|
|
44
|
-
pip install
|
|
36
|
+
pip install gl-py2pyd
|
|
45
37
|
```
|
|
46
38
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
-
|
|
39
|
+
### 系统要求
|
|
40
|
+
|
|
41
|
+
你的系统需要有合适的C/C++编译器:
|
|
42
|
+
- **Windows**: 需要安装 Visual C++ Build Tools
|
|
43
|
+
- **Linux**: 需要安装 GCC
|
|
44
|
+
- **macOS**: 需要安装 XCode 命令行工具(`xcode-select --install`)
|
|
51
45
|
|
|
52
46
|
## 使用方法
|
|
53
47
|
|
|
54
|
-
###
|
|
48
|
+
### 命令行使用
|
|
55
49
|
|
|
56
50
|
```bash
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
# 转换单个文件
|
|
52
|
+
py2pyd file.py
|
|
59
53
|
|
|
60
|
-
|
|
54
|
+
# 转换目录下所有Python文件
|
|
55
|
+
py2pyd folder/
|
|
61
56
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```
|
|
57
|
+
# 递归转换目录及其子目录中的所有Python文件
|
|
58
|
+
py2pyd -r folder/
|
|
65
59
|
|
|
66
|
-
|
|
60
|
+
# 转换后删除原始Python文件
|
|
61
|
+
py2pyd --remove file.py
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
```
|
|
63
|
+
# 组合使用
|
|
64
|
+
py2pyd -r --remove folder/
|
|
71
65
|
|
|
72
|
-
|
|
66
|
+
# 查看版本
|
|
67
|
+
py2pyd -v
|
|
73
68
|
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
# 查看帮助
|
|
70
|
+
py2pyd -h
|
|
76
71
|
```
|
|
77
72
|
|
|
78
|
-
###
|
|
73
|
+
### 输出示例
|
|
79
74
|
|
|
80
|
-
```bash
|
|
81
|
-
python py2pyd.py -r --remove path/to/your/directory
|
|
82
75
|
```
|
|
76
|
+
📄 处理文件: test.py
|
|
77
|
+
转换进度 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
|
|
83
78
|
|
|
84
|
-
|
|
79
|
+
✅ 处理完成!成功: 1 个文件
|
|
85
80
|
|
|
86
|
-
|
|
81
|
+
🎉 全部转换成功!
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 作为模块导入
|
|
87
85
|
|
|
88
86
|
```python
|
|
89
87
|
# 转换单个文件
|
|
@@ -105,8 +103,8 @@ print(f"成功:{converter.success_count} 个文件,失败:{converter.fail_
|
|
|
105
103
|
|
|
106
104
|
工具会自动检测必要的依赖并提供错误信息。常见问题包括:
|
|
107
105
|
|
|
108
|
-
1. **缺少Cython**: 运行前会检查Cython
|
|
109
|
-
2. **编译失败**:
|
|
106
|
+
1. **缺少Cython**: 运行前会检查Cython是否已安装,若未安装则会提示安装
|
|
107
|
+
2. **编译失败**: 可能是缺少编译器或者Python文件内容有问题
|
|
110
108
|
|
|
111
109
|
## 优化的编译选项
|
|
112
110
|
|
|
@@ -120,5 +118,9 @@ print(f"成功:{converter.success_count} 个文件,失败:{converter.fail_
|
|
|
120
118
|
|
|
121
119
|
- 确保已安装Cython和适当的编译器
|
|
122
120
|
- 转换后的so/pyd文件会保留在原始Python文件的相同目录中
|
|
123
|
-
- 在Windows系统上生成.pyd文件,在Linux/
|
|
124
|
-
- 对于复杂的Python项目,可能需要额外的编译选项
|
|
121
|
+
- 在Windows系统上生成.pyd文件,在Linux/macOS上生成.so文件
|
|
122
|
+
- 对于复杂的Python项目,可能需要额外的编译选项
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT License
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
py2pyd.py,sha256=ZP2z6BPpep0MSV8oLnFV0DFaYLkVTewXvxk-S5EYVXs,5399
|
|
2
|
+
module/__init__.py,sha256=Fh4A481uGhDkVmqGIH8MKH5_yAMncOz2UBdbCoYLl6k,220
|
|
3
|
+
module/fileConversion.py,sha256=NnjAlY1Cpl0_vidGetZq2uA-0Aaa-nH3MMfVwXkz-a0,3451
|
|
4
|
+
module/single_py2pyd.py,sha256=Bu9qL5qd4mVlODHExne3kfoYj0zcFSLc-G5rjc4DX8U,4894
|
|
5
|
+
gl_py2pyd-0.2.0.dist-info/METADATA,sha256=YxfZk1tVQi4-TypjWhv_qd8TF9dGBfTFopfcmoTKYkc,3357
|
|
6
|
+
gl_py2pyd-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
7
|
+
gl_py2pyd-0.2.0.dist-info/entry_points.txt,sha256=MNnYM2S-NKXNdgYAJ6ZVbXgOpFfZ3F9aQwn8MudjjSU,39
|
|
8
|
+
gl_py2pyd-0.2.0.dist-info/top_level.txt,sha256=uPWv-HYowjiEf_u6fIT0VxVmHRAn9YF2s-ORQePa1U4,14
|
|
9
|
+
gl_py2pyd-0.2.0.dist-info/RECORD,,
|
module/fileConversion.py
CHANGED
|
@@ -5,36 +5,79 @@ LastEditTime: 2023-09-26 10:43:03
|
|
|
5
5
|
LastEditors: gu lei
|
|
6
6
|
'''
|
|
7
7
|
import os
|
|
8
|
-
import
|
|
9
|
-
from
|
|
8
|
+
from rich.console import Console
|
|
9
|
+
from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TaskProgressColumn
|
|
10
10
|
from .single_py2pyd import py2pyd
|
|
11
11
|
|
|
12
|
+
console = Console()
|
|
13
|
+
|
|
12
14
|
class FileConversion:
|
|
13
15
|
|
|
14
16
|
def __init__(self) -> None:
|
|
15
17
|
self.initpy = None
|
|
16
18
|
self.success_count = 0
|
|
17
19
|
self.fail_count = 0
|
|
20
|
+
self.failed_files = [] # 记录失败的文件
|
|
18
21
|
|
|
19
22
|
def get_all_file(self, path, need_remove: bool): # 遍历此目录下的所有py文件,包含子目录里的py
|
|
23
|
+
# 首先收集所有需要处理的文件
|
|
24
|
+
all_files = []
|
|
25
|
+
init_py_dirs = [] # 记录有 __init__.py 的目录
|
|
26
|
+
|
|
20
27
|
for root, dirs, files in os.walk(path):
|
|
21
28
|
if "__init__.py" in files:
|
|
22
|
-
|
|
23
|
-
files
|
|
29
|
+
init_py_dirs.append(root)
|
|
30
|
+
files = [f for f in files if f != "__init__.py"]
|
|
24
31
|
for name in files:
|
|
25
32
|
if name.endswith(".py"):
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
all_files.append(os.path.join(root, name))
|
|
34
|
+
|
|
35
|
+
if not all_files:
|
|
36
|
+
console.print("⚠️ [yellow]目录中没有找到 .py 文件[/yellow]")
|
|
37
|
+
return True
|
|
38
|
+
|
|
39
|
+
# 使用 rich 进度条
|
|
40
|
+
with Progress(
|
|
41
|
+
SpinnerColumn(),
|
|
42
|
+
TextColumn("[progress.description]{task.description}"),
|
|
43
|
+
BarColumn(),
|
|
44
|
+
TaskProgressColumn(),
|
|
45
|
+
console=console
|
|
46
|
+
) as progress:
|
|
47
|
+
task = progress.add_task("转换进度", total=len(all_files))
|
|
48
|
+
|
|
49
|
+
for file_path in all_files:
|
|
50
|
+
# 处理 __init__.py
|
|
51
|
+
dir_path = os.path.dirname(file_path)
|
|
52
|
+
if dir_path in init_py_dirs and self.initpy is None:
|
|
53
|
+
self.process_init_py(dir_path)
|
|
54
|
+
init_py_dirs.remove(dir_path)
|
|
55
|
+
|
|
56
|
+
success = py2pyd(file_path)
|
|
57
|
+
if success:
|
|
58
|
+
self.success_count += 1
|
|
59
|
+
if need_remove:
|
|
60
|
+
os.remove(file_path)
|
|
61
|
+
else:
|
|
62
|
+
self.fail_count += 1
|
|
63
|
+
self.failed_files.append(file_path)
|
|
64
|
+
|
|
65
|
+
# 恢复 __init__.py
|
|
66
|
+
if self.initpy and dir_path not in init_py_dirs:
|
|
67
|
+
self.process_init_py(dir_path)
|
|
68
|
+
|
|
69
|
+
progress.update(task, advance=1)
|
|
70
|
+
|
|
71
|
+
# 显示结果
|
|
72
|
+
console.print()
|
|
73
|
+
if self.fail_count == 0:
|
|
74
|
+
console.print(f"✅ [bold green]处理完成!成功: {self.success_count} 个文件[/bold green]")
|
|
75
|
+
else:
|
|
76
|
+
console.print(f"⚠️ [yellow]处理完成!成功: {self.success_count} 个文件,失败: {self.fail_count} 个文件[/yellow]")
|
|
77
|
+
console.print("[red]失败的文件:[/red]")
|
|
78
|
+
for f in self.failed_files:
|
|
79
|
+
console.print(f" - {f}")
|
|
36
80
|
|
|
37
|
-
logger.info(f"处理完成!成功: {self.success_count} 个文件,失败: {self.fail_count} 个文件")
|
|
38
81
|
return self.success_count > 0 and self.fail_count == 0
|
|
39
82
|
|
|
40
83
|
def process_init_py(self, path):
|
module/single_py2pyd.py
CHANGED
|
@@ -9,7 +9,6 @@ import shutil
|
|
|
9
9
|
import glob
|
|
10
10
|
import subprocess
|
|
11
11
|
import sys
|
|
12
|
-
from loguru import logger
|
|
13
12
|
|
|
14
13
|
def py2pyd(path):
|
|
15
14
|
"""
|
|
@@ -17,11 +16,10 @@ def py2pyd(path):
|
|
|
17
16
|
|
|
18
17
|
Args:
|
|
19
18
|
path: Python文件路径
|
|
20
|
-
"""
|
|
21
|
-
logger.info(f"==========================================")
|
|
22
|
-
logger.info(f"开始处理文件: {path}")
|
|
23
|
-
logger.info(f"当前工作目录: {os.getcwd()}")
|
|
24
19
|
|
|
20
|
+
Returns:
|
|
21
|
+
bool: 转换是否成功
|
|
22
|
+
"""
|
|
25
23
|
# 保存原始工作目录
|
|
26
24
|
original_dir = os.getcwd()
|
|
27
25
|
try:
|
|
@@ -29,8 +27,6 @@ def py2pyd(path):
|
|
|
29
27
|
try:
|
|
30
28
|
import Cython
|
|
31
29
|
except ImportError:
|
|
32
|
-
logger.error("缺少必要的依赖: Cython")
|
|
33
|
-
logger.info("请先安装依赖: pip install cython")
|
|
34
30
|
return False
|
|
35
31
|
|
|
36
32
|
# 转换为绝对路径
|
|
@@ -39,12 +35,8 @@ def py2pyd(path):
|
|
|
39
35
|
file_path: str = os.path.basename(abs_path) # 带py的文件名
|
|
40
36
|
filename = file_path.split('.py')[0] # 不带py的文件名
|
|
41
37
|
|
|
42
|
-
logger.info(f"目标文件夹路径: {folder_path}")
|
|
43
|
-
logger.info(f"文件名: {file_path}")
|
|
44
|
-
|
|
45
38
|
# 更改工作目录
|
|
46
39
|
os.chdir(folder_path)
|
|
47
|
-
logger.info(f"切换后的工作目录: {os.getcwd()}")
|
|
48
40
|
|
|
49
41
|
# 根据系统配置编译参数和链接参数
|
|
50
42
|
extra_compile_args = []
|
|
@@ -91,12 +83,11 @@ def py2pyd(path):
|
|
|
91
83
|
f.write(' )\n')
|
|
92
84
|
f.write(')\n')
|
|
93
85
|
|
|
94
|
-
logger.info(f"开始执行 setup.py")
|
|
95
86
|
try:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
87
|
+
# 隐藏编译输出,保持界面简洁
|
|
88
|
+
subprocess.check_call(['python', 'setup.py', 'build_ext', '--inplace'],
|
|
89
|
+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
90
|
+
except subprocess.CalledProcessError:
|
|
100
91
|
# 清理临时文件
|
|
101
92
|
if os.path.exists('setup.py'):
|
|
102
93
|
os.remove('setup.py')
|
|
@@ -106,10 +97,8 @@ def py2pyd(path):
|
|
|
106
97
|
is_windows = sys.platform.startswith('win')
|
|
107
98
|
extension = '.pyd' if is_windows else '.so'
|
|
108
99
|
output_file = f"{filename}{extension}"
|
|
109
|
-
logger.info(f"目标文件名: {output_file}")
|
|
110
100
|
|
|
111
101
|
if os.path.exists(output_file):
|
|
112
|
-
logger.info(f"删除已存在的文件: {output_file}")
|
|
113
102
|
os.remove(output_file) # 删除老的文件
|
|
114
103
|
|
|
115
104
|
# 查找生成的扩展文件
|
|
@@ -119,16 +108,11 @@ def py2pyd(path):
|
|
|
119
108
|
ext_files = glob.glob(filename + "*.so")
|
|
120
109
|
|
|
121
110
|
if not ext_files:
|
|
122
|
-
logger.error(f"未找到编译后的文件")
|
|
123
111
|
return False
|
|
124
|
-
|
|
125
|
-
logger.info(f"找到的文件: {ext_files}")
|
|
126
112
|
|
|
127
113
|
os.rename(ext_files[0], output_file) # 改名字,删除多余的cp38-win_amd64.等
|
|
128
|
-
logger.info(f"重命名文件完成")
|
|
129
114
|
|
|
130
115
|
# 清理临时文件
|
|
131
|
-
logger.info("开始清理临时文件")
|
|
132
116
|
if os.path.exists('%s.c' % filename):
|
|
133
117
|
os.remove('%s.c' % filename) # 删除临时文件
|
|
134
118
|
if os.path.exists('build'):
|
|
@@ -138,18 +122,14 @@ def py2pyd(path):
|
|
|
138
122
|
if os.path.exists('__pycache__'):
|
|
139
123
|
shutil.rmtree('__pycache__') # 删除 __pycache__文件夹
|
|
140
124
|
[os.remove(i) for i in glob.glob("*.ui")] # 删除ui文件
|
|
141
|
-
|
|
142
|
-
logger.info(f"==========================================\n")
|
|
125
|
+
|
|
143
126
|
return True
|
|
144
127
|
|
|
145
|
-
except Exception
|
|
146
|
-
logger.error(f"处理文件时发生错误: {e}")
|
|
128
|
+
except Exception:
|
|
147
129
|
return False
|
|
148
130
|
finally:
|
|
149
131
|
# 恢复原始工作目录
|
|
150
132
|
os.chdir(original_dir)
|
|
151
|
-
logger.info(f"恢复原始工作目录: {original_dir}")
|
|
152
|
-
logger.info(f"==========================================\n")
|
|
153
133
|
|
|
154
134
|
if __name__ == "__main__":
|
|
155
135
|
import argparse
|
py2pyd.py
CHANGED
|
@@ -9,83 +9,145 @@ LastEditors: gu lei
|
|
|
9
9
|
import os
|
|
10
10
|
import sys
|
|
11
11
|
import argparse
|
|
12
|
-
from
|
|
12
|
+
from rich.console import Console
|
|
13
|
+
from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TaskProgressColumn
|
|
14
|
+
|
|
15
|
+
__version__ = '0.2.0'
|
|
16
|
+
|
|
17
|
+
console = Console()
|
|
13
18
|
|
|
14
19
|
def check_dependencies():
|
|
15
20
|
"""检查必要的依赖是否已安装"""
|
|
16
21
|
try:
|
|
17
22
|
import Cython
|
|
18
|
-
logger.info(f"检测到Cython版本: {Cython.__version__}")
|
|
19
23
|
return True
|
|
20
24
|
except ImportError:
|
|
21
|
-
|
|
25
|
+
console.print("❌ [bold red]缺少必要的依赖: Cython[/bold red]")
|
|
26
|
+
console.print(" 请先安装依赖: pip install cython")
|
|
22
27
|
return False
|
|
23
28
|
|
|
24
29
|
from module.single_py2pyd import py2pyd
|
|
25
30
|
from module.fileConversion import FileConversion
|
|
26
31
|
|
|
27
|
-
def
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
def process_files(files, need_remove=False, desc="转换进度"):
|
|
33
|
+
"""处理文件列表并显示进度条"""
|
|
34
|
+
success_count = 0
|
|
35
|
+
fail_count = 0
|
|
36
|
+
failed_files = []
|
|
37
|
+
|
|
38
|
+
with Progress(
|
|
39
|
+
SpinnerColumn(),
|
|
40
|
+
TextColumn("[progress.description]{task.description}"),
|
|
41
|
+
BarColumn(),
|
|
42
|
+
TaskProgressColumn(),
|
|
43
|
+
console=console
|
|
44
|
+
) as progress:
|
|
45
|
+
task = progress.add_task(desc, total=len(files))
|
|
31
46
|
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
for file_path in files:
|
|
48
|
+
success = py2pyd(file_path)
|
|
49
|
+
if success:
|
|
50
|
+
success_count += 1
|
|
51
|
+
if need_remove:
|
|
52
|
+
os.remove(file_path)
|
|
53
|
+
else:
|
|
54
|
+
fail_count += 1
|
|
55
|
+
failed_files.append(file_path)
|
|
56
|
+
progress.update(task, advance=1)
|
|
57
|
+
|
|
58
|
+
return success_count, fail_count, failed_files
|
|
59
|
+
|
|
60
|
+
def main():
|
|
61
|
+
parser = argparse.ArgumentParser(
|
|
62
|
+
description="将Python文件转换为pyd/so文件",
|
|
63
|
+
epilog="示例:\n"
|
|
64
|
+
" py2pyd file.py 转换单个文件\n"
|
|
65
|
+
" py2pyd folder/ 转换目录下的文件\n"
|
|
66
|
+
" py2pyd -r folder/ 递归转换目录\n"
|
|
67
|
+
" py2pyd --remove file.py 转换后删除原文件",
|
|
68
|
+
formatter_class=argparse.RawDescriptionHelpFormatter
|
|
69
|
+
)
|
|
70
|
+
parser.add_argument("path", nargs='?', help="要转换的Python文件或目录路径")
|
|
34
71
|
parser.add_argument("-r", "--recursive", action="store_true", help="递归处理目录")
|
|
35
72
|
parser.add_argument("--remove", action="store_true", help="转换后删除原始.py文件")
|
|
73
|
+
parser.add_argument("-v", "--version", action="version", version=f"py2pyd {__version__}")
|
|
36
74
|
|
|
37
75
|
args = parser.parse_args()
|
|
38
76
|
|
|
77
|
+
# 如果没有提供路径参数,显示帮助信息
|
|
78
|
+
if not args.path:
|
|
79
|
+
parser.print_help()
|
|
80
|
+
sys.exit(0)
|
|
81
|
+
|
|
82
|
+
# 检查依赖
|
|
83
|
+
if not check_dependencies():
|
|
84
|
+
sys.exit(1)
|
|
85
|
+
|
|
86
|
+
# 删除确认
|
|
87
|
+
if args.remove:
|
|
88
|
+
confirm = input("⚠️ 警告: --remove 选项将会删除所有py源文件,是否继续? (y/n): ")
|
|
89
|
+
if confirm.lower() != 'y':
|
|
90
|
+
console.print("操作已取消")
|
|
91
|
+
sys.exit(0)
|
|
92
|
+
|
|
39
93
|
path = args.path
|
|
40
94
|
|
|
41
95
|
if not os.path.exists(path):
|
|
42
|
-
|
|
96
|
+
console.print(f"❌ [bold red]路径不存在: {path}[/bold red]")
|
|
43
97
|
sys.exit(1)
|
|
44
98
|
|
|
45
|
-
|
|
99
|
+
success_count = 0
|
|
100
|
+
fail_count = 0
|
|
101
|
+
failed_files = []
|
|
46
102
|
|
|
47
103
|
if os.path.isfile(path):
|
|
48
104
|
# 处理单个文件
|
|
49
105
|
if not path.endswith(".py"):
|
|
50
|
-
|
|
106
|
+
console.print(f"❌ [bold red]不是Python文件: {path}[/bold red]")
|
|
51
107
|
sys.exit(1)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
logger.info(f"删除原始文件: {path}")
|
|
56
|
-
os.remove(path)
|
|
108
|
+
console.print(f"📄 处理文件: [cyan]{path}[/cyan]")
|
|
109
|
+
success_count, fail_count, failed_files = process_files([path], args.remove)
|
|
110
|
+
|
|
57
111
|
elif os.path.isdir(path):
|
|
58
112
|
# 处理目录
|
|
59
113
|
if args.recursive:
|
|
60
|
-
|
|
114
|
+
console.print(f"📁 递归处理目录: [cyan]{path}[/cyan]")
|
|
61
115
|
converter = FileConversion()
|
|
62
116
|
success = converter.get_all_file(path, args.remove)
|
|
117
|
+
if success:
|
|
118
|
+
console.print("\n🎉 [bold green]全部转换成功![/bold green]")
|
|
119
|
+
else:
|
|
120
|
+
console.print("\n❌ [bold red]处理完成,但有部分文件转换失败![/bold red]")
|
|
121
|
+
sys.exit(0 if success else 1)
|
|
63
122
|
else:
|
|
64
123
|
# 仅处理当前目录下的.py文件
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
for
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
success_count += 1
|
|
74
|
-
if args.remove:
|
|
75
|
-
logger.info(f"删除原始文件: {file_path}")
|
|
76
|
-
os.remove(file_path)
|
|
77
|
-
else:
|
|
78
|
-
fail_count += 1
|
|
124
|
+
console.print(f"📁 处理目录: [cyan]{path}[/cyan]")
|
|
125
|
+
|
|
126
|
+
# 收集所有 .py 文件
|
|
127
|
+
py_files = [os.path.join(path, f) for f in os.listdir(path) if f.endswith(".py")]
|
|
128
|
+
|
|
129
|
+
if not py_files:
|
|
130
|
+
console.print("⚠️ [yellow]目录中没有找到 .py 文件[/yellow]")
|
|
131
|
+
sys.exit(0)
|
|
79
132
|
|
|
80
|
-
|
|
81
|
-
|
|
133
|
+
success_count, fail_count, failed_files = process_files(py_files, args.remove)
|
|
134
|
+
|
|
135
|
+
# 显示结果
|
|
136
|
+
console.print()
|
|
137
|
+
if fail_count == 0:
|
|
138
|
+
console.print(f"✅ [bold green]处理完成!成功: {success_count} 个文件[/bold green]")
|
|
139
|
+
else:
|
|
140
|
+
console.print(f"⚠️ [yellow]处理完成!成功: {success_count} 个文件,失败: {fail_count} 个文件[/yellow]")
|
|
141
|
+
console.print("[red]失败的文件:[/red]")
|
|
142
|
+
for f in failed_files:
|
|
143
|
+
console.print(f" - {f}")
|
|
82
144
|
|
|
83
|
-
if
|
|
84
|
-
|
|
145
|
+
if fail_count == 0:
|
|
146
|
+
console.print("\n🎉 [bold green]全部转换成功![/bold green]")
|
|
85
147
|
sys.exit(0)
|
|
86
148
|
else:
|
|
87
|
-
|
|
149
|
+
console.print("\n❌ [bold red]处理完成,但有部分文件转换失败![/bold red]")
|
|
88
150
|
sys.exit(1)
|
|
89
151
|
|
|
90
152
|
if __name__ == "__main__":
|
|
91
|
-
main()
|
|
153
|
+
main()
|
gl_py2pyd-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
py2pyd.py,sha256=WBkiwqHMOhegcp0s57Zvh0i64SO3IiUgUwN4ej_lJhs,3016
|
|
2
|
-
module/__init__.py,sha256=Fh4A481uGhDkVmqGIH8MKH5_yAMncOz2UBdbCoYLl6k,220
|
|
3
|
-
module/fileConversion.py,sha256=C5N_8WkCadZFEo1ylbaGEiDoINK3lKh7bEbz_rqdu3Q,1714
|
|
4
|
-
module/single_py2pyd.py,sha256=lx1CojipLdkyJWSCsxSFHGNZPHCZKiN42Osd6Zmlktg,6048
|
|
5
|
-
gl_py2pyd-0.1.0.dist-info/METADATA,sha256=LdrkXjhVhU6W3bq6gr0F9KgRqNkgjBFUXTxL28CWv7g,3586
|
|
6
|
-
gl_py2pyd-0.1.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
7
|
-
gl_py2pyd-0.1.0.dist-info/entry_points.txt,sha256=MNnYM2S-NKXNdgYAJ6ZVbXgOpFfZ3F9aQwn8MudjjSU,39
|
|
8
|
-
gl_py2pyd-0.1.0.dist-info/top_level.txt,sha256=uPWv-HYowjiEf_u6fIT0VxVmHRAn9YF2s-ORQePa1U4,14
|
|
9
|
-
gl_py2pyd-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|