Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gene1wood/ea21ccbed99e982f23a215fa25ed346d to your computer and use it in GitHub Desktop.
Save gene1wood/ea21ccbed99e982f23a215fa25ed346d to your computer and use it in GitHub Desktop.
Some exploration around what would be needed to simplify (through code) the process of releasing python package versions
  • Make sure CHANGELOG.md has all new functionality you want in the release

    • Summarize changes since last release that are missing from Unreleased
  • Pick new version based on semver rules

  • Run unit tests / tox

  • Run flake8

  • Check CHANGELOG.md to ensure

    • There are contents in unreleased
    • The new version number isn't present
  • Verify version is newer than newest version in pypi.org

    curl https://pypi.org/project/${PACKAGE_NAME}/${NEW_VERSION}/
    pip install ${PACKAGE_NAME}== 2>&1 | grep "Could not find a version" 
    
  • Increment version in setup.py

  • Update CHANGELOG.md

    • Create new section with the new version number
    • Update links at the bottom to accomodate the new version number
  • Ensure there is no distribution in CWD already

  • Build the distribution

    python3 setup.py sdist bdist_wheel --universal
    
  • Install the newest version of twine (and maybe setuptools?)

  • twine check distribution

    twine check dist/*
    
  • Upload the distribution to test.pypi.org with twine

    echo test | gpg --clearsign --armor # sign something to cache the gpg passphrase
    twine upload -r pypitest -s dist/*
    
  • Provision virtualenv

    virtualenv --python=python3 /tmp/${PACKAGE_NAME}-${NEW_VERSION}
    
  • Install -r requirements.txt

    /tmp/${PACKAGE_NAME}-${NEW_VERSION}/bin/pip install -r requirements.txt
    
  • Install the package from test.pypi.org

    /tmp/${PACKAGE_NAME}-${NEW_VERSION}/bin/pip install -i https://testpypi.python.org/pypi ${PACKAGE_NAME}==${NEW_VERSION}
    
  • Test

    . "/tmp/${PACKAGE_NAME}-${NEW_VERSION}/bin/activate"
    
  • Clean up the virtualenv

    deactivate
    rm -rf /tmp/${PACKAGE_NAME}-${NEW_VERSION}/
    
  • Either

    • Commit the updated setup.py and CHANGELOG.md directly to upstream
      • Tag the commit
      • Push the commit and the tag
      • Create a GitHub release for the tag
    • PR the updated setup.py and CHANGELOG.md
      • Merge the PR
      • Create a GitHub release which creates a tag
  • Upload distribution to pypi.org with twine

    twine upload -s dist/*
    
  • Provision and activate virtualenv

    virtualenv --python=python3 /tmp/${PACKAGE_NAME}-${NEW_VERSION}
    
  • Install the package

    /tmp/${PACKAGE_NAME}-${NEW_VERSION}/bin/pip install --upgrade ${PACKAGE_NAME}==${NEW_VERSION}
    
  • Verify the version number is correct

  • Test

    . "/tmp/${PACKAGE_NAME}-${NEW_VERSION}/bin/activate"
    
  • Delete dist build etc

  • Clean up the virtualenv

    deactivate
    rm -rf /tmp/${PACKAGE_NAME}-${NEW_VERSION}/
    
  • Parseing and dealing with CHANGELOG.md

  • Some of this in GitHub Actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment