Skip to main content

Working with PyPi

Publish PyPi Package

  1. Edit $HOME/.pypirc to add a package repository like below:

    [distutils]
    index-servers=
    onedev

    [onedev]
    repository=https://onedev.example.com/<project path>/~pypi
    username=<onedev_account_name>
    password=<onedev_account_password>
    ParamExplanation
    <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
  2. Then upload package to the repository with twine

    $ python3 -m twine upload --repository onedev /path/to/files_to_upload
  3. 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 permission

    cat << EOF > $HOME/.pypirc
    [distutils]
    index-servers=
    onedev

    [onedev]
    repository=https://onedev.example.com/<project path>/~pypi
    username=@job_token@
    password=@secret:access-token@
    EOF
    ParamExplanation
    <project path>same as above

Consume Published PyPi Package

The package detail page contains instructions on how to consume published image.