Skip to content

Commit

Permalink
Add version_callback option
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Sep 10, 2020
1 parent 4d57008 commit 4bce22a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,63 @@ jobs:
install:
- pip install "flake8>=3.8" -r requirements.txt
script:
- flake8 --count
- flake8 --count --max-line-length=120
- python setup.py bdist_wheel sdist
- name: "Python 3.8"
dist: xenial
python: '3.8'
install:
- pip install "flake8>=3.8" -r requirements.txt
script:
- flake8 --count
- flake8 --count --max-line-length=120
- python setup.py bdist_wheel sdist
- name: "Python 3.7"
dist: xenial
python: '3.7'
install:
- pip install "flake8>=3.8" -r requirements.txt
script:
- flake8 --count
- flake8 --count --max-line-length=120
- python setup.py bdist_wheel sdist
- name: "Python 3.6"
dist: xenial
python: '3.6'
install:
- pip install "flake8>=3.8" -r requirements.txt
script:
- flake8 --count
- flake8 --count --max-line-length=120
- python setup.py bdist_wheel sdist
- name: "Python 3.5"
dist: xenial
python: '3.5'
install:
- pip install "flake8>=3.8" -r requirements.txt
script:
- flake8 --count
- flake8 --count --max-line-length=120
- python setup.py bdist_wheel sdist
- name: "Python 3.4"
dist: trusty
python: '3.4'
install:
- pip install -I "flake8<=2.6" -r requirements.txt
script:
- flake8 --count --ignore=F401 .
- flake8 --count --ignore=F401 --max-line-length=120 .
- python setup.py bdist_wheel sdist
- name: "Python 3.3"
dist: trusty
python: '3.3'
install:
- pip install -I "flake8<=2.6" -r requirements.txt
script:
- flake8 --count --ignore=F401 .
- flake8 --count --ignore=F401 --max-line-length=120 .
- python setup.py bdist_wheel sdist
- name: "Python 2.7"
dist: xenial
python: '2.7'
install:
- pip install "flake8>=3.8" -r requirements.txt
script:
- flake8 --count
- flake8 --count --max-line-length=120
- python setup.py bdist_wheel sdist
deploy:
- provider: pypi
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ Automatically set package version using git tag/hash

## Compairing with other packages

| Package/Function | Lastest release | Python2 support | Python3 support | PEP 440 compatible | Separated template for not tagged HEAD | Separated template for dirty run | Using functions outside setup.py | Returning starting_version if no tags |
|:----------------------------------------------------------------------------------------------------|----------------:|:---------------:|:---------------:|:------------------:|:--------------------------------------:|:--------------------------------:|:--------------------------------:|:--------------------------------:|
| [setuptools-git-versioning](https://github.com/dolfinus/setuptools-git-versioning) | 2020 | + | + | + | + | + | + | + |
| [setuptools-git-ver](https://github.com/camas/setuptools-git-ver) (Base package) | 2020 | - | + | + | + | + | - | - |
| [even-better-setuptools-git-version](https://github.com/ktemkin/even-better-setuptools-git-version) | 2019 | - | + | + | - | - | + | + |
| [better-setuptools-git-version](https://github.com/vivin/better-setuptools-git-version) | 2018 | - | + | + | - | - | + | + |
| [very-good-setuptools-git-version](https://github.com/Kautenja/very-good-setuptools-git-version) | 2018 | - | + | - | - | - | + | - |
| [setuptools-git-version](https://github.com/pyfidelity/setuptools-git-version) | 2018 | + | + | - | - | - | - | - |
| Package/Function | Lastest release | Python2 support | Python3 support | PEP 440 compatible | Separated template for not tagged HEAD | Separated template for dirty run | Using functions outside setup.py | Returning fixed version if no tags | Returning callback if no tags |
|:----------------------------------------------------------------------------------------------------|----------------:|:---------------:|:---------------:|:------------------:|:--------------------------------------:|:--------------------------------:|:--------------------------------:|:--------------------------------:|:--------------------------------:|
| [setuptools-git-versioning](https://github.com/dolfinus/setuptools-git-versioning) | 2020 | + | + | + | + | + | + | + | + |
| [setuptools-git-ver](https://github.com/camas/setuptools-git-ver) (Base package) | 2020 | - | + | + | + | + | - | - | - |
| [even-better-setuptools-git-version](https://github.com/ktemkin/even-better-setuptools-git-version) | 2019 | - | + | + | - | - | + | + | - |
| [better-setuptools-git-version](https://github.com/vivin/better-setuptools-git-version) | 2018 | - | + | + | - | - | + | + | - |
| [very-good-setuptools-git-version](https://github.com/Kautenja/very-good-setuptools-git-version) | 2018 | - | + | - | - | - | + | - | - |
| [setuptools-git-version](https://github.com/pyfidelity/setuptools-git-version) | 2018 | + | + | - | - | - | - | - | - |

## Installation

Expand Down Expand Up @@ -46,7 +46,8 @@ setuptools.setup(
"template": "{tag}",
"dev_template": "{tag}.dev{ccount}+git.{sha}"
"dirty_template": "{tag}.dev{ccount}+git.{sha}.dirty",
"starting_version": "0.0.1"
"starting_version": "0.0.1",
"version_callback": None,
},
...
setup_requires=['setuptools-git-versioning'],
Expand All @@ -64,6 +65,7 @@ setuptools.setup(

- `starting_version`: static value, used if not tags exist in repo

- `version_callback`: variable or callback function to get version instead of using `starting_version`
### Format Options

- `{tag}`: Latest tag in the repository
Expand Down
12 changes: 10 additions & 2 deletions setuptools_git_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools.dist import Distribution
from distutils.errors import DistutilsSetupError
from typing import List, Optional, Any
from typing import List, Optional, Any, Callable
from six.moves import collections_abc

DEFAULT_TEMPLATE = "{tag}" # type: str
Expand Down Expand Up @@ -87,12 +87,14 @@ def parse_config(dist, _, value): # type: (Distribution, Any, Any) -> None
dev_template = value.get('dev_template', DEFAULT_DEV_TEMPLATE)
dirty_template = value.get('dirty_template', DEFAULT_DIRTY_TEMPLATE)
starting_version = value.get('starting_version', DEFAULT_STARTING_VERSION)
version_callback = value.get('version_callback', None)

version = version_from_git(
template=template,
dev_template=dev_template,
dirty_template=dirty_template,
starting_version=starting_version,
version_callback=version_callback,
)
dist.metadata.version = version

Expand All @@ -101,7 +103,8 @@ def version_from_git(template=DEFAULT_TEMPLATE,
dev_template=DEFAULT_DEV_TEMPLATE,
dirty_template=DEFAULT_DIRTY_TEMPLATE,
starting_version=DEFAULT_STARTING_VERSION,
): # type: (str, str, str, str) -> None
version_callback=None,
): # type: (str, str, str, str, Optional[Any, Callable]) -> str

# Check if PKG-INFO exists and return value in that if it does
if os.path.exists('PKG-INFO'):
Expand All @@ -113,6 +116,11 @@ def version_from_git(template=DEFAULT_TEMPLATE,

tag = get_tag()
if tag is None:
if version_callback is not None:
if callable(version_callback):
return version_callback()
else:
return version_callback
return starting_version

dirty = is_dirty()
Expand Down

0 comments on commit 4bce22a

Please sign in to comment.