Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit c3c33b77e31f2aaca290d19d851bfa73275765d9 1 parent 1c276f4
@rtyler authored
Showing with 14 additions and 2 deletions.
  1. +11 −2 setup.py
  2. +3 −0  yajl.c
View
13 setup.py
@@ -11,6 +11,15 @@
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 @@
'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 @@
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',
View
3  yajl.c
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.