summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/MANIFEST.in5
-rw-r--r--python/setup.py42
-rw-r--r--python/src/uclmodule.c3
-rw-r--r--python/tests/test_example.py59
-rw-r--r--python/tests/test_load.py17
5 files changed, 119 insertions, 7 deletions
diff --git a/python/MANIFEST.in b/python/MANIFEST.in
new file mode 100644
index 000000000000..336a4b3a7a07
--- /dev/null
+++ b/python/MANIFEST.in
@@ -0,0 +1,5 @@
+include COPYING
+recursive-include include *.h
+recursive-include src *.h
+recursive-include klib *.h
+recursive-include uthash *.h
diff --git a/python/setup.py b/python/setup.py
index 9e1151a1323a..8da832bac381 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -1,11 +1,20 @@
try:
from setuptools import setup, Extension
+ # setuptools doesn't support template param for MANIFEST.in
+ from setuptools.command.egg_info import manifest_maker
+ manifest_maker.template = 'python/MANIFEST.in'
except ImportError:
from distutils.core import setup, Extension
import os
import sys
+LIB_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir))
+if os.getcwd() != LIB_ROOT:
+ os.chdir(LIB_ROOT)
+if LIB_ROOT not in sys.path:
+ sys.path.append(LIB_ROOT)
+
tests_require = []
if sys.version < '2.7':
@@ -13,16 +22,35 @@ if sys.version < '2.7':
uclmodule = Extension(
'ucl',
- libraries = ['ucl'],
- sources = ['src/uclmodule.c'],
- language = 'c'
+ libraries=['ucl', 'curl'],
+ sources=['python/src/uclmodule.c'],
+ include_dirs=['include'],
+ language='c',
)
+ucl_lib = {
+ 'sources': ['src/' + fn for fn in os.listdir('src') if fn.endswith('.c')],
+ 'include_dirs': ['include', 'src', 'uthash', 'klib'],
+ 'macros': [('CURL_FOUND', '1')],
+}
+
+# sdist setup() will pull in the *.c files automatically, but not headers
+# MANIFEST.in will include the headers for sdist only
+template = 'python/MANIFEST.in'
+
+# distutils assume setup.py is in the root of the project
+# we need to include C source from the parent so trick it
+in_ucl_root = 'setup.py' in os.listdir('python')
+if in_ucl_root:
+ os.link('python/setup.py', 'setup.py')
+
setup(
name = 'ucl',
- version = '0.8',
- description = 'ucl parser and emmitter',
+ version = '0.8.1',
+ description = 'ucl parser and emitter',
ext_modules = [uclmodule],
+ template=template, # no longer supported with setuptools but doesn't hurt
+ libraries = [('ucl', ucl_lib)],
test_suite = 'tests',
tests_require = tests_require,
author = "Eitan Adler, Denis Volpato Martins",
@@ -41,3 +69,7 @@ setup(
"Topic :: Software Development :: Libraries",
]
)
+
+# clean up the trick after the build
+if in_ucl_root:
+ os.unlink("setup.py")
diff --git a/python/src/uclmodule.c b/python/src/uclmodule.c
index fce0dab14a44..d1051fbb0d12 100644
--- a/python/src/uclmodule.c
+++ b/python/src/uclmodule.c
@@ -80,7 +80,8 @@ static PyObject *
_internal_load_ucl (char *uclstr)
{
PyObject *ret;
- struct ucl_parser *parser = ucl_parser_new (UCL_PARSER_NO_TIME);
+ struct ucl_parser *parser =
+ ucl_parser_new (UCL_PARSER_NO_TIME|UCL_PARSER_NO_IMPLICIT_ARRAYS);
bool r = ucl_parser_add_string(parser, uclstr, 0);
if (r) {
diff --git a/python/tests/test_example.py b/python/tests/test_example.py
new file mode 100644
index 000000000000..f0785531f4e2
--- /dev/null
+++ b/python/tests/test_example.py
@@ -0,0 +1,59 @@
+from .compat import unittest
+import json
+import ucl
+
+_ucl_inp = '''
+param = value;
+section {
+ param = value;
+ param1 = value1;
+ flag = true;
+ number = 10k;
+ time = 0.2s;
+ string = "something";
+ subsection {
+ host = {
+ host = "hostname";
+ port = 900;
+ }
+ host = {
+ host = "hostname";
+ port = 901;
+ }
+ }
+}
+'''
+
+_json_res = {
+ 'param': 'value',
+ 'section': {
+ 'param': 'value',
+ 'param1': 'value1',
+ 'flag': True,
+ 'number': 10000,
+ 'time': '0.2s',
+ 'string': 'something',
+ 'subsection': {
+ 'host': [
+ {
+ 'host': 'hostname',
+ 'port': 900,
+ },
+ {
+ 'host': 'hostname',
+ 'port': 901,
+ }
+ ]
+ }
+ }
+}
+
+class TestExample(unittest.TestCase):
+ def test_example(self):
+ # load in sample UCL
+ u = ucl.load(_ucl_inp)
+
+ # Output and read back the JSON
+ uj = json.loads(json.dumps(u))
+
+ self.assertEqual(uj, _json_res)
diff --git a/python/tests/test_load.py b/python/tests/test_load.py
index 786587a67f3d..73d43188f3d5 100644
--- a/python/tests/test_load.py
+++ b/python/tests/test_load.py
@@ -71,7 +71,22 @@ class LoadTest(unittest.TestCase):
self.assertEqual(ucl.load("{/*1*/}"), {})
def test_1_in(self):
- valid = { 'key1': 'value' }
+ valid = {
+ 'key1': [
+ 'value',
+ 'value2',
+ 'value;',
+ 1.0,
+ -0xdeadbeef,
+ '0xdeadbeef.1',
+ '0xreadbeef',
+ -1e-10,
+ 1,
+ True,
+ False,
+ True,
+ ]
+ }
with open("../tests/basic/1.in", "r") as in1:
self.assertEqual(ucl.load(in1.read()), valid)