To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

python.py 1.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

16
import subprocess as subproc
John Zhang's avatar
John Zhang committed
17
18
import os

John Zhang's avatar
John Zhang committed
19
20
21
from mubench import CALLBACKS_DIR
from mubench.lang import Language
from mubench.exceptions import ExecutionFailure
22
from mubench.util import expandenv
John Zhang's avatar
John Zhang committed
23

24
25
26
27
28
29
30
31

class Python(Language):
    name = 'python'
    src_ext = 'py'
    compiled = False
    default_exec = 'python'

    @classmethod
John Zhang's avatar
John Zhang committed
32
33
    def check_runner(cls, rc, lc, task):
        env = task.env
34
35
36
37
38
39
40
41
42
43
44
45
46
47
        # python interpreter
        python = rc.get('exec', cls.default_exec)
        rc['exec'] = expandenv(python, env)

        # PYTHOPATH
        pythonpath = env.get('PYTHONPATH', '')
        callback_dir = CALLBACKS_DIR / 'python'
        pythonpath = '%(callback_dir)s:%(pythonpath)s' % locals()
        env['PYTHONPATH'] = pythonpath

        return rc

    @classmethod
    def run(cls, target, task):
John Zhang's avatar
John Zhang committed
48
49
        rc = task.runner
        bmc = task.benchmark
50

John Zhang's avatar
John Zhang committed
51
        cmd = []
52

53
        cmd.append(rc['exec'])
John Zhang's avatar
John Zhang committed
54

55
        cmd.append(target)
John Zhang's avatar
John Zhang committed
56
57

        # first & second argument: callback class name and parameter string
John Zhang's avatar
John Zhang committed
58
        cmd.append(task.callback['dylib'])
John Zhang's avatar
John Zhang committed
59
        cmd.append(task.callback['param'])
60

61
        cmd.extend(bmc['args'])
John Zhang's avatar
John Zhang committed
62

John Zhang's avatar
John Zhang committed
63
        return cls.run_in_subproc(cmd, task.env)