Skip to main content

Miniver

license: CC0-1.0 PyPI version CI status

Like versioneer, but smaller

Miniver is a minimal versioning tool that serves the same purpose as Versioneer, except that it only works with Git and multiplatform support is still experimental.

Why would I use this?

If you are developing a Python package inside a Git repository and want to get the version directly from Git tags, rather than hard-coding version strings everywhere.

This is the same problem that Versioneer solves, but Miniver is less than 200 lines of code, whereas Versioneer is over 2000. The tradeoff is that Miniver only works with Git and Python 3.5 (or above).

Support for Python 2 is not a goal, as Python 2 is fast approaching its end of life (2020), and we want to encourage people to use Python 3! That being said, Christian Marquardt has a fork that also works with Python 2

Usage

The simplest way to use Miniver is to run the following in your project root:

curl https://raw.githubusercontent.com/jbweston/miniver/master/miniver/app.py | python - install <your_package_directory>

This will grab the latest files from GitHub and set up Miniver for your project.

I get an unknown version!

The version is reported as unknown (plus the current git hash) when there are no valid tags in the git history. You should create an annotated tag so that Miniver reports a reasonable version.

If your project uses unannotated tags for versioning (though this is not the recommended way) then you'll need to run the following in order to modify Miniver's behaviour:

curl https://raw.githubusercontent.com/jbweston/miniver/master/unannotated-tags.patch | patch <your_package_directory>/_version.py

I don't want to type that URL every time I use this

You can pip install miniver, which will give you the miniver command. Then you can simply run the following from your project root to use Miniver:

miniver install <your_package_directory>

Can I use this without executing random code from the internet?

Sure! Copy miniver/_version.py and miniver/_static_version.py from this repository into your package directory, then copy the following snippets into the appropriate files:

# Your package's __init__.py
from ._version import __version__
del _version
# Your project's setup.py

from setuptools import setup

# Loads _version.py module without importing the whole package.
def get_version_and_cmdclass(pkg_path):
    import os
    from importlib.util import module_from_spec, spec_from_file_location
    spec = spec_from_file_location(
        'version', os.path.join(pkg_path, '_version.py'),
    )
    module = module_from_spec(spec)
    spec.loader.exec_module(module)
    return module.__version__, module.get_cmdclass(pkg_path)


version, cmdclass = get_version_and_cmdclass('my_package')

setup(
    name='my_package',
    version=version,
    cmdclass=cmdclass,
)
# Your project's .gitattributes
my_package/_static_version.py export-subst

replacing 'my_package' in the above with the name of your package (this should be the same as the name of the directory into which you copied the contents of miniver).

That's it!

License

Miniver is in the public domain under a CC0 license.

Metadata

Release files for miniver 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for miniver 0.8.0
File Size Uploaded
miniver-0.8.0.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for miniver 0.8.0
File Interpreter ABI Platform
miniver-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.3 kB

Release files / miniver-0.8.0.tar.gz

Download URL miniver-0.8.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a327a34ea251b7215d2832d568a9488bbceceff77fd2220233d0979198d021ee
BLAKE2b-256 checksum
How to use checksums
66ffc0cdc845e8f6eacf5b309f949e85be84eb42c6fa64b95403534565a6a716
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.1

Release files / miniver-0.8.0-py3-none-any.whl

Download URL miniver-0.8.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6064cc1abdae48d3ee8aeb0570f549cdf09a8f9791d319a137d176f5458bbe30
BLAKE2b-256 checksum
How to use checksums
65e5e9e0964cc49149fce8853dcaa3832fa978e4ae7838b51440f7eaee2e74b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page