forked from hpcugent/VSC-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_mympirun.py
149 lines (125 loc) · 5.66 KB
/
setup_mympirun.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
#!/usr/bin/env python
# -*- coding: latin-1 -*-
#
# Copyright 2009-2012 Ghent University
# Copyright 2009-2012 Stijn De Weirdt
# Copyright 2012 Andy Georges
#
# This file is part of VSC-tools,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en),
# the Hercules foundation (http://www.herculesstichting.be/in_English)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# http://github.com/hpcugent/VSC-tools
#
# VSC-tools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# VSC-tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with VSC-tools. If not, see <http://www.gnu.org/licenses/>.
#
"""
Setup for mympirun
"""
import os
import shared_setup
import shutil
import sys
from shared_setup import vsc_install_scripts, action_target, sdw
# generate these somehow from lib/vsc/mympirun/mpi/mpi.py
FAKE_SUBDIRECTORY_NAME = 'fake'
MYMPIRUN_ALIASES = ['%smpirun' % x for x in ['i', 'ih', 'o', 'm', 'mh', 'mm', 'q', 'm2', 'm2h']] + ['myscoop']
log = shared_setup.log
# redo this part, redefine some functionality of vsc-shared
try:
from setuptools.command.easy_install import easy_install
# uch uch, easy_install ignores the easy_install cmdclass
_orig_install_egg_scripts = sys.modules['setuptools.command.easy_install'].easy_install.install_egg_scripts
def _new_install_egg_scripts(self, dist):
orig_func = dist.metadata_listdir
def new_func(txt):
"""The original metadata_listdir assumes no subdirectories in scripts dir.
fake/mpirun is the exception (mpirun itself is not listed !)
The function is used through a whole bunch of Egg classes, now way we can easily intercept this
"""
res = orig_func(txt)
if txt == 'scripts':
if FAKE_SUBDIRECTORY_NAME in res:
idx = res.index(FAKE_SUBDIRECTORY_NAME)
if idx >= 0:
res[idx] = '%s/mpirun' % FAKE_SUBDIRECTORY_NAME
return res
dist.metadata_listdir = new_func
_orig_install_egg_scripts(self, dist)
sys.modules['setuptools.command.easy_install'].easy_install.install_egg_scripts = _new_install_egg_scripts
except:
raise("mympirun requires setuptools")
class mympirun_vsc_install_scripts(vsc_install_scripts):
"""Create the (fake) links for mympirun
also remove .sh and .py extensions from the scripts
"""
def run(self):
vsc_install_scripts.run(self)
for script in self.original_outfiles:
if script.endswith(".py") or script.endswith(".sh"):
script = script[:-3]
if script.endswith('/mympirun'):
# make the fake dir, create all symlinks
# make all links
# they are create with relative paths !
rel_script = os.path.basename(script)
rel_script_dir = os.path.dirname(script)
# abspath: all_syms = [os.path.join(self.install_dir, x) for x in MYMPIRUN_ALIASES]
# abspath: all_syms.append(os.path.join(abs_fakepath, 'mpirun'))
# with relative paths, we also ne to chdir for the fake/mpirun and ref to ../mympirun
previous_pwd = os.getcwd()
os.chdir(rel_script_dir)
for sym_name in MYMPIRUN_ALIASES:
if os.path.exists(sym_name):
os.remove(sym_name)
os.symlink(rel_script, sym_name)
newoutfile = os.path.join(rel_script_dir, sym_name)
self.outfiles.append(newoutfile)
log.info("symlink %s to %s newoutfile %s" % (rel_script, sym_name, newoutfile))
# fake mpirun
os.chdir(previous_pwd)
abs_fakepath = os.path.join(self.install_dir, FAKE_SUBDIRECTORY_NAME)
if not os.path.isdir(abs_fakepath):
log.info("creating abs_fakepath %s" % abs_fakepath)
os.mkdir(abs_fakepath)
else:
log.info("not creating abs_fakepath %s (already exists)" % abs_fakepath)
os.chdir(abs_fakepath) # abs_fakepath si not always absolute
fake_mpirun = os.path.join(abs_fakepath, 'mpirun')
if os.path.exists(fake_mpirun):
os.remove(fake_mpirun)
mympirun_src = '../%s' % rel_script
os.symlink(mympirun_src, 'mpirun')
self.outfiles.append(fake_mpirun)
log.info("symlink %s to %s newoutfile %s" % (mympirun_src, 'mpirun', fake_mpirun))
os.chdir(previous_pwd)
## change
PACKAGE = {
'name': 'vsc-mympirun',
'install_requires': ['vsc-base >= 0.95'],
'version': '3.0.7',
'author': [sdw],
'maintainer': [sdw],
'packages': ['vsc.mympirun', 'vsc.mympirun.mpi', 'vsc.mympirun.rm'],
'py_modules': ['vsc.__init__'],
'namespace_packages': ['vsc'],
'scripts': ['bin/mympirun.py', 'bin/pbsssh.sh', 'bin/sshsleep.sh', 'bin/mympisanity.py'],
'cmdclass': {
"install_scripts": mympirun_vsc_install_scripts,
},
}
if __name__ == '__main__':
action_target(PACKAGE)