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   荣锋亮  阅读(37)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-04-01 grafana admin 密码重置
2023-04-01 "cni0" already has an IP address different from 问题解决
2022-04-01 apm + tracing 一些开源工具参考资料
2022-04-01 signoz reader 接口定义
2022-04-01 signoz 参考架构设计
2021-04-01 cube.js dremio driver基于补偿机制提升查询速度
2019-04-01 hasura graphql-engine 集成zombodb

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示