如何将开源 Python 包发布到 PyPI 存储库

2022/11/1 23:24:52

本文主要是介绍如何将开源 Python 包发布到 PyPI 存储库,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

项目结构:

myproject-source-dir/
├── LICENSE
├── pyproject.toml
├── README.md
├── magic_config/
│   └── magic_config/
│       ├── __init__.py
│       └── lib.py
├── .gitignore
├── tests/
└── setup.py

Cat pyproject.toml

[build-system]
requires = [
    "setuptools>=42",
    "wheel",
]
build-backend = "setuptools.build_meta"

[project]
name = "magic-config"
version = "0.1.5"
authors = [
    { name = "Alexander Majorov", email = "alexander.majorov@gmail.com" },
]
description = "A simple library"
readme = "README.md"
requires-python = ">=3.10.8"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
]

[project.urls]
"Homepage" = "https://github.com/frontdevops/magic-config"
"Documentation" = "https://github.com/frontdevops/magic-config/blob/main/README.md"
"Bug Tracker" = "https://github.com/frontdevops/magic-config/issues"

为了方便起见,为了不对多个文件进行编辑,我这样做是为了使文件从文件中获取所有数据setup.pypyproject.toml

猫 setup.py

 

生成分发存档并上传到 PyPi

确保您拥有最新版本并安装了:setuptoolswheel

pip install --user --upgrade setuptools wheel

现在从所在的同一目录运行此命令:setup.py

python -m build
python -m twine upload --verbose dist/*

为方便起见,您可以在文件中写入您的登录名:~/.pypirc



这篇关于如何将开源 Python 包发布到 PyPI 存储库的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程