Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
177 lines (154 loc) · 6.6 KB
/
Copy pathsetup.py
File metadata and controls
177 lines (154 loc) · 6.6 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from setuptools import setup, find_packages, Extension
from distutils.sysconfig import get_python_inc
import glob
import os
import re
import sys
GMCPP_PC = 'GraphicsMagick++.pc'
IMCPP_PC = 'ImageMagick++.pc'
LIBRARY = 'GraphicsMagick' # default value
include_dirs = [get_python_inc()]
library_dirs = []
#hack for heroku
include_dirs.append('/app/vendor/boost/include/')
library_dirs.append('/app/vendor/boost/include/')
search_include_dirs = ['/usr/local/include/GraphicsMagick/',
'/usr/include/GraphicsMagick/', '/app/bin/gm','/app/vendor/graphicsmagick/bin/gm','/app/vendor/graphicsmagick/include/GraphicsMagick' ]
search_library_dirs = ['/app/vendor/boost/include/','/usr/local/lib64/', '/usr/lib64/',
'/usr/local/lib/', '/usr/lib/', '/app/bin/gm','/app/vendor/graphicsmagick/lib', '/app/vendor/']
search_heroku_library_dirs = ['/app/vendor/boost/include/']
if sys.platform.lower() == 'darwin':
include_dirs.append('/opt/local/include/')
search_include_dirs.extend(['/opt/local/include/GraphicsMagick/',
'/opt/local/include/'])
search_library_dirs.append('/opt/local/lib/')
# for ImageMagick
search_include_dirs.extend(['/usr/local/include/ImageMagick/',
'/usr/include/ImageMagick/'])
if sys.platform.lower() == 'darwin':
search_include_dirs.append('/opt/local/include/ImageMagick/')
def _grep(regex, filename):
for line in open(filename):
if re.search(regex, line):
return line
def get_version_from_devheaders(search_dirs):
target_api_name = "addNoiseChannel"
for dirname in search_dirs:
for root, dirs, files in os.walk(dirname):
for f in files:
if f == 'Image.h':
if _grep(target_api_name, os.path.join(root, 'Image.h')):
return '1.2.0'
def get_version_from_pc(search_dirs, target):
"""similar to 'pkg-config --modversion GraphicsMagick++'"""
search_dirs.append('/usr/local/lib/pkgconfig/')
search_dirs.append('/usr/lib/pkgconfig/')
for dirname in search_dirs:
for root, dirs, files in os.walk(dirname):
for f in files:
if f == target:
_tmp = _grep("\Version: ", dirname + target)
return _tmp.split()[1]
def find_file(filename, search_dirs):
for dirname in search_dirs:
for root, dirs, files in os.walk(dirname):
for f in files:
if filename in f:
return dirname
for d in dirs:
if filename in d:
return dirname
if filename in root:
return dirname
return False
# find to header path
header_path = find_file('Magick++', search_include_dirs)
if not header_path:
raise Exception("Magick++ not found")
print("include header path: %s" % header_path)
include_dirs.append(header_path)
# find to library path for boost_python
# TODO: only test on Ubuntu11.10
_version = sys.version_info
#hack for heroku boost folder
boost_lib = '/app/vendor/boost/include/boost'
lib_path = find_file(boost_lib, search_heroku_library_dirs)
if not lib_path:
#gentoo appends the python version numbers to the boost_python libraries
boost_lib = "boost_python-%s.%s" % (_version[0], _version[1])
lib_path = find_file('lib' + boost_lib, search_library_dirs)
if not lib_path:
if _version >= (3, ):
boost_lib = "boost_python-py%s%s" % (_version[0], _version[1])
lib_path = find_file('lib' + boost_lib, search_library_dirs)
if not lib_path:
boost_lib = "boost_python"
else:
boost_lib = "boost_python"
libraries = [boost_lib]
# find to library path for Magick
lib_path = find_file('libGraphicsMagick++', search_library_dirs)
if lib_path:
libraries.append('GraphicsMagick++')
print("library path: %s%s" % (lib_path, "libGraphicsMagick++"))
else:
lib_path = find_file('libMagick++', search_library_dirs)
if lib_path:
LIBRARY = 'ImageMagick'
libraries.append('Magick++')
print("library path: %s%s" % (lib_path, "libMagick++"))
else:
raise Exception("libGraphicsMagick++ (or libMagick++) not found")
library_dirs.append(lib_path)
# get version and extra compile argument
ext_compile_args = []
if LIBRARY == 'GraphicsMagick':
_version = get_version_from_pc(search_include_dirs, GMCPP_PC)
else:
_version = get_version_from_pc(search_include_dirs, IMCPP_PC)
if not _version:
_version = get_version_from_devheaders(include_dirs)
if _version:
print("%s version: %s" % (LIBRARY, _version))
_version = list(map(int, _version.split('.')))
if len(_version) == 2:
# ex) 1.2 -> 1.2.0
_version.append(0)
if LIBRARY == 'GraphicsMagick':
if _version[0] == 1 and _version[1] == 3 and _version[2] >= 6:
# for not Ubuntu10.04
ext_compile_args = ["-DPGMAGICK_LIB_GRAPHICSMAGICK_1_3_6",
"-DPGMAGICK_LIB_GRAPHICSMAGICK_1_3_x"]
elif not (_version[0] == 1 and _version[1] == 1):
# for GM version 1.3.x and higher
ext_compile_args = ["-DPGMAGICK_LIB_GRAPHICSMAGICK_1_3_x"]
elif LIBRARY == 'ImageMagick':
ext_compile_args = ["-DPGMAGICK_LIB_IMAGEMAGICK"]
else:
_version = '%s version: ???' % (LIBRARY)
setup(name='pgmagick',
version="0.5.5",
description="Yet Another Python wrapper for GraphicsMagick",
long_description=open('README.rst').read(),
author='Hideo Hattori',
author_email='hhatto.jp@gmail.com',
url='http://bitbucket.org/hhatto/pgmagick',
license='MIT',
packages=find_packages(),
ext_modules=[
Extension('pgmagick._pgmagick',
sources=glob.glob('./src/*.cpp'),
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args=ext_compile_args)],
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX',
'Programming Language :: C++',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Multimedia :: Graphics'],
keywords="GraphicsMagick ImageMagick graphics boost image")