-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.py
More file actions
126 lines (107 loc) · 3.77 KB
/
setup.py
File metadata and controls
126 lines (107 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import os
from setuptools import Extension, setup
from setuptools.command.build_clib import build_clib
class BuildCLib(build_clib):
"""Builds jsonnet library"""
cflags = {
"msvc": ["/EHsc", "/Ox"],
"unix": [
"-g",
"-O3",
"-Wall",
"-Wextra",
"-Woverloaded-virtual",
"-pedantic",
"-std=c++0x",
"-fPIC",
],
}
def _buildstdlib(self):
"""Builds the byte-array for stdlib."""
with open("jsonnet/stdlib/std.jsonnet", "rb") as f:
stdlib = bytearray(f.read())
with open("jsonnet/core/std.jsonnet.h", "w") as f:
for byte in stdlib:
f.write("%d," % byte)
f.write("0")
def _patchcflags(self, libraries):
"""Add in cflags."""
compiler = self.compiler.compiler_type
args = self.cflags[compiler]
for lib in libraries:
lib[1]["cflags"] = args
def build_libraries(self, libraries):
self._patchcflags(libraries)
self._buildstdlib()
super(BuildCLib, self).build_libraries(libraries)
DIR = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(DIR, 'README.md'), encoding='utf-8') as f:
readme = f.read()
def get_libjsonnet_version():
"""
Parses the version out of libjsonnet.h. This is a copy/paste from official setup.py.
"""
with open(os.path.join(DIR, 'jsonnet/include/libjsonnet.h')) as f:
for line in f:
if '#define' in line and 'LIB_JSONNET_VERSION' in line:
v_code = line.partition('LIB_JSONNET_VERSION')[2].strip('\n "')
if v_code[0] == "v":
v_code = v_code[1:]
return v_code
post_release_segment = "" # ".post0"
"""
The post release segment of jsonnet-binary, appended after version of jsonnet.
It should be defined to release a new version of jsonnet-binary packages, but jsonnet version is still the same.
`See PEP 440 Post Releases <https://www.python.org/dev/peps/pep-0440/#post-releases>`_.
"""
setup(
name="jsonnet-binary",
url="https://github.com/Toilal/python-jsonnet-binary",
description="An UNOFFICIAL Python interface to Jsonnet, "
"available as whl packages for Mac, Linux and Windows.",
long_description=readme,
long_description_content_type='text/markdown',
author="Matt Covalt",
author_email="mcovalt@mailbox.org",
maintainer="Rémi Alvergnat",
maintainer_email="toilal.dev@gmail.com",
version=get_libjsonnet_version() + post_release_segment,
ext_modules=[
Extension(
"_jsonnet",
sources=["jsonnet/python/_jsonnet.c"],
libraries=["jsonnet"],
include_dirs=[
"jsonnet/include",
"jsonnet/third_party/json",
"jsonnet/third_party/md5",
],
language="c++",
)
],
libraries=[
[
"jsonnet",
{
"sources": [
"jsonnet/core/desugarer.cpp",
"jsonnet/core/formatter.cpp",
"jsonnet/core/libjsonnet.cpp",
"jsonnet/core/lexer.cpp",
"jsonnet/core/parser.cpp",
"jsonnet/core/pass.cpp",
"jsonnet/core/static_analysis.cpp",
"jsonnet/core/string_utils.cpp",
"jsonnet/core/vm.cpp",
"jsonnet/third_party/md5/md5.cpp",
],
"include_dirs": [
"jsonnet/include",
"jsonnet/third_party/json",
"jsonnet/third_party/md5",
],
},
]
],
cmdclass={"build_clib": BuildCLib},
)