Completed
Push — develop ( b745b5...362316 )
by Wu
9s
created

my_exec_command()   F

Complexity

Conditions 13

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 41
rs 2.7716
cc 13

How to fix   Complexity   

Complexity

Complex classes like my_exec_command() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
""" Monkey patch waf code to pipe command output direct to stdout
2
3
As far as I know there is no way to do this using standard waf build commands
4
options.
5
"""
6
7
import sys
8
from waflib import Utils, Errors, Logs, Context
9
10
11
def my_exec_command(self,cmd,**kw):
12
    """ Copy of Context.exec_command that doesn't capture stdout / stderr
13
14
    This is necessary to prevent travis-ci timing out while waiting for
15
    feedback from the scipy build process, in particular
16
    """
17
    subprocess=Utils.subprocess
18
    kw['shell']=isinstance(cmd,str)
19
    Logs.debug('runner: %r'%cmd)
20
    Logs.debug('runner_env: kw=%s'%kw)
21
    if self.logger:
22
        self.logger.info(cmd)
23
    if'stdout'not in kw:
24
        kw['stdout']=sys.stdout
25
    if'stderr'not in kw:
26
        kw['stderr']=sys.stderr
27
    try:
28
        if kw['stdout']or kw['stderr']:
29
            p=subprocess.Popen(cmd,**kw)
30
            (out,err)=p.communicate()
31
            ret=p.returncode
32
        else:
33
            out,err=(None,None)
34
            ret=subprocess.Popen(cmd,**kw).wait()
35
    except Exception as e:
36
        raise Errors.WafError('Execution failure: %s'%str(e),ex=e)
37
    if out:
38
        if not isinstance(out,str):
39
            out=out.decode(sys.stdout.encoding or'iso8859-1')
40
        if self.logger:
41
            self.logger.debug('out: %s'%out)
42
        else:
43
            sys.stdout.write(out)
44
    if err:
45
        if not isinstance(err,str):
46
            err=err.decode(sys.stdout.encoding or'iso8859-1')
47
        if self.logger:
48
            self.logger.error('err: %s'%err)
49
        else:
50
            sys.stderr.write(err)
51
    return ret
52
53
54
def monkey_patch():
55
    """ Apply monkey patch to exec_command """
56
    Context.Context.exec_command = my_exec_command
57