setuptools入门
sixwalter Lv6

setuptools Quickstart

basics

  1. 声明使用setuptools 来打包项目
1
2
3
4
# pyproject.toml
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
  1. 通过配置文件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"',
],
)
  1. 需要一个构建器builder
1
2
# pip install build
python -m build

extensions

  1. 自动包发现
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. 依赖管理
1
2
3
4
5
setup(
# ...
install_requires=["docutils", "requests <= 0.4"],
# ...
)
  1. 开发者模式
1
pip install --editable .

experiments

遵循教程,实验打包流程:https://packaging.python.org/en/latest/tutorials/packaging-projects/

image-20220414140619160

  • Post title:setuptools入门
  • Post author:sixwalter
  • Create time:2023-08-05 11:14:26
  • Post link:https://coelien.github.io/2023/08/05/projects/kinetics project/setuptools/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments