forked from flupke/pypotrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·102 lines (87 loc) · 3.46 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
#!/usr/bin/env python
import os
import subprocess
from setuptools import setup
from distutils.extension import Extension
# Use Cython version of build_ext if the CYTHONIZE environment variable is set
CYTHONIZE = 'CYTHONIZE' in os.environ
if CYTHONIZE:
from Cython.Distutils import build_ext
else:
from setuptools.command.build_ext import build_ext
# Get numpy include dirs
try:
import numpy
include_dirs = [numpy.get_include()]
except ImportError:
include_dirs = []
def get_flags(flags, prefix):
return [flag[2:].decode() for flag in flags if flag.startswith(prefix.encode())]
def create_ext_obj(name, sources, cython=False, pkg_config_libs=None, **kwargs):
'''
Create an :class:`~distutils.extension.Extension` object for module *name*,
built from *sources*.
*sources* strings are interpolated with the ``{ext}`` named variable.
``ext`` is determined automatically depending on the *cython* argument and
the value of the *language* keyword argument. This way if Cython is
present, Cython source files are compiled to C (typically on a developer
machine), and if it's absent (e.g. on a deployment machine) the existing C
files are compiled.
Any other extra keyword arguments are passed as-is to
:class:`~distutils.extension.Extension` constructor.
'''
if pkg_config_libs is not None:
args = ['pkg-config', '--libs', '--cflags']
args.extend(pkg_config_libs)
pkg_config_output = subprocess.check_output(args)
flags = pkg_config_output.split()
for key, flag in (
('include_dirs', '-I'),
('library_dirs', '-L'),
('libraries', '-l')):
pkg_config_flags = get_flags(flags, flag)
kwargs_value = kwargs.get(key, [])
kwargs_value += pkg_config_flags
kwargs[key] = kwargs_value
if cython:
ext = 'pyx'
elif kwargs.get('language') == 'c++':
ext = 'cpp'
else:
ext = 'c'
sources = [s.format(ext=ext) for s in sources]
return Extension(name=name, sources=sources, **kwargs)
ext_modules = [
create_ext_obj("potrace._potrace", ["potrace/_potrace.{ext}"],
libraries=["potrace"], include_dirs=include_dirs, cython=CYTHONIZE),
create_ext_obj("potrace.bezier", ["potrace/bezier.{ext}"],
pkg_config_libs=['libagg'], language="c++", include_dirs=include_dirs,
cython=CYTHONIZE),
create_ext_obj("potrace.agg.curves", ["potrace/agg/curves.{ext}"],
pkg_config_libs=['libagg'], language="c++", include_dirs=include_dirs,
cython=CYTHONIZE),
]
setup(
name = "pypotrace",
author = "Luper Rouch",
author_email = "luper.rouch@gmail.com",
url = "http://github.com/flupke/pypotrace",
description = "potrace Python bindings",
long_description = open("README.rst").read(),
version = "0.1.3",
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Cython",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
],
packages = ["potrace", "potrace.agg"],
ext_modules = ext_modules,
cmdclass = {"build_ext": build_ext},
)