setuptools 对于现代python包支持的简单试用

以前我们编写python包通过setuptools 是编写配置setup.cfg以及一个setup.py 文件,现代的玩法是基于pyproject.toml
以下是一个简单学习

项目准备

使用venv

  • cli
python -m venv venv
source venv/bin/activate
  • 创建项目文件
    pyproject.toml,里边包含了build backend
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

setup.cfg 主要是配置一些信息,当然也都可以写到pyproject.toml 中

[metadata]
name = dalong
version = 0.0.1
description = a package  for learning
 
[options]
 
[options.packages.find]
where = src
include = dalong.*
 
[options.entry_points]
sqlalchemy.dialects =
    dalong=dalong.app:app
  • 构建
python -m build
  • 效果

说明

以上是一个简单的试用,setuptools 也在持续演进,值得重新学习下

参考资料

https://setuptools.pypa.io/en/latest/pkg_resources.html#entry-points
https://hatch.pypa.io/latest/
https://github.com/pypa/hatch
https://setuptools.pypa.io/en/latest/userguide/quickstart.html
https://python-poetry.org/docs/pyproject/
https://github.com/python-poetry/poetry

posted on 2024-04-01 08:00  荣锋亮  阅读(18)  评论(0编辑  收藏  举报

导航