如何将开源 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.py
pyproject.toml
猫 setup.py
生成分发存档并上传到 PyPi
确保您拥有最新版本并安装了:setuptools
wheel
pip install --user --upgrade setuptools wheel
现在从所在的同一目录运行此命令:setup.py
python -m build python -m twine upload --verbose dist/*
为方便起见,您可以在文件中写入您的登录名:~/.pypirc