CircleCI + Pypi deploy

python

#1

Hello. I’m trying to upload my python project to a private pypi after the build is successful for tags or branches. I couldn’t find anything in the documentation about it. Is this possible? How?

Thanks in advance!


#2

Not sure there is a separate article about that, subject is too specific to cover in general documentation from my perspective.

We do use Circle standard stages to do the package build, for 1.0 it looks like:

deployment:
  build_package:
    branch: master
    commands:
      - ./circle-build-package.sh

for 2.0 it is something like:

      - type: deploy
        name: Build Package
        command: ./circle-build-package.sh

Where circle-build-package.sh is something like:

#!/usr/bin/env bash

if [ -z "$CI" ]; then
    echo "Will only continue on CI"
    exit
fi

if [[ $CIRCLE_BRANCH != "master" ]]; then
    echo "Will only continue for master builds"
    exit
fi

# build package and upload to private pypi index
echo "[distutils]" >> ~/.pypirc
echo "index-servers = pypi-private" >> ~/.pypirc
echo "[pypi-private]" >> ~/.pypirc
echo "repository=https://$PYPI_HOST" >> ~/.pypirc
echo "username=$PYPI_USERNAME" >> ~/.pypirc
echo "password=$PYPI_PASSWORD" >> ~/.pypirc

python setup.py sdist upload -r pypi-private

Of course in this setup you have to specify PYPI_HOST, PYPI_USERNAME and PYPI_PASSWORD in your circle.yml environment variables section.


#3