Working with PyPI
Publish PyPI Package
-
Edit
$HOME/.pypircto add a package repository like below:[distutils]index-servers=onedev[onedev]repository=https://onedev.example.com/<project path>/~pypiusername=<onedev_account_name>password=<onedev_account_password>Param Explanation <project path> path of a project with package management enabled <onedev_account_name> name of OneDev account with package write permission over the project <onedev_account_password> password or access token of OneDev account -
Build your Python distribution and upload it with Twine. For a project with
pyproject.toml:python3 -m pip install build twinepython3 -m buildThen upload:
$ python3 -m twine upload --repository onedev /path/to/files_to_upload -
For CI/CD job, run below to add package repository via command step
# Use job token to tell OneDev the build publishing the package# Job secret 'access-token' should be defined in project build setting as an access token with package write permissioncat << EOF > $HOME/.pypirc[distutils]index-servers=onedev[onedev]repository=https://onedev.example.com/<project path>/~pypiusername=@job_token@password=@secret:access-token@EOFpython3 -m buildpython3 -m twine upload --repository onedev dist/*Param Explanation <project path> same as above
Consume Published PyPI Package
Open the package detail page for its installation instructions. Use the registry's simple endpoint for pip:
python3 -m pip install --index-url https://onedev.example.com/<project-path>/~pypi/simple <package-name>==<version>
Authenticate with an account or token with package read permission, using a protected .netrc or your environment's credential mechanism. .pypirc configures Twine uploads; it does not configure pip authentication. Keep credential files out of source control.
