Add a __version__ attribute onto the module

When building a module from inside the git tree, the version
will also be "tagged" with the latest commit hash

Change-Id: Ic4b3d4072afcfccbb7bcbe09afc49f950d25e535
This commit is contained in:
R. Tyler Ballance 2010-04-10 17:41:12 -07:00
parent 1c276f4366
commit c3c33b77e3
2 changed files with 14 additions and 2 deletions

View File

@ -11,6 +11,15 @@ try:
except ImportError:
from distutils.core import setup, Extension
version = '0.3.6'
if os.path.exists('.git'):
try:
commit = subprocess.Popen(['git', 'log', '--max-count=1', '--format=%h'], stdout=subprocess.PIPE).communicate()[0]
version = '%s-%s' % (version, commit.strip())
except:
pass
base_modules = [
Extension('yajl', [
'yajl.c',
@ -26,7 +35,7 @@ base_modules = [
'yajl/src/yajl_parser.c',
],
include_dirs=('.', 'includes/', 'yajl/src'),
extra_compile_args=['-Wall',],
extra_compile_args=['-Wall', '-DMOD_VERSION="%s"' % version],
language='c'),
]
@ -37,7 +46,7 @@ packages = ('yajl',)
setup_kwargs = dict(
name = 'yajl',
description = '''A CPython module for Yet-Another-Json-Library''',
version = '0.3.6',
version = version,
author = 'R. Tyler Ballance',
author_email = 'tyler@monkeypox.org',
url = 'http://rtyler.github.com/py-yajl',

3
yajl.c
View File

@ -409,6 +409,9 @@ PyMODINIT_FUNC PyInit_yajl(void)
);
#endif
PyObject *version = PyUnicode_FromString(MOD_VERSION);
PyModule_AddObject(module, "__version__", version);
YajlDecoderType.tp_new = PyType_GenericNew;
if (PyType_Ready(&YajlDecoderType) < 0) {
goto bad_exit;