GitLab will be upgraded on 30 Jan 2023 from 2.00 pm (AEDT) to 3.00 pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

python.py 1.49 KB
Newer Older
1
import subprocess as subproc
John Zhang's avatar
John Zhang committed
2
3
import os

John Zhang's avatar
John Zhang committed
4
5
6
from mubench import CALLBACKS_DIR
from mubench.lang import Language
from mubench.exceptions import ExecutionFailure
7
from mubench.util import expandenv
John Zhang's avatar
John Zhang committed
8

9
10
11
12
13
14
15
16

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

    @classmethod
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    def check_runner(cls, rc, lc, env):
        # 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):
        rc = task.runner_conf
        bmc = task.benchmark_conf

John Zhang's avatar
John Zhang committed
35
        cmd = []
36
        cmd.append(rc['exec'])
John Zhang's avatar
John Zhang committed
37

38
        cmd.append(target)
John Zhang's avatar
John Zhang committed
39
40

        # first & second argument: callback class name and parameter string
41
42
        cmd.append(task.callback_conf['name'])
        cmd.append(task.callback_conf['param'])
John Zhang's avatar
John Zhang committed
43

44
        # third argument: iterations
45
        cmd.append(bmc['iterations'])
46

47
        cmd.extend(bmc['args'])
John Zhang's avatar
John Zhang committed
48
49
50
51

        # place callback module on PYTHONPATH
        env = os.environ.copy()
        pythonpath = env.get('PYTHONPATH', '')
John Zhang's avatar
John Zhang committed
52
        callback_dir = CALLBACKS_DIR / 'python'
John Zhang's avatar
John Zhang committed
53
54
55
        pythonpath = '%(callback_dir)s:%(pythonpath)s' % locals()
        env['PYTHONPATH'] = pythonpath

56
        return cls.run_in_subproc(cmd, os.environ)