-
Notifications
You must be signed in to change notification settings - Fork 30
/
setupegg.py
99 lines (87 loc) · 3.36 KB
/
setupegg.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
#!/usr/bin/env python
"""
Install scitools with easyviz
Usage:
python setup.py install [, --prefix=$PREFIX --easyviz_backend backendname]
"""
import os, sys, socket, re, glob, platform
scripts = [os.path.join("bin", "scitools"), os.path.join("bin", "pyreport")]
if platform.system() == "Windows" or "bdist_wininst" in sys.argv:
# In the Windows command prompt we can't execute Python scripts
# without a .py extension. A solution is to create batch files
# that runs the different scripts.
batch_files = []
for script in scripts:
batch_file = script + ".bat"
f = open(batch_file, "w")
f.write('python "%%~dp0\%s" %%*\n' % os.path.split(script)[1])
f.close()
batch_files.append(batch_file)
scripts.extend(batch_files)
# NOTE: now we force matplotlib as default backend if it is installed:
# (previously gnuplot was always default)
try:
import matplotlib
default_easyviz_backend = 'matplotlib'
except: # cannot accept any error here
try:
import Gnuplot
default_easyviz_backend = 'gnuplot'
except:
# Neither Gnuplot nor Matplotlib is installed. Matplotlib is now set
# as default backend for Easyviz.
default_easyviz_backend = 'matplotlib'
# modify config file so that it sets the wanted backend for easyviz
config_file = os.path.join('lib', 'scitools', 'scitools.cfg')
if '--easyviz_backend' in sys.argv:
try:
i = sys.argv.index('--easyviz_backend')
default_easyviz_backend = \
sys.argv[i+1]
del sys.argv[i:i+2]
except IndexError:
print '--easyviz_backend must be followed by a name like '\
'\ngnuplot, matplotlib, etc.'
sys.exit(1)
print 'default scitools.easyviz backend becomes', default_easyviz_backend
print '(could be set by the --easyviz_backend option to setup.py)\n'
# write new config file and change backend line
os.rename(config_file, config_file + '.old~~')
infile = open(config_file + '.old~~', 'r')
outfile = open(config_file, 'w')
for line in infile:
if line.lstrip().startswith('['):
section = line.lower().strip()[1:-1]
if line.lstrip().startswith('backend') and section == 'easyviz':
outfile.write('backend = %s ; default backend\n' % \
default_easyviz_backend)
else:
outfile.write(line)
infile.close(); outfile.close()
if __file__ == 'setupegg.py':
# http://peak.telecommunity.com/DevCenter/setuptools
from setuptools import setup, Extension
else:
from distutils.core import setup
# make sure we import from scitools in this package, not an installed one:
sys.path.insert(0, os.path.join('lib')); import scitools
setup(
version = str(scitools.version),
author = ', '.join(scitools.author),
author_email = "<[email protected]>",
description = scitools.__doc__,
license = "BSD",
name = "SciTools",
url = "http://scitools.googlecode.com",
package_dir = {'': 'lib'},
packages = ["scitools",
os.path.join("scitools", "easyviz"),
],
package_data = {'': ['scitools.cfg']},
scripts = scripts,
data_files=[(os.path.join("share", "man", "man1"),
[os.path.join("doc", "man", "man1", "scitools.1.gz"),
os.path.join("doc", "man", "man1", "pyreport.1.gz")])],
)
if os.path.isfile(config_file + '.cop'):
os.rename(config_file + '.cop', config_file)