Skip to content

Commit 7dd3929

Browse files
authored
Merge pull request #5 from pyfidelity/version-injection
Version injection
2 parents a9331e5 + 008aec0 commit 7dd3929

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ this package allows to extract it from the underlying Git repository:
3030
Changes
3131
-------
3232

33+
1.0.4 - 2016-06-22
34+
35+
- [feature] allow to build a package using a git-based version without modifying it upfront
36+
3337
1.0.3 - 2015-04-23
3438
++++++++++++++++++
3539

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='setuptools-git-version',
6-
version='1.0.3',
6+
version='1.0.4',
77
url='https://github.com/pyfidelity/setuptools-git-version',
88
author='pyfidelity UG',
99
author_email='[email protected]',

setuptools_git_version.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
command = 'git describe --tags --long --dirty'
6+
fmt = '{tag}.{commitcount}+{gitsha}'
67

78

89
def validate_version_format(dist, attr, value):
@@ -15,11 +16,29 @@ def validate_version_format(dist, attr, value):
1516
dist.metadata.version = version
1617

1718

18-
def format_version(version, fmt):
19+
def format_version(version, fmt=fmt):
1920
parts = version.split('-')
2021
assert len(parts) in (3, 4)
2122
dirty = len(parts) == 4
2223
tag, count, sha = parts[:3]
2324
if count == '0' and not dirty:
2425
return tag
2526
return fmt.format(tag=tag, commitcount=count, gitsha=sha.lstrip('g'))
27+
28+
29+
if __name__ == "__main__":
30+
# determine version from git
31+
git_version = check_output(command.split()).decode('utf-8').strip()
32+
git_version = format_version(version=git_version)
33+
34+
# monkey-patch `setuptools.setup` to inject the git version
35+
import setuptools
36+
original_setup = setuptools.setup
37+
38+
def setup(version=None, *args, **kw):
39+
return original_setup(version=git_version, *args, **kw)
40+
41+
setuptools.setup = setup
42+
43+
# import the packages's setup module
44+
import setup

0 commit comments

Comments
 (0)