Package: pypi-version
pypi-versionGetting startedHow to installWhat is pypi-versionMotivationExamplesUsageCommand line interfaceConfiguration fileContinuous integration servicesTravis-CICircleCIContributingReferencesPython packageGitflow workflowUpload to PyPiContinuous integration servicesGetting startedHow to installInstall thepypi-versionwith the following command usingpip3:$pip3installpypi-versionWhat is pypi-versionpypi-versionchecks if you haven't forgotten to bump thePyPi package version numberbefore you merge a release
pull request.It would be useful if you:developPython package,followGitflow workflow,upload package to thePython Package Index (PyPi),use the following continuous integration services:Travis-CI,CircleCIIf you do not know these concepts, go ahead to thereferences sectionfirst. After, start reading from the next section.MotivationPython packageshave version number such as0.1.0or1.3.3.Python packagescommonly are uploaded toPyPi.
Sometimes after adding new functionality to your package you forget to increase the version number of the package.
So when you try to upload it, you get the error messagePackage version number already in use. It is okay if
you develop the package locally and alone, you just modify the version number and upload it again. But if you
develop the package using particular development flow such asGitflow workflowand continuous integration
services — then you should create separated pull request to bump the version, the resources and time you will spend
on it are increasing in few times. The cost of the mistake is high.So if you integrate thepypi-versionto your continuous integration service by checking the version using simple command line tool, it willneverallow your pull request to be merged if you forget to increase the version.ExamplesThere is the test repository of thePython packagethat has integratedpypi-version—test-pypi-version-travis-ci. It usesTravis CIas continuous integration service.It contains:developandmasterbranches,masterbranch contains filesetup.py where version is 0.1.0,according to the version number in themasterbranch (release branch), package isuploaded to the PyPi with version 0.1.0,there is apull request from develop branch to master branch— it is a release pull request that intend increasing of the version number,but in the changesversion number in setup.py isn't increased,that's becausepull request's continuous integration checkingis failed — there ispypi-versionchecking integrated.as configured, there are aninstalling of the pypi-version and checking the version by using it,as the result,pypi-versionchecksif release pull request's (fromdeveloptomaster) changes contain an increasing thepackage version numberbefore it will be merged. In the example that is described above there is no increasing the version —pypi-version checkis failed. If one of the declared checking in the configuration file is failed — it means pull request continuous integration checking is failed and pull request does not allowed to be merged with wrong version number.UsageCommand line interfaceTo check if you haven't forgotten to bump thePyPi package version numberbefore you merge a release
pull request:$pypi-versioncheckTo fetch the version of thepypi-versionpackage:$pypi-version--version
pypi-version,version0.1.0To fetch all available package commands, use the following command:$pypi-version--help
Usage:pypi-version[OPTIONS]COMMAND[ARGS]...CommandlineinterfaceforPyPiversionchecking.

Options:--versionShowtheversionandexit.--helpShowthismessageandexit.

Commands:checkCheckifyouhaven'tforgottentobumpthePyPipackageversion.Configuration filepypi-versionrequires a configuration file called.pypi-version.ymlto be located in the root of the project:package
 |
 - ...
 - source
 - README.md
 - setup.py
 - .pypi-version.yml
 ...The configuration file should contains:the section with yourPyPi package namethat is the same with the name in thesetup.py:package:
  name: test-pypi-version-travis-ciname of the continuous integration service you use. Available options are:travis.ci:
  name: travisdevelopmentandreleasebranch names. In the configurations which are illustrated below meanspackage version numberwill be checked only when you do a pull request fromdeveloptomaster.branches:
  development: develop
  release: masterThe full example of the configuration file is:package:
  name: pypi-version

ci:
  name: travis

branches:
  development: develop
  release: masterContinuous integration servicesTravis-CIThe example of the configuration file which install and usepypi-version:language: python

python:
  - "3.6"

install:
  - pip install pypi-version

script:
  - pypi-version checkThe example of the failed build (version hasn't been bumped):CircleCIThe example of the configuration file which install and usepypi-version:version: 2
jobs:
  build:
    docker:
      - image: circleci/python:3.6.4
    steps:
      - checkout
      - run:
          name: Install pypi-version package
          command: sudo pip3 install pypi-version
      - run:
          name: Check if PyPi should be bumped
          command: sudo -H -E pypi-version checkThe example of the failed build (version hasn't been bumped):ContributingClone the project and install requirements:$gitclonegit@github.com:dmytrostriletskyi/pypi-version.git&&cdpypi-version
$pip3install-rrequirements.txt
$pip3install-rrequirements-dev.txt
$pip3install-rrequirements-tests.txtWhen you will make changes, ensure your code passthe checkersand is covered by tests usingpytest.If you are new for the contribution, please read:Read about pull requests —https://help.github.com/en/articles/about-pull-requestsRead how to provide pull request —https://help.github.com/en/articles/creating-a-pull-request-from-a-forkAlso the useful article about how to contribute —https://akrabat.com/the-beginners-guide-to-contributing-to-a-github-project/ReferencesPython packagePython packageis redistributed and reused couple of thePythonscripts. They exist to solve the typical problems. So if
you have common problem in your project — instead of writing own code and spend a time for it, use the package that already have required functionality. The examples ofPython packagesyou should know arerequestsandDjango.Gitflow workflowInstead of a singlemasterbranch, this workflow uses two branches to record the history of the project. Themasterbranch stores the official release history, and thedevelopbranch serves as an integration branch for features.So when you complete the feature, you open the pull request fromfeaturebranch to thedevelopbranch. When you complete the bunch of features, you open the pull request fromdevelopbranch tomasterbranch which are going to merge this bunch of features that means you do new release.According to the changes that contains new features, you should increase your version number (e.g. from1.0.0to1.1.0) in the file calledsetup.pyin the same pull request.Upload to PyPiWhen your features with increased version number have been merged to themasterbranch, you are going to upload your source code to thePython Package Index.Being in the root of you project,package
 |
 - ...
 - source
 - README.md
 - setup.py
 ...you do the following command:$ python3 setup.py sdist
$ twine upload dist/*And if you haven't forgotten to bump thePyPi package version number, the upload is successful.Continuous integration servicesContinuous integration services are useful when you want add some robotic checking for your pull request changes.
For instance, you can run checking code style withflake8and run tests withpytestto check your changes does not break existing functionality on the few version
ofPython. The configuration file example forTravis CIis presented below.language: python

python:
  - "3.4"
  - "3.5"
  - "3.6"
  - "3.7-dev"

install:
  - pip install -r requirements-dev.txt
  - pip install -r requirements-tests.txt

script:
  - cat requirements-tests.txt requirements-dev.txt | safety check --stdin
  - radon cc accessify -nb --total-average
  - isort -rc accessify --diff && isort -rc tests --diff
  - flake8 accessify
  - coverage run -m pytest -vv tests

after_success:
  - coverage report -m && coverage xml
  - bash <(curl -s https://codecov.io/bash)Each pull request the checking report will be presented. By clicking on thedetailsyou will see full report.