据我所知,公文包实际上与PEP 517不兼容(至少默认情况下不兼容)。它使用一个pyproject.toml
文件,但不填满该[build-system]
部分,因此应该可以在该文件中设置实际的PEP 517构建后端而不会引起冲突。
pyproject.toml
[build-system]
build-backend = 'setuptools.build_meta'
requires = [
'setuptools',
'toml',
]
[tool.briefcase.app.exampleapp]
formal_name = 'exampleapp'
description = 'something'
requires = ['PyQt5', 'qtconsole']
sources = ['exampleapp']
setup.py
#!/usr/bin/env python3
import pathlib
import pkg_resources
import setuptools
import toml
def _parse_briefcase_toml(pyproject_path, app_name):
pyproject_text = pyproject_path.read_text()
pyproject_data = toml.loads(pyproject_text)
briefcase_data = pyproject_data['tool']['briefcase']
app_data = briefcase_data['app'][app_name]
setup_data = {
'name': pkg_resources.safe_name(app_data['formal_name']),
'version': briefcase_data['version'],
'install_requires': app_data['requires'],
# ...
}
return setup_data
def _setup():
app_name = 'exampleapp'
pyproject_path = pathlib.Path('pyproject.toml')
setup_data = _parse_briefcase_toml(pyproject_path, app_name)
setuptools.setup(**setup_data)
if __name__ == '__main__':
_setup()
然后pip和其他PEP 517兼容的前端应该能够通过委派给setuptools来构建和安装项目,同时注意正确设置包含setuptools和toml的构建环境。
我想也可以让公文包处理pyproject.toml
文件的解析(也许用briefcase.config.parse_config(...)
),但它没有记录,所以我不知道这些 API 有多稳定。