forked from expyriment/expyriment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·157 lines (136 loc) · 5.29 KB
/
setup.py
File metadata and controls
executable file
·157 lines (136 loc) · 5.29 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
#!/usr/bin/env python
import stat
from subprocess import Popen, PIPE
from distutils.core import setup
from distutils.command.build_py import build_py
from distutils.command.install import install
from distutils.command.bdist_wininst import bdist_wininst
from os import remove, close, chmod, path
from shutil import move, rmtree
from tempfile import mkstemp
from glob import glob
# Settings
packages = ['expyriment',
'expyriment.control',
'expyriment.io', 'expyriment.io.extras',
'expyriment.misc', 'expyriment.misc.extras',
'expyriment.stimuli', 'expyriment.stimuli.extras',
'expyriment.design', 'expyriment.design.extras']
package_data = {'expyriment':['expyriment_logo.png']}
# Clear old installation when installing
class Install(install):
"""Specialized installer."""
def run(self):
# Clear old installation
olddir = path.abspath(self.install_lib + path.sep + "expyriment")
oldegginfo = glob(path.abspath(self.install_lib) + path.sep + \
"expyriment*.egg-info")
for egginfo in oldegginfo:
remove(egginfo)
if path.isdir(olddir):
rmtree(olddir)
install.run(self)
# Clear old installation when installing (for bdist_wininst)
class Wininst(bdist_wininst):
"""Specialized installer."""
def run(self):
fh, abs_path = mkstemp(".py")
new_file = open(abs_path, 'w')
# Clear old installation
new_file.write("""
from distutils import sysconfig
import os, shutil
old_installation = os.path.join(sysconfig.get_python_lib(), 'expyriment')
if os.path.isdir(old_installation):
shutil.rmtree(old_installation)
""")
new_file.close()
close(fh)
self.pre_install_script = abs_path
bdist_wininst.run(self)
# Manipulate the header of all files (only for building/installing from repository)
class Build(build_py):
"""Specialized Python source builder."""
def byte_compile(self, files):
for f in files:
if f.endswith('.py'):
# Create temp file
fh, abs_path = mkstemp()
new_file = open(abs_path, 'w')
old_file = open(f, 'rU')
for line in old_file:
if line[0:11] == '__version__':
new_file.write("__version__ = '" + version_nr + "'" + \
'\n')
elif line[0:12] == '__revision__':
new_file.write("__revision__ = '" + revision_nr + "'"\
+ '\n')
elif line[0:8] == '__date__':
new_file.write("__date__ = '" + date + "'" + '\n')
else:
new_file.write(line)
# Close temp file
new_file.close()
close(fh)
old_file.close()
# Remove original file
remove(f)
# Move new file
move(abs_path, f)
chmod(f, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
build_py.byte_compile(self, files)
version_nr = "{0}"
with open('CHANGES.txt') as f:
for line in f:
if line[0:8].lower() == "upcoming":
version_nr += "+"
if line[0:7] == "Version":
version_nr = version_nr.format(line[8:13])
break
# Check if we are building/installing from the repository
try:
proc = Popen(['hg', 'log', '-r0'], stdout=PIPE, stderr=PIPE)
if not proc.stdout.readline() == 'changeset: 0:9b8d198ba90f\n':
raise Exception
proc = Popen(['hg', 'id', '-i'], stdout=PIPE, stderr=PIPE)
revision_nr = proc.stdout.read()
if revision_nr[-1] == '\n':
revision_nr = revision_nr[:-1]
proc = Popen(['hg', 'log', '-l1'], stdout=PIPE, stderr=PIPE)
while True:
line = proc.stdout.readline()
if line[0:5] == 'date:':
break
date = line[5:].lstrip()[0:30]
# Build
setup(name='expyriment',
version=version_nr,
description='A Python library for cognitive and neuroscientific experiments',
author='Florian Krause, Oliver Lindemann',
author_email='florian@expyriment.org, oliver@expyriment.org',
license='GNU GPLv3',
url='http://www.expyriment.org',
packages=packages,
package_dir={'expyriment':'expyriment'},
package_data=package_data,
cmdclass={'build_py': Build, 'install': Install, 'bdist_wininst': Wininst}
)
print ""
print "Expyriment Version:", version_nr, "(from repository)"
# If not, we are building/installing from a released download
except:
# Build
setup(name='expyriment',
version=version_nr,
description='A Python library for cognitive and neuroscientific experiments',
author='Florian Krause, Oliver Lindemann',
author_email='florian@expyriment.org, oliver@expyriment.org',
license='GNU GPLv3',
url='http://www.expyriment.org',
packages=packages,
package_dir={'expyriment':'expyriment'},
package_data=package_data,
cmdclass={'install': Install, 'bdist_wininst': Wininst}
)
print ""
print "Expyriment Version:", version_nr