-
Notifications
You must be signed in to change notification settings - Fork 0
/
amp_build.py
executable file
·103 lines (87 loc) · 3.89 KB
/
amp_build.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
#!/bin/env python3
#
# Build the amp-mgms tarball for distribution
#
import argparse
import logging
import tempfile
from pathlib import Path
import sys
import os
import subprocess
from amp.package import *
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--debug', default=False, action='store_true', help="Turn on debugging")
parser.add_argument('--package', default=False, action='store_true', help="build a package instead of installing")
parser.add_argument('destdir', help="Output directory for package or tool directory root")
args = parser.parse_args()
logging.basicConfig(format="%(asctime)s [%(levelname)-8s] (%(filename)s:%(lineno)d) %(message)s",
level=logging.DEBUG if args.debug else logging.INFO)
# build anything that needs to be built...
# Apptainer builds need a lot of disk space. If
# APPTAINER_TMPDIR isn't set, we'll use the temp
# directory next to this script. Same for the
# apptainer cache.
tempdir = Path(sys.path[0], 'temp')
logging.info(f"Setting tempdir to {tempdir}")
tempdir.mkdir(exist_ok=True)
if 'APPTAINER_TMPDIR' not in os.environ:
os.environ['APPTAINER_TMPDIR'] = sys.path[0] + "/temp"
Path(os.environ['APPTAINER_TMPDIR']).mkdir(exist_ok=True)
logging.info(f"Setting APPTAINER_TMPDIR = {os.environ['APPTAINER_TMPDIR']}")
if 'APPTAINER_CACHEDIR' not in os.environ:
os.environ['APPTAINER_CACHEDIR'] = sys.path[0] + "/temp/apptainer_cache"
Path(os.environ['APPTAINER_CACHEDIR']).mkdir(exist_ok=True, parents=True)
logging.info(f"Setting APPTAINER_CACHEDIR = {os.environ['APPTAINER_CACHEDIR']}")
logging.info("Building MGMs")
here = Path.cwd().resolve()
destdir = Path(args.destdir).resolve()
for buildscript in here.glob(f"tools/*/mgm_build.sh"):
# figure out where we're building this
if args.package:
buildtmp = tempfile.TemporaryDirectory(prefix='amp_mgms_build-', dir=tempdir)
builddir = Path(buildtmp.name).resolve()
else:
builddir = destdir
logging.info(f"Running build script {buildscript}")
os.chdir(buildscript.parent)
cmd = [str(buildscript), str(builddir)]
if args.debug:
cmd.append('--debug')
logging.debug(f"Running command: {cmd}")
p = subprocess.run(cmd)
if p.returncode:
logging.error(f"Build command ({buildscript}) failed with return code {p.returncode}")
exit(1)
os.chdir(here)
if args.package:
# get the version
if (buildscript.parent / "mgm_version").exists():
with open(buildscript.parent / "mgm_version") as f:
version = f.readline().strip()
else:
version = "0.0"
# Find optional things
options = {}
# defaults
for dtype in ('user', 'system'):
cfile = buildscript.parent / f"amp_config.{dtype}_defaults"
if cfile.exists():
options[f"{dtype}_defaults"] = cfile
# hooks
options['hooks'] = {}
for hook in ('pre', 'post', 'config', 'start', 'stop'):
hfile = buildscript.parent / f"amp_hook_{hook}.py"
if hfile.exists():
options['hooks'][hook] = hfile
# arch specific
options['arch_specific'] = (buildscript.parent / f"amp_arch_specific").exists()
pkgname = buildscript.parent.stem
pfile = create_package(f"amp_mgms-{pkgname}", version, "galaxy",
Path(destdir), builddir,
depends_on=['galaxy', 'amp_python'],
**options)
logging.info(f"New package in {pfile!s}")
if __name__ == "__main__":
main()