1
0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-11-24 05:12:02 +01:00

Added ujson.__version__ string (which is synchronized to setup.py's). #19

This commit is contained in:
Hong Minhee 2011-08-16 08:07:17 -04:00
parent 6dc158775d
commit 2c4cb36579
4 changed files with 31 additions and 4 deletions

@ -1,6 +1,8 @@
from distutils.core import setup, Extension
import distutils.sysconfig
import shutil
import os.path
import re
try:
shutil.rmtree("./build")
@ -12,9 +14,22 @@ module1 = Extension('ujson',
include_dirs = ['../'],
library_dirs = ['./lib/'],
libraries=['ujson'])
def get_version():
filename = os.path.join(os.path.dirname(__file__), 'version.h')
file = None
try:
file = open(filename)
header = file.read()
finally:
if file:
file.close()
m = re.search(r'#define\s+UJSON_VERSION\s+"(\d+\.\d+(?:\.\d+)?)"', header)
assert m, "version.h must contain UJSON_VERSION macro"
return m.group(1)
setup (name = 'ujson',
version = '1.0',
version = get_version(),
description = 'Ultra fast JSON encoder and decoder for Python',
ext_modules = [module1],
author = "Jonas Tarnstrom",

@ -12,6 +12,7 @@ import time
import datetime
import calendar
import StringIO
import re
class UltraJSONTests(TestCase):
@ -552,6 +553,10 @@ class UltraJSONTests(TestCase):
pass
else:
assert False, "expected TypeError"
def test_version(self):
assert re.match(r'^\d+\.\d+(\.\d+)?$', ujson.__version__), \
"ujson.__version__ must be a string like '1.4.0'"
"""
def test_decodeNumericIntFrcOverflow(self):

@ -1,4 +1,5 @@
#include <Python.h>
#include "version.h"
/* objToJSON */
PyObject* objToJSON(PyObject* self, PyObject *arg);
@ -29,7 +30,12 @@ static PyMethodDef ujsonMethods[] = {
PyMODINIT_FUNC
initujson(void)
{
initObjToJSON();
Py_InitModule("ujson", ujsonMethods);
PyObject *module;
PyObject *version_string;
initObjToJSON();
module = Py_InitModule("ujson", ujsonMethods);
version_string = PyString_FromString (UJSON_VERSION);
PyModule_AddObject (module, "__version__", version_string);
}

1
python/version.h Normal file

@ -0,0 +1 @@
#define UJSON_VERSION "1.4"