-
Notifications
You must be signed in to change notification settings - Fork 94
/
script.py
executable file
·67 lines (53 loc) · 2.27 KB
/
script.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
#!/usr/bin/env python
"""This example demonstrates importing hpccm in a Python script.
Rather than using the hpccm command line tool to convert a recipe into
a container specification, import hpccm directly.
The script is responsible for handling user arguments, managing
layers, and printing the output.
Note: HPCCM must be installed via pip prior to using this script.
Usage:
$ python recipes/examples/script.py --help
$ python recipes/examples/script.py --linux ubuntu
$ python recipes/examples/script.py --format singularity
"""
from __future__ import unicode_literals
from __future__ import print_function
import argparse
import hpccm
### Parse command line arguments
parser = argparse.ArgumentParser(description='HPCCM example')
parser.add_argument('--compiler', type=str, default='gnu',
choices=['gnu', 'llvm', 'nvhpc'],
help='Compiler choice (default: gnu)')
parser.add_argument('--format', type=str, default='docker',
choices=['docker', 'singularity'],
help='Container specification format (default: docker)')
parser.add_argument('--linux', type=str, default='centos',
choices=['centos', 'ubuntu'],
help='Linux distribution choice (default: centos)')
parser.add_argument('--nvhpc_eula_accept', action='store_true',
default=False,
help='Accept PGI EULA (default: false)')
args = parser.parse_args()
### Create Stage
Stage0 = hpccm.Stage()
### Linux distribution
if args.linux == 'centos':
Stage0 += hpccm.primitives.baseimage(image='centos:7')
elif args.linux == 'ubuntu':
Stage0 += hpccm.primitives.baseimage(image='ubuntu:16.04')
### Compiler
if args.compiler == 'gnu':
Stage0 += hpccm.building_blocks.gnu()
elif args.compiler == 'llvm':
Stage0 += hpccm.building_blocks.llvm()
elif args.compiler == 'nvhpc':
if not args.nvhpc_eula_accept:
print('EULA not accepted. To accept, use "--nvhpc_eula_accept".\n'
'See NVIDIA EULA at https://docs.nvidia.com/hpc-sdk/eula')
exit(1)
Stage0 += hpccm.building_blocks.nvhpc(eula=args.nvhpc_eula_accept)
### Set container specification output format
hpccm.config.set_container_format(args.format)
### Output container specification
print(Stage0)