-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.py
executable file
·109 lines (93 loc) · 3.32 KB
/
setup.py
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
#!/usr/bin/env python
from distutils.core import setup
from distutils.extension import Extension
from distutils.command import build_ext
from my_build_ext import build_ext as _link_build_ext
from distutils.util import strtobool
import os
EMBED = strtobool(os.environ.get("EMBED", "1"))
if not os.path.exists("fribidi-src"):
EMBED = False
class my_build_ext(_link_build_ext):
def build_extension(self, ext):
configure = os.path.abspath("fribidi-src/configure")
bdir = os.path.join(self.build_temp, "fribidi")
if not os.path.isdir(bdir):
os.makedirs(bdir)
cwd = os.getcwd()
os.chdir(bdir)
try:
if not os.path.exists("./config.status"):
os.system("sh %s --with-glib=no" % configure)
finally:
os.chdir(cwd)
self.include_dirs[:0] = [bdir, "%s/lib" % bdir]
self.compiler.set_include_dirs(self.include_dirs)
return _link_build_ext.build_extension(self, ext)
def _getpkgconfigvalue(value, package="fribidi"):
""" get a value from pkg-config for package (default: fribidi)
param value: long-option to pkg-config
"""
f = os.popen("pkg-config --%s %s" % (value, package))
x = f.readline().strip()
f.close()
l = []
for y in x.split(" "):
l.append(y[2:])
return [x.strip() for x in l if x.strip()]
if not EMBED:
lib_sources = []
include_dirs = _getpkgconfigvalue("cflags-only-I") or ["/usr/include/fribidi"]
libraries = _getpkgconfigvalue("libs-only-l") or ["fribidi"]
define_macros = []
my_build_ext = _link_build_ext
else:
lib_sources = """
fribidi-src/lib/fribidi.c
fribidi-src/lib/fribidi-arabic.c
fribidi-src/lib/fribidi-bidi.c
fribidi-src/lib/fribidi-bidi-types.c
fribidi-src/lib/fribidi-deprecated.c
fribidi-src/lib/fribidi-joining.c
fribidi-src/lib/fribidi-joining-types.c
fribidi-src/lib/fribidi-mem.c
fribidi-src/lib/fribidi-mirroring.c
fribidi-src/lib/fribidi-run.c
fribidi-src/lib/fribidi-shape.c
fribidi-src/charset/fribidi-char-sets-cp1256.c
fribidi-src/charset/fribidi-char-sets-iso8859-8.c
fribidi-src/charset/fribidi-char-sets-cap-rtl.c
fribidi-src/charset/fribidi-char-sets-utf8.c
fribidi-src/charset/fribidi-char-sets.c
fribidi-src/charset/fribidi-char-sets-cp1255.c
fribidi-src/charset/fribidi-char-sets-iso8859-6.c
""".split()
libraries = []
include_dirs = ["fribidi-src", "fribidi-src/lib", "fribidi-src/charset"]
define_macros = [("HAVE_CONFIG_H", 1)]
def get_version():
d = {}
try:
exec(compile(open("pyfribidi.py", "rb").read(), "pyfribidi.py", 'exec'), d, d)
except (ImportError, RuntimeError):
pass
return d["__version__"]
setup(name="pyfribidi",
version=get_version(),
description="Python libfribidi interface",
author="Yaacov Zamir, Nir Soffer",
author_email="[email protected]",
url="https://github.com/pediapress/pyfribidi",
license="GPL",
install_requires=[
"six",
],
cmdclass={'build_ext': my_build_ext},
long_description=open("README.rst").read(),
py_modules=["pyfribidi", "pyfribidi2"],
ext_modules=[Extension(
name='_pyfribidi',
sources=['pyfribidi.c'] + lib_sources,
define_macros=define_macros,
libraries=libraries,
include_dirs=include_dirs)])