From 9803857bd8fcaba632516062b27e343ba83ba43f Mon Sep 17 00:00:00 2001 From: Paul Furtado Date: Wed, 11 Mar 2015 02:39:21 -0400 Subject: [PATCH 1/2] Added a python distutils setup.py for easy installation as a python package --- setup.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..cc2859313 --- /dev/null +++ b/setup.py @@ -0,0 +1,44 @@ + +import os +from distutils.core import setup, Extension +from distutils.command.build import build as DistutilsBuild +from subprocess import Popen + + +DIR = os.path.abspath(os.path.dirname(__file__)) +JSONNET_SOURCES = ['libjsonnet.cpp', 'lexer.cpp', 'parser.cpp', 'static_analysis.cpp', 'vm.cpp', '_jsonnet.c'] +COMPILE_ARGS = ['-std=c++0x'] + + +def get_version(): + """ + Parses the version out of jsonnet.cpp + """ + with open(os.path.join(DIR, 'jsonnet.cpp')) as f: + for line in f: + if '#define' in line and 'JSONNET_VERSION' in line: + return line.partition('JSONNET_VERSION')[2].strip('\n "') + + +def make_std_lib(): + """ + Runs the jsonnet C makefile to build std.jsonnet.h + """ + p = Popen(['make', 'std.jsonnet.h'], cwd=DIR) + p.wait() + if p.returncode != 0: + raise Exception('Could not build std.jsonnet.h') + + +class CustomBuild(DistutilsBuild): + def run(self): + make_std_lib() + DistutilsBuild.run(self) + + +setup(name='_jsonnet', + version=get_version(), + cmdclass={'build': CustomBuild}, + ext_modules=[Extension('_jsonnet', extra_compile_args=COMPILE_ARGS, + sources=JSONNET_SOURCES)] +) From d19d0e0ff73eed0b50e01d0cef23ad3f67e8de59 Mon Sep 17 00:00:00 2001 From: Paul Furtado Date: Thu, 12 Mar 2015 01:36:53 -0400 Subject: [PATCH 2/2] Add more metadata and ensure that all files make it into the package --- MANIFEST.in | 2 ++ setup.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000..f101b4bda --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include * +recursive-include * * diff --git a/setup.py b/setup.py index cc2859313..7f2b450cc 100644 --- a/setup.py +++ b/setup.py @@ -36,9 +36,13 @@ def run(self): DistutilsBuild.run(self) -setup(name='_jsonnet', +setup(name='jsonnet', + url='https://google.github.io/jsonnet/doc/', + description='Python bindings for Jsonnet - The data templating language ', + author='David Cunningham', + author_email='dcunnin@google.com', version=get_version(), cmdclass={'build': CustomBuild}, ext_modules=[Extension('_jsonnet', extra_compile_args=COMPILE_ARGS, - sources=JSONNET_SOURCES)] + sources=JSONNET_SOURCES)] )