basics
- 声明使用setuptools 来打包项目
1 2 3 4
| # pyproject.toml [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta"
|
- 通过配置文件setup.py来 specify 包信息
1 2 3 4 5 6 7 8 9 10 11
| from setuptools import setup
setup( name='mypackage', version='0.0.1', packages=['mypackage'], install_requires=[ 'requests', 'importlib-metadata; python_version == "3.8"', ], )
|
- 需要一个构建器builder
1 2
| # pip install build python -m build
|
extensions
- 自动包发现
1 2 3 4 5 6 7 8 9 10 11
| from setuptools import find_packages # or find_namespace_packages
setup( # ... packages=find_packages( where='.', include=['mypackage*'], # ["*"] by default exclude=['mypackage.tests'], # empty by default ), # ... )
|
- 依赖管理
1 2 3 4 5
| setup( # ... install_requires=["docutils", "requests <= 0.4"], # ... )
|
- 开发者模式
1
| pip install --editable .
|
experiments
遵循教程,实验打包流程:https://packaging.python.org/en/latest/tutorials/packaging-projects/