Skip to content
This repository was archived by the owner on Mar 8, 2018. It is now read-only.

Commit c3c33b7

Browse files
author
R. Tyler Ballance
committed
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
1 parent 1c276f4 commit c3c33b7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

setup.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
except ImportError:
1212
from distutils.core import setup, Extension
1313

14+
version = '0.3.6'
15+
if os.path.exists('.git'):
16+
try:
17+
commit = subprocess.Popen(['git', 'log', '--max-count=1', '--format=%h'], stdout=subprocess.PIPE).communicate()[0]
18+
version = '%s-%s' % (version, commit.strip())
19+
except:
20+
pass
21+
22+
1423
base_modules = [
1524
Extension('yajl', [
1625
'yajl.c',
@@ -26,7 +35,7 @@
2635
'yajl/src/yajl_parser.c',
2736
],
2837
include_dirs=('.', 'includes/', 'yajl/src'),
29-
extra_compile_args=['-Wall',],
38+
extra_compile_args=['-Wall', '-DMOD_VERSION="%s"' % version],
3039
language='c'),
3140
]
3241

@@ -37,7 +46,7 @@
3746
setup_kwargs = dict(
3847
name = 'yajl',
3948
description = '''A CPython module for Yet-Another-Json-Library''',
40-
version = '0.3.6',
49+
version = version,
4150
author = 'R. Tyler Ballance',
4251
author_email = '[email protected]',
4352
url = 'http://rtyler.github.com/py-yajl',

yajl.c

+3
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ PyMODINIT_FUNC PyInit_yajl(void)
409409
);
410410
#endif
411411

412+
PyObject *version = PyUnicode_FromString(MOD_VERSION);
413+
PyModule_AddObject(module, "__version__", version);
414+
412415
YajlDecoderType.tp_new = PyType_GenericNew;
413416
if (PyType_Ready(&YajlDecoderType) < 0) {
414417
goto bad_exit;

0 commit comments

Comments
 (0)