Skip to content

Commit 4bce22a

Browse files
committed
Add version_callback option
1 parent 4d57008 commit 4bce22a

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

.travis.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,63 +8,63 @@ jobs:
88
install:
99
- pip install "flake8>=3.8" -r requirements.txt
1010
script:
11-
- flake8 --count
11+
- flake8 --count --max-line-length=120
1212
- python setup.py bdist_wheel sdist
1313
- name: "Python 3.8"
1414
dist: xenial
1515
python: '3.8'
1616
install:
1717
- pip install "flake8>=3.8" -r requirements.txt
1818
script:
19-
- flake8 --count
19+
- flake8 --count --max-line-length=120
2020
- python setup.py bdist_wheel sdist
2121
- name: "Python 3.7"
2222
dist: xenial
2323
python: '3.7'
2424
install:
2525
- pip install "flake8>=3.8" -r requirements.txt
2626
script:
27-
- flake8 --count
27+
- flake8 --count --max-line-length=120
2828
- python setup.py bdist_wheel sdist
2929
- name: "Python 3.6"
3030
dist: xenial
3131
python: '3.6'
3232
install:
3333
- pip install "flake8>=3.8" -r requirements.txt
3434
script:
35-
- flake8 --count
35+
- flake8 --count --max-line-length=120
3636
- python setup.py bdist_wheel sdist
3737
- name: "Python 3.5"
3838
dist: xenial
3939
python: '3.5'
4040
install:
4141
- pip install "flake8>=3.8" -r requirements.txt
4242
script:
43-
- flake8 --count
43+
- flake8 --count --max-line-length=120
4444
- python setup.py bdist_wheel sdist
4545
- name: "Python 3.4"
4646
dist: trusty
4747
python: '3.4'
4848
install:
4949
- pip install -I "flake8<=2.6" -r requirements.txt
5050
script:
51-
- flake8 --count --ignore=F401 .
51+
- flake8 --count --ignore=F401 --max-line-length=120 .
5252
- python setup.py bdist_wheel sdist
5353
- name: "Python 3.3"
5454
dist: trusty
5555
python: '3.3'
5656
install:
5757
- pip install -I "flake8<=2.6" -r requirements.txt
5858
script:
59-
- flake8 --count --ignore=F401 .
59+
- flake8 --count --ignore=F401 --max-line-length=120 .
6060
- python setup.py bdist_wheel sdist
6161
- name: "Python 2.7"
6262
dist: xenial
6363
python: '2.7'
6464
install:
6565
- pip install "flake8>=3.8" -r requirements.txt
6666
script:
67-
- flake8 --count
67+
- flake8 --count --max-line-length=120
6868
- python setup.py bdist_wheel sdist
6969
deploy:
7070
- provider: pypi

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ Automatically set package version using git tag/hash
88

99
## Compairing with other packages
1010

11-
| 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 |
12-
|:----------------------------------------------------------------------------------------------------|----------------:|:---------------:|:---------------:|:------------------:|:--------------------------------------:|:--------------------------------:|:--------------------------------:|:--------------------------------:|
13-
| [setuptools-git-versioning](https://github.com/dolfinus/setuptools-git-versioning) | 2020 | + | + | + | + | + | + | + |
14-
| [setuptools-git-ver](https://github.com/camas/setuptools-git-ver) (Base package) | 2020 | - | + | + | + | + | - | - |
15-
| [even-better-setuptools-git-version](https://github.com/ktemkin/even-better-setuptools-git-version) | 2019 | - | + | + | - | - | + | + |
16-
| [better-setuptools-git-version](https://github.com/vivin/better-setuptools-git-version) | 2018 | - | + | + | - | - | + | + |
17-
| [very-good-setuptools-git-version](https://github.com/Kautenja/very-good-setuptools-git-version) | 2018 | - | + | - | - | - | + | - |
18-
| [setuptools-git-version](https://github.com/pyfidelity/setuptools-git-version) | 2018 | + | + | - | - | - | - | - |
11+
| 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 |
12+
|:----------------------------------------------------------------------------------------------------|----------------:|:---------------:|:---------------:|:------------------:|:--------------------------------------:|:--------------------------------:|:--------------------------------:|:--------------------------------:|:--------------------------------:|
13+
| [setuptools-git-versioning](https://github.com/dolfinus/setuptools-git-versioning) | 2020 | + | + | + | + | + | + | + | + |
14+
| [setuptools-git-ver](https://github.com/camas/setuptools-git-ver) (Base package) | 2020 | - | + | + | + | + | - | - | - |
15+
| [even-better-setuptools-git-version](https://github.com/ktemkin/even-better-setuptools-git-version) | 2019 | - | + | + | - | - | + | + | - |
16+
| [better-setuptools-git-version](https://github.com/vivin/better-setuptools-git-version) | 2018 | - | + | + | - | - | + | + | - |
17+
| [very-good-setuptools-git-version](https://github.com/Kautenja/very-good-setuptools-git-version) | 2018 | - | + | - | - | - | + | - | - |
18+
| [setuptools-git-version](https://github.com/pyfidelity/setuptools-git-version) | 2018 | + | + | - | - | - | - | - | - |
1919

2020
## Installation
2121

@@ -46,7 +46,8 @@ setuptools.setup(
4646
"template": "{tag}",
4747
"dev_template": "{tag}.dev{ccount}+git.{sha}"
4848
"dirty_template": "{tag}.dev{ccount}+git.{sha}.dirty",
49-
"starting_version": "0.0.1"
49+
"starting_version": "0.0.1",
50+
"version_callback": None,
5051
},
5152
...
5253
setup_requires=['setuptools-git-versioning'],
@@ -64,6 +65,7 @@ setuptools.setup(
6465

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

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

6971
- `{tag}`: Latest tag in the repository

setuptools_git_versioning.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from setuptools.dist import Distribution
55
from distutils.errors import DistutilsSetupError
6-
from typing import List, Optional, Any
6+
from typing import List, Optional, Any, Callable
77
from six.moves import collections_abc
88

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

9192
version = version_from_git(
9293
template=template,
9394
dev_template=dev_template,
9495
dirty_template=dirty_template,
9596
starting_version=starting_version,
97+
version_callback=version_callback,
9698
)
9799
dist.metadata.version = version
98100

@@ -101,7 +103,8 @@ def version_from_git(template=DEFAULT_TEMPLATE,
101103
dev_template=DEFAULT_DEV_TEMPLATE,
102104
dirty_template=DEFAULT_DIRTY_TEMPLATE,
103105
starting_version=DEFAULT_STARTING_VERSION,
104-
): # type: (str, str, str, str) -> None
106+
version_callback=None,
107+
): # type: (str, str, str, str, Optional[Any, Callable]) -> str
105108

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

114117
tag = get_tag()
115118
if tag is None:
119+
if version_callback is not None:
120+
if callable(version_callback):
121+
return version_callback()
122+
else:
123+
return version_callback
116124
return starting_version
117125

118126
dirty = is_dirty()

0 commit comments

Comments
 (0)