-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
executable file
·152 lines (127 loc) · 4.67 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
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
#!/usr/bin/env python
"""
setup.py script for the py_gd package
Tested with:
conda (with conda-forge libgd) on OS_X
On Windows, MacOS and Linux (CentoOS 7)
libgd is assumed to be installed (and its dependencies) already.
The conda package on conda-forge is a good way to get it:
https://anaconda.org/conda-forge/libgd
"""
import sys
import os
import glob
import shutil
from setuptools import setup, Extension
from distutils.command.clean import clean
from Cython.Build import cythonize
import numpy # for the include dirs...
# could run setup from anywhere
SETUP_PATH = os.path.dirname(os.path.abspath(__file__))
include_dirs = [numpy.get_include()]
library_dirs = []
libraries = ['gd']
compile_args = []
link_args = []
if sys.platform.startswith('win'):
# need the library and include for Windows Anaconda... <PREFIX>/Library
include_dirs.append(os.path.join(sys.prefix, r'Library\include'))
# dlls go in bin, rather than lib (??)
library_dirs.append(os.path.join(sys.prefix, r'Library\lib'))
compile_args.append('-EHsc')
link_args.append('/MANIFEST')
elif sys.platform.startswith('linux'):
library_dirs.append('/usr/local/lib')
include_dirs.append('/usr/local/include')
class cleanall(clean):
description = ("cleans files generated by 'develop' mode and files "
"autogenerated by cython")
def run(self):
# call base class clean
clean.run(self)
# clean remaining cython/cpp files
t_path = [os.path.join(SETUP_PATH, 'py_gd')]
exts = ['*.so', 'cy_*.pyd', 'cy_*.cpp', 'cy_*.c']
for temp in t_path:
for ext in exts:
for f in glob.glob(os.path.join(temp, ext)):
print("Deleting auto-generated file: {0}".format(f))
try:
if os.path.isdir(f):
shutil.rmtree(f)
else:
os.remove(f)
except OSError as err:
print("Failed to remove {0}. Error: {1}"
.format(f, err))
# raise
rm_dir = ['py_gd.egg-info', 'build']
for dir_ in rm_dir:
print("Deleting auto-generated directory: {0}".format(dir_))
try:
shutil.rmtree(dir_)
except OSError as err:
if err.errno != 2: # ignore the not-found error
raise
# This setup requires libgd and its dependent libs
# It expects to find them in the "usual" locations
# or where conda puts it...
ext_modules = [
Extension(
"py_gd.py_gd",
["py_gd/py_gd.pyx"],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
"py_gd.spline",
["py_gd/spline.pyx"],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args=compile_args,
extra_link_args=link_args,
)
]
ext_modules = cythonize(
ext_modules,
compiler_directives={'language_level': 3})
def get_version():
"""
get version from __init__.py
"""
with open(os.path.join("py_gd", "__init__.py")) as initfile:
for line in initfile:
line = line.strip()
if line.startswith("__version__"):
version = line.split("=")[1].strip(' "')
return version
setup(name="py_gd",
version=get_version(),
description="python wrappers around libgd graphics lib",
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
author="Christopher H. Barker",
author_email="chris.barker@noaa.gov",
url="https://github.com/NOAA-ORR-ERD/py_gd",
license="Public Domain",
keywords="graphics cython drawing",
cmdclass={'cleanall': cleanall},
ext_modules=cythonize(ext_modules),
zip_safe=False, # dont want a compiled extension in a zipfile...
packages=['py_gd', 'py_gd.test'],
python_requires='>=3.9',
classifiers=["Development Status :: 5 - Production/Stable",
"Topic :: Utilities",
"License :: Public Domain",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Cython",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Multimedia :: Graphics",
],
)