y4h2 / personal-notes

my personal notes
0 stars 0 forks source link

python打包 #69

Open y4h2 opened 1 year ago

y4h2 commented 1 year ago

How to Publish an Open-Source Python Package to PyPI

Setup Tool

click setup example: https://github.com/yu-iskw/click-custom-multi-commands-example other doc: https://stackoverflow.com/questions/61449987/how-to-package-my-python-program-so-the-user-can-install-it-using-setup-py more about setup tool: https://python-packaging-tutorial.readthedocs.io/en/latest/setup_py.html

pyproject.toml

https://godatadriven.com/blog/a-practical-guide-to-setuptools-and-pyproject-toml/

official doc

install your package locally

python -m pip install -e .

or

pip install mypackage --no-index --find-links file:///srv/pkg/mypackage

--no-index and --find-links可以被放在requirements.txt

generate package

Python: Creating a pip installable package

python setup.py sdist

or

python -m build

upload package to private registry

setup your .pypirc

[distutils]
index-servers = nexus

[nexus]
repository=[my URL]/repository/[repositoryname]
username=[username]
password=[password]

用twine上传

twine upload -r nexus dist/*