使用pep 517钩子构建python包的包装器
pep517的Python项目详细描述
PEP 517指定一个标准 用于构建python包的系统的api。
此包包含pep 517指定的钩子周围的包装。它 提供:
- 调用子进程中钩子的机制,以便它们与 当前进程。
- 可选钩子的回退,以便前端可以调用钩子 检查已定义的。
- 将生成依赖项安装到 临时环境并使用它们构建一个wheel/sdist。
使用py.test运行测试。
高级使用,处理生成要求:
importosfrompep517.envbuildimportbuild_wheel,build_sdistsrc='path/to/source'# Folder containing 'pyproject.toml'destination='also/a/folder'whl_filename=build_wheel(src,destination)assertos.path.isfile(os.path.join(destination,whl_filename))targz_filename=build_sdist(src,destination)assertos.path.isfile(os.path.join(destination,targz_filename))
您负责确保构建需求 可用:
importosimportpytomlfrompep517.wrappersimportPep517HookCallersrc='path/to/source'# Folder containing 'pyproject.toml'withopen(os.path.join(src,'pyproject.toml'))asf:build_sys=pytoml.load(f)['build-system']print(build_sys['requires'])# List of static requirementshooks=Pep517HookCaller(src,build_backend=build_sys['build_backend'])config_options={}# Optional parameters for backend# List of dynamic requirements:print(hooks.get_requires_for_build_wheel(config_options))destination='also/a/folder'whl_filename=hooks.build_wheel(destination,config_options)assertos.path.isfile(os.path.join(destination,whl_filename))
要测试项目的生成后端,请在系统外壳中运行:
python3 -m pep517.check path/to/source # source dir containing pyproject.toml
要将后端构建为源和/或二进制发行版,请在shell中运行:
python -m pep517.build path/to/source # source dir containing pyproject.toml
当pypadecides on the best place for this functionality时,这个“build”模块应该被认为是实验性的。