Skip to main content

自动Cython,使用Cython批量编译.py文件为.pyd文件!

Project description

AutoCython V2

中文 | English

自动 Cython:一键将 Python 文件批量编译为 PYD / SO 文件 py_pyd

✨ 特性

  • 单文件/多文件批量编译
  • 跨平台支持 (Windows/Linux/MacOS)
  • 简洁命令行界面

📦 安装

pip install -U AutoCython-zhang

⚙️ 依赖环境

C/C++ 编译器

  • Windows: Visual Studio
  • Linux: gcc & g++

重要提示:编译器架构必须与Python解释器一致(64位Python需64位编译器)

其他编译器配置请参考 Cython 项目

🚀 使用指南

命令行操作

命令行演示

# 编译单个文件
AutoCython -f test.py

# 编译整个目录
AutoCython -p D:/python_code/ProjectPath

# 编译后删除源代码 (默认不删除)
AutoCython -d -f test.py
AutoCython -d -p D:/python_code/ProjectPath

# 指定混淆随机种子(可复现构建)
AutoCython --seed 2025 -f test.py

编译界面

AutoCython GUI

手动排除文件不编译

在文件头部 前两行 添加声明:

# AutoCython No Compile
# 此文件将跳过编译处理

🧪 测试

# 运行全部测试
pytest

# 只运行单元测试
pytest -m unit

# 只运行集成测试 (kd_dist)
pytest -m integ

# 排除集成测试(快速验证)
pytest -m "not integ"

kd-dist 集成测试配置

# 指定真实项目根目录(未设置则自动探测)
export KD_DIST_ROOT=/path/to/kd-dist

# 开启严格文件计数阈值校验(默认关闭)
export KD_DIST_STRICT_COUNTS=1

# 输出 kd-dist 分层测试 JSON 报告
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json

tests/kd_dist/manifest.json 用于定义 import policy 与行为等价用例,
tests/kd_dist/known_failures.json 用于记录已知 Cython 不兼容文件(xfail 治理)。

⚠️ 常见问题解决

一般是源代码中有 Cython 不支持的语句, 或者文件名不支持等. 可以查阅 Cython Wiki 项目 官方文档, 或者提 Issue.

📅 更新记录

V2 版本

  1. 20250623 release V2.1.0 禁用激进的性能优化选项. 显示系统信息.
  2. 20250609 release V2.0.0 重构了代码, 使用新的界面 (不安全版本)

V1 版本

  1. 20220613 更新对Linux的支持, Linux下需要配置gcc&g++
  2. 20221123 可以通过文件头手动指定不编译的文件
  3. 20230306 更新可以指定命令行头如 Python310 以此支持非Widnows系统下编译
  4. 20230324 更新文档
  5. 20240506 修复编译失败时遗漏复原 __init__.py 的问题

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autocython_zhang-2.3.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autocython_zhang-2.3.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file autocython_zhang-2.3.0.tar.gz.

File metadata

  • Download URL: autocython_zhang-2.3.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for autocython_zhang-2.3.0.tar.gz
Algorithm Hash digest
SHA256 f7a20fefc129c4dee8c1496590cafbf61a306804d8585428aec529809d15ee85
MD5 67b659e9c67a7b81eb0692887081ca07
BLAKE2b-256 a8cad0c8cb59170b940943a8ef4994eb87aefdde231981d85bbd8f2c3f9ab04b

See more details on using hashes here.

File details

Details for the file autocython_zhang-2.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for autocython_zhang-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62c6ab28c64eb46d9583f3d6bcc8e5e3a16bb13358bd8f2bf782051053ad2c59
MD5 8d52ec3a0928c15c845c98f67b847fa0
BLAKE2b-256 9b4303fdfef5a9ab21df63bb7dfd8fe3b9e228e2ccad440221044634067b8bb8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page