-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
95 lines (82 loc) · 3.26 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
#!/usr/bin/env python
import os
import re
from setuptools import find_packages, setup
from setuptools.command.develop import develop
from setuptools.command.install import install
thisScriptDir = os.path.dirname(os.path.realpath(__file__))
def EnsureNewline(line):
line = line.rstrip()
line = line + '\n'
return line
def ReplaceBtwnLines(fPath, startLine, endLine, txtBlock):
repRe = re.compile(startLine + '.*' + endLine, re.DOTALL)
replTxt = EnsureNewline(startLine) + EnsureNewline(txtBlock) + endLine
try:
with open(fPath, 'r') as f:
oldTxt = f.read()
except IOError:
return False
if repRe.search(oldTxt):
newTxt = repRe.sub(replTxt, oldTxt)
with open(fPath, 'w') as f:
f.write(newTxt)
return True
else:
return False
def AppendBlockToFile(fPath, startLine, endLine, txtBlock):
oldTxt = ''
newTxt = EnsureNewline(startLine) + EnsureNewline(txtBlock) + endLine
try:
with open(fPath, 'r') as f:
oldTxt = f.read()
oldTxt = EnsureNewline(oldTxt) + '\n'
except IOError:
pass
with open(fPath, 'w') as f:
f.write(oldTxt)
f.write(newTxt)
class CustomSetupCommand:
'''
customized setup command base class
meant to be used in a subclass that also inherits either setuptools.command.install.install or .develop
'''
leapSDKEnvVar = 'LEAPSDK_DIR'
def run(self):
self._writeLeapConfig()
self._writePymolrc()
def _writeLeapConfig(self):
'''
write config file to set path to leap motion packages
'''
if self.leapSDKEnvVar not in os.environ:
raise EnvironmentError('%s%s' % ('You need to set the %s environment variable before installing ocumol, ' % self.leapSDKEnvVar,
'e.g. you could run `LEAPSDK_DIR=/usr/local/LeapSDK pip install ocumol`'))
leapSDKDir = os.environ.get(self.leapSDKEnvVar)
with open('ocumol/leapConfig.py', 'w') as f:
f.write("leapPath = '%s'" % os.path.join(leapSDKDir, 'lib'))
def _writePymolrc(self):
pymolrcPath = os.path.expanduser('~/.pymolrc.py')
ocumolStartBumper = '#'*4 + 'START_OCUMOL_PLUGIN' + '#'*4
ocumolEndBumper = '#'*4 + 'END_OCUMOL_PLUGIN' + '#'*4
with open(os.path.join(thisScriptDir, 'pymolrc'), 'r') as f:
ocumolPluginTxt = f.read()
if not ReplaceBtwnLines(pymolrcPath, ocumolStartBumper, ocumolEndBumper, ocumolPluginTxt):
AppendBlockToFile(pymolrcPath, ocumolStartBumper, ocumolEndBumper, ocumolPluginTxt)
class CustomDevelopCommand(CustomSetupCommand, develop):
def run(self):
CustomSetupCommand.run(self)
develop.run(self)
class CustomInstallCommand(CustomSetupCommand, install):
def run(self):
CustomSetupCommand.run(self)
install.run(self)
setup(
author = 'Max Klein, Jeliazko Jeliazkov, Henry Lessen, Mariusz Matyszewski',
cmdclass = {'develop': CustomDevelopCommand,'install': CustomInstallCommand},
description = 'adds VR support to various molecular viewers',
license = 'apache',
name = "ocumol",
packages=find_packages(),
url='https://github.com/lqtza/OcuMOL_Leap'
)