cde1ceab |
# Miniver
|
ae583efd |
[![license: CC0-1.0](https://img.shields.io/pypi/l/miniver.svg)][cc0]
[![PyPI version](https://img.shields.io/pypi/v/miniver.svg)][pypi]
|
7102465b |
[![Travis build](https://travis-ci.org/jbweston/miniver.svg)][travis]
[![Appveyor build](https://ci.appveyor.com/api/projects/status/v9q0hmjfm9qxdsi4?svg=true)][appveyor]
|
cde1ceab |
**Like [versioneer][versioneer], but smaller**
|
c626bec6 |
Miniver is a **mini**mal **ver**sioning tool that serves the same purpose
|
9a91c583 |
as [Versioneer][versioneer], except that it only works with Git and
multiplatform support is still experimental.
|
cde1ceab |
#### 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
|
aee8d05b |
is that Miniver only works with Git and Python 3.5 (or above).
|
cde1ceab |
|
1a076952 |
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
|
ca2ae3c1 |
works with Python 2](https://github.com/cmarquardt/miniver2)
|
cde1ceab |
[versioneer]: https://github.com/warner/python-versioneer
[cc0]: http://creativecommons.org/publicdomain/zero/1.0/
|
ae583efd |
[pypi]: https://pypi.org/project/miniver/
|
7102465b |
[travis]: https://travis-ci.org/jbweston/miniver
[appveyor]: https://ci.appveyor.com/project/jbweston/miniver
|
cde1ceab |
## Usage
|
eefedd80 |
The simplest way to use Miniver is to run the following in your project root:
```
|
10679ce5 |
curl https://raw.githubusercontent.com/jbweston/miniver/master/bin/miniver | python - install <your_package_directory>
|
eefedd80 |
```
This will grab the latest files from GitHub and set up Miniver for your project.
|
cde1ceab |
|
8efa6e65 |
### 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*](https://git-scm.com/book/en/v2/Git-Basics-Tagging)
so that Miniver reports a reasonable version.
If your project uses *unannotated tags* for versioning (though this is not the
[recommended way](https://stackoverflow.com/questions/11514075/what-is-the-difference-between-an-annotated-and-unannotated-tag))
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
```
|
eefedd80 |
### I don't want to type that URL every time I use this
|
10679ce5 |
You can `pip install miniver`, which will give you the `miniver` command.
|
eefedd80 |
Then you can simply run the following from your project root to use Miniver:
```
|
10679ce5 |
miniver install <your_package_directory>
|
eefedd80 |
```
### 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:
|
cde1ceab |
```python
# Your package's __init__.py
|
8dddbd2e |
from ._version import __version__
del _version
|
cde1ceab |
```
```python
# Your project's setup.py
|
8dddbd2e |
# Loads _version.py module without importing the whole package.
|
cde1ceab |
def get_version_and_cmdclass(package_name):
import os
from importlib.util import module_from_spec, spec_from_file_location
spec = spec_from_file_location('version',
|
8dddbd2e |
os.path.join(package_name, '_version.py'))
|
cde1ceab |
module = module_from_spec(spec)
spec.loader.exec_module(module)
|
8dddbd2e |
return module.__version__, module.cmdclass
|
cde1ceab |
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.
|