-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from PaulFurtado/master
Added a python distutils setup.py for easy installation as a python package
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include * | ||
recursive-include * * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
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', | ||
url='https://google.github.io/jsonnet/doc/', | ||
description='Python bindings for Jsonnet - The data templating language ', | ||
author='David Cunningham', | ||
author_email='[email protected]', | ||
version=get_version(), | ||
cmdclass={'build': CustomBuild}, | ||
ext_modules=[Extension('_jsonnet', extra_compile_args=COMPILE_ARGS, | ||
sources=JSONNET_SOURCES)] | ||
) |