forked from easybuilders/easybuild-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoy_extension.py
More file actions
114 lines (99 loc) · 4.11 KB
/
toy_extension.py
File metadata and controls
114 lines (99 loc) · 4.11 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
##
# Copyright 2009-2023 Ghent University
#
# This file is part of EasyBuild,
# 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://www.vscentrum.be),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild 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.
#
# EasyBuild 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 EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
EasyBuild support for building and installing toy extensions, implemented as an easyblock
@author: Kenneth Hoste (Ghent University)
"""
import os
from easybuild.framework.easyconfig import CUSTOM
from easybuild.framework.extensioneasyblock import ExtensionEasyBlock
from easybuild.easyblocks.toy import EB_toy, compose_toy_build_cmd
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.run import run_shell_cmd
class Toy_Extension(ExtensionEasyBlock):
"""Support for building/installing toy."""
@staticmethod
def extra_options():
"""Custom easyconfig parameters for toy extensions."""
extra_vars = {
'toy_ext_param': ['', "Toy extension parameter", CUSTOM],
}
return ExtensionEasyBlock.extra_options(extra_vars=extra_vars)
@property
def required_deps(self):
"""Return list of required dependencies for this extension."""
deps = {
'bar': [],
'barbar': ['bar'],
'ls': [],
}
if self.name in deps:
return deps[self.name]
else:
raise EasyBuildError("Dependencies for %s are unknown!", self.name)
def run(self, *args, **kwargs):
"""
Install toy extension.
"""
if self.src:
EB_toy.build_step(self.master, name=self.name, cfg=self.cfg)
if self.cfg['toy_ext_param']:
run_shell_cmd(self.cfg['toy_ext_param'])
return self.module_generator.set_environment('TOY_EXT_%s' % self.name.upper().replace('-', '_'), self.name)
def prerun(self):
"""
Prepare installation of toy extension.
"""
super(Toy_Extension, self).prerun()
if self.src:
super(Toy_Extension, self).run(unpack_src=True)
EB_toy.configure_step(self.master, name=self.name, cfg=self.cfg)
def run_async(self, thread_pool):
"""
Install toy extension asynchronously.
"""
task_id = f'ext_{self.name}_{self.version}'
if self.src:
cmd = compose_toy_build_cmd(self.cfg, self.name, self.cfg['prebuildopts'], self.cfg['buildopts'])
else:
cmd = f"echo 'no sources for {self.name}'"
return thread_pool.submit(run_shell_cmd, cmd, asynchronous=True, env=os.environ.copy(),
fail_on_error=False, task_id=task_id, work_dir=os.getcwd())
def postrun(self):
"""
Wrap up installation of toy extension.
"""
super(Toy_Extension, self).postrun()
EB_toy.install_step(self.master, name=self.name)
def sanity_check_step(self, *args, **kwargs):
"""Custom sanity check for toy extensions."""
self.log.info("Loaded modules: %s", self.modules_tool.list())
custom_paths = {
'files': [],
'dirs': ['.'], # minor hack to make sure there's always a non-empty list
}
if self.src:
custom_paths['files'].extend(['bin/%s' % self.name, 'lib/lib%s.a' % self.name])
return super(Toy_Extension, self).sanity_check_step(custom_paths=custom_paths)