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

python.py 1.72 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
from mubench import CALLBACKS_DIR
from mubench.lang import Language
21
from mubench.util import expandenv, run_in_subproc
John Zhang's avatar
John Zhang committed
22

23
24
25
26
27
28
29
30

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

    @classmethod
John Zhang's avatar
John Zhang committed
31
32
    def check_runner(cls, rc, lc, task):
        env = task.env
33
34
35
36
37
38
39
40
41
42
43
44
45
46
        # 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
47
48
        rc = task.runner
        bmc = task.benchmark
49

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

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

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

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

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

62
        return run_in_subproc(cmd, task.env)