From f10d2b7b3f0c67d81b175326035e4813420156bd Mon Sep 17 00:00:00 2001
From: "W. Trevor King" <wking@tremily.us>
Date: Thu, 13 Sep 2012 07:52:22 -0400
Subject: [PATCH] pygit2:version: add 'pygit2.__version__' for easy access from
 client software.

Moved the hardcoded version from setup.py to pygit2/version.py so
client software can figure out which version of pygit2 it's using.
Having setup.py import pygit2.version.__version__ removes duplication,
and also means that setup.py will always use the local version (and
not the version of a previously installed pygit2).
---
 pygit2/__init__.py |  1 +
 pygit2/version.py  | 26 ++++++++++++++++++++++++++
 setup.py           |  7 ++++++-
 3 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 pygit2/version.py

diff --git a/pygit2/__init__.py b/pygit2/__init__.py
index 151fcaf..6a0e24b 100644
--- a/pygit2/__init__.py
+++ b/pygit2/__init__.py
@@ -25,5 +25,6 @@
 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
+from .version import __version__
 from _pygit2 import *
 import pygit2.utils
diff --git a/pygit2/version.py b/pygit2/version.py
new file mode 100644
index 0000000..e5179fc
--- /dev/null
+++ b/pygit2/version.py
@@ -0,0 +1,26 @@
+# Copyright 2012 The pygit2 contributors
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License, version 2,
+# as published by the Free Software Foundation.
+#
+# In addition to the permissions in the GNU General Public License,
+# the authors give you unlimited permission to link the compiled
+# version of this file into combinations with other programs,
+# and to distribute those combinations without any restriction
+# coming from the use of this file.  (The General Public License
+# restrictions do apply in other respects; for example, they cover
+# modification of the file, and distribution when not linked into
+# a combined executable.)
+#
+# This file is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING.  If not, write to
+# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+__version__ = '0.17.2'
diff --git a/setup.py b/setup.py
index 4722427..7a8dce8 100644
--- a/setup.py
+++ b/setup.py
@@ -38,6 +38,11 @@ from distutils.command.build import build
 from distutils.command.sdist import sdist
 from distutils import log
 
+# read version from local pygit2/version.py without pulling in
+# pygit2/__init__.py
+sys.path.insert(0, 'pygit2')
+from version import __version__
+
 
 # Use environment variable LIBGIT2 to set your own libgit2 configuration.
 libgit2_path = os.getenv("LIBGIT2")
@@ -163,7 +168,7 @@ with open('README.rst') as readme:
 setup(name='pygit2',
       description='Python bindings for libgit2.',
       keywords='git',
-      version='0.17.2',
+      version=__version__,
       url='http://github.com/libgit2/pygit2',
       classifiers=classifiers,
       license='GPLv2',