afmformats._version

Determine package version from git repository tag

Each time this file is imported it checks whether the package version can be determined using git describe. If this fails (because either this file is not located at the 1st level down the repository root or it is not under version control), the version is read from the script “_version_save.py” which is not versioned by git, but always included in the final distribution archive (e.g. via PyPI). If the git version does not match the saved version, then “_version_save.py” is updated.

Usage

  1. Put this file in your main module directory:

    REPO_ROOT/package_name/_version.py

  2. Add this line to REPO_ROOT/package_name/__init__.py

    from ._version import version as __version__ # noqa: F401

  3. (Optional) Add this line to REPO_ROOT/.gitignore

    _version_save.py

Features

  • supports Python 2 and 3

  • supports frozen applications (e.g. PyInstaller)

  • supports installing into a virtual environment that is located in a git repository

  • saved version is located in a python file and therefore no other files (e.g. MANIFEST.in) need be edited

  • fallback version is the creation date

  • excluded from code coverage via “pragma: no cover”

Changelog

2019-11-06.2
  • use os.path.split instead of counting os.path.sep (Windows)

2019-11-06
  • remove deprecated imp dependency (replace with parser)

  • check whether this file is versioned and its location is correct

  • code cleanup and docs update