Skip to content

Commit

Permalink
Merge pull request #5 from pyfidelity/version-injection
Browse files Browse the repository at this point in the history
Version injection
  • Loading branch information
tomster authored Jun 22, 2016
2 parents a9331e5 + 008aec0 commit 7dd3929
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ this package allows to extract it from the underlying Git repository:
Changes
-------

1.0.4 - 2016-06-22

- [feature] allow to build a package using a git-based version without modifying it upfront

1.0.3 - 2015-04-23
++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='setuptools-git-version',
version='1.0.3',
version='1.0.4',
url='https://github.com/pyfidelity/setuptools-git-version',
author='pyfidelity UG',
author_email='mail@pyfidelity.com',
Expand Down
21 changes: 20 additions & 1 deletion setuptools_git_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


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


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


def format_version(version, fmt):
def format_version(version, fmt=fmt):
parts = version.split('-')
assert len(parts) in (3, 4)
dirty = len(parts) == 4
tag, count, sha = parts[:3]
if count == '0' and not dirty:
return tag
return fmt.format(tag=tag, commitcount=count, gitsha=sha.lstrip('g'))


if __name__ == "__main__":
# determine version from git
git_version = check_output(command.split()).decode('utf-8').strip()
git_version = format_version(version=git_version)

# monkey-patch `setuptools.setup` to inject the git version
import setuptools
original_setup = setuptools.setup

def setup(version=None, *args, **kw):
return original_setup(version=git_version, *args, **kw)

setuptools.setup = setup

# import the packages's setup module
import setup

0 comments on commit 7dd3929

Please sign in to comment.