forked from hhuangwx/cmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
86 lines (72 loc) · 2.8 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
from glob import glob
from setuptools import setup
import os
VERSION = '1.0.2'
CMAPSFILE_DIR = os.path.join('./cmaps/colormaps')
def write_version_py(version=VERSION, filename='cmaps/_version.py'):
cnt = '# THIS FILE IS GENERATED FROM SETUP.PY\n' + \
'__version__ = "%(version)s"\n'
a = open(filename, 'w')
try:
a.write(cnt % {'version': version})
finally:
a.close()
def _listfname():
l = {}
l.update({'ncl': {
'p': 'os.path.join(CMAPSFILE_DIR, "ncar_ncl", ',
'l': sorted(glob(os.path.join(CMAPSFILE_DIR, 'ncar_ncl/*.rgb')))}})
l.update({'self_defined': {
'p': 'os.path.join(CMAPSFILE_DIR, "self_defined", ',
'l': sorted(glob(os.path.join(CMAPSFILE_DIR, 'self_defined/*.rgb')))}})
return l
def write_cmaps(template_file='./cmaps.template'):
with open(template_file, 'rt') as f:
c = f.read()
l = _listfname()
for t in l.keys():
for cmap_file in l[t]['l']:
cname = os.path.basename(cmap_file).split('.rgb')[0]
# start with the number will result illegal attribute
if cname[0].isdigit() or cname.startswith('_'):
cname = 'N' + cname
if '-' in cname:
cname = cname.replace('-', '_')
if '+' in cname:
cname = cname.replace('+', '_')
c += ' @property\n'
c += ' def {}(self):\n'.format(cname)
c += ' cname = "{}"\n'.format(cname)
c += ' cmap_file = {} "{}")\n'.format(
l[t]['p'], os.path.basename(cmap_file))
c += ' cmap = Colormap(self._coltbl(cmap_file), name=cname)\n'
c += ' matplotlib.cm.register_cmap(name=cname, cmap=cmap)\n'
c += ' return cmap\n\n'
c += ' @property\n'
c += ' def {}(self):\n'.format(cname + '_r')
c += ' cname = "{}"\n'.format(cname + '_r')
c += ' cmap_file = {} "{}")\n'.format(
l[t]['p'], os.path.basename(cmap_file))
c += ' cmap = Colormap(self._coltbl(cmap_file)[::-1], name=cname)\n'
c += ' matplotlib.cm.register_cmap(name=cname, cmap=cmap)\n'
c += ' return cmap\n\n'
cmapspy = './cmaps/cmaps.py'
with open(cmapspy, 'wt') as fw:
fw.write(c)
write_version_py()
write_cmaps()
setup(
name='cmaps',
author='Hao Huang',
version=VERSION,
author_email='[email protected]',
packages=['cmaps', ],
package_data={'cmaps': ['colormaps/ncar_ncl/*',
'colormaps/self_defined/*'], },
data_files=[('', ['cmaps.template', 'LICENSE']),],
url='',
license='LICENSE',
description='',
long_description='',
install_requires=['matplotlib', 'numpy'],
)