Skip to content

Commit 85439b4

Browse files
committed
Add starting_version option
1 parent b2293fa commit 85439b4

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python.linting.pylintEnabled": false,
3+
"python.linting.flake8Enabled": true,
4+
"python.linting.enabled": true
5+
}

readme.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ Automatically set package version using git tag/hash
77

88
## Compairing with other packages
99

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

1919
## Installation
2020

@@ -44,7 +44,8 @@ setuptools.setup(
4444
version_config={
4545
"template": "{tag}",
4646
"dev_template": "{tag}.dev{ccount}+git.{sha}"
47-
"dirty_template": "{tag}.dev{ccount}+git.{sha}.dirty"
47+
"dirty_template": "{tag}.dev{ccount}+git.{sha}.dirty",
48+
"starting_version": "0.0.1"
4849
},
4950
...
5051
setup_requires=['setuptools-git-versioning'],
@@ -60,6 +61,8 @@ setuptools.setup(
6061

6162
- `dirty_template`: used if untracked files exist or uncommitted changes have been made
6263

64+
- `starting_version`: static value, used if not tags exist in repo
65+
6366
### Format Options
6467

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

setuptools_git_versioning.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
DEFAULT_TEMPLATE = "{tag}" # type: str
1414
DEFAULT_DEV_TEMPLATE = "{tag}.dev{ccount}+git.{sha}" # type: str
1515
DEFAULT_DIRTY_TEMPLATE = "{tag}.dev{ccount}+git.{sha}.dirty" # type: str
16+
DEFAULT_STARTING_VERSION = '0.0.1'
1617

1718

1819
def _exec(cmd): # type: (str) -> List[str]
@@ -72,24 +73,25 @@ def parse_config(dist, _, value): # type: (Distribution, Any, Any) -> None
7273
if not isinstance(value, Mapping):
7374
raise DistutilsSetupError("Config in the wrong format")
7475

75-
template = value['template'] if 'template' in value else DEFAULT_TEMPLATE
76-
dev_template = value['dev_template'] if 'dev_template' in value \
77-
else DEFAULT_DEV_TEMPLATE
78-
dirty_template = value['dirty_template'] if 'dirty_template' in value \
79-
else DEFAULT_DIRTY_TEMPLATE
76+
template = value.get('template', DEFAULT_TEMPLATE)
77+
dev_template = value.get('dev_template', DEFAULT_DEV_TEMPLATE)
78+
dirty_template = value.get('dirty_template', DEFAULT_DIRTY_TEMPLATE)
79+
starting_version = value.get('starting_version', DEFAULT_STARTING_VERSION)
8080

8181
version = version_from_git(
8282
template=template,
8383
dev_template=dev_template,
8484
dirty_template=dirty_template,
85+
starting_version=starting_version,
8586
)
8687
dist.metadata.version = version
8788

8889

8990
def version_from_git(template=DEFAULT_TEMPLATE,
9091
dev_template=DEFAULT_DEV_TEMPLATE,
9192
dirty_template=DEFAULT_DIRTY_TEMPLATE,
92-
): # type: (str, str, str) -> None
93+
starting_version=DEFAULT_STARTING_VERSION,
94+
): # type: (str, str, str, str) -> None
9395

9496
# Check if PKG-INFO exists and return value in that if it does
9597
if os.path.exists('PKG-INFO'):
@@ -101,7 +103,7 @@ def version_from_git(template=DEFAULT_TEMPLATE,
101103

102104
tag = get_tag()
103105
if tag is None:
104-
raise Exception("Couldn't find tag to use.")
106+
return starting_version
105107

106108
dirty = is_dirty()
107109
tag_sha = get_sha(tag)

0 commit comments

Comments
 (0)