Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python changes #247

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ commands:
sudo npm install --global coveralls
coveralls <coverage.info
fi
python:
description: "Build the Python bindings"
steps:
- run: |
sudo apt-get -qq install --no-install-recommends python3{-minimal,-pip,-dev}

python3 -m pip install --user --upgrade pip wheel setuptools
python3 python/setup.py sdist bdist_wheel

for dist in dist/*; do
python3 -m pip install --user --install-option build_ext --install-option "--library-dirs /usr/lib/x86_64-linux-gnu/" "$dist"
python3 -c "import ucl"
# relative path tests fail if we don't cd
pushd python
python3 -m unittest discover
popd
python3 -m pip uninstall -y ucl
done

executors:
debian:
Expand All @@ -64,6 +82,7 @@ jobs:
- build_cmake
- build_autotools
- code_coverage
- python

workflows:
version: 2
Expand Down
5 changes: 5 additions & 0 deletions python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include COPYING
recursive-include include *.h
recursive-include src *.h
recursive-include klib *.h
recursive-include uthash *.h
34 changes: 30 additions & 4 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
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

Expand All @@ -13,16 +16,35 @@

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.1',
description = 'ucl parser and emmitter',
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",
Expand All @@ -41,3 +63,7 @@
"Topic :: Software Development :: Libraries",
]
)

# clean up the trick after the build
if in_ucl_root:
os.unlink("setup.py")
17 changes: 16 additions & 1 deletion python/tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,22 @@ def test_comment_ignored(self):
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)

Expand Down