Code Duplication    Length = 35-35 lines in 2 locations

versioneer.py 1 location

@@ 384-418 (lines=35) @@
381
    return decorate
382
383
384
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
385
                env=None):
386
    """Call the given command(s)."""
387
    assert isinstance(commands, list)
388
    p = None
389
    for c in commands:
390
        try:
391
            dispcmd = str([c] + args)
392
            # remember shell=False, so use git.cmd on windows, not just git
393
            p = subprocess.Popen([c] + args, cwd=cwd, env=env,
394
                                 stdout=subprocess.PIPE,
395
                                 stderr=(subprocess.PIPE if hide_stderr
396
                                         else None))
397
            break
398
        except EnvironmentError:
399
            e = sys.exc_info()[1]
400
            if e.errno == errno.ENOENT:
401
                continue
402
            if verbose:
403
                print("unable to run %s" % dispcmd)
404
                print(e)
405
            return None, None
406
    else:
407
        if verbose:
408
            print("unable to find command, tried %s" % (commands,))
409
        return None, None
410
    stdout = p.communicate()[0].strip()
411
    if sys.version_info[0] >= 3:
412
        stdout = stdout.decode()
413
    if p.returncode != 0:
414
        if verbose:
415
            print("unable to run %s (error)" % dispcmd)
416
            print("stdout was %s" % stdout)
417
        return None, p.returncode
418
    return stdout, p.returncode
419
420
421
LONG_VERSION_PY['git'] = '''

rna_tools/_version.py 1 location

@@ 70-104 (lines=35) @@
67
    return decorate
68
69
70
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
71
                env=None):
72
    """Call the given command(s)."""
73
    assert isinstance(commands, list)
74
    p = None
75
    for c in commands:
76
        try:
77
            dispcmd = str([c] + args)
78
            # remember shell=False, so use git.cmd on windows, not just git
79
            p = subprocess.Popen([c] + args, cwd=cwd, env=env,
80
                                 stdout=subprocess.PIPE,
81
                                 stderr=(subprocess.PIPE if hide_stderr
82
                                         else None))
83
            break
84
        except EnvironmentError:
85
            e = sys.exc_info()[1]
86
            if e.errno == errno.ENOENT:
87
                continue
88
            if verbose:
89
                print("unable to run %s" % dispcmd)
90
                print(e)
91
            return None, None
92
    else:
93
        if verbose:
94
            print("unable to find command, tried %s" % (commands,))
95
        return None, None
96
    stdout = p.communicate()[0].strip()
97
    if sys.version_info[0] >= 3:
98
        stdout = stdout.decode()
99
    if p.returncode != 0:
100
        if verbose:
101
            print("unable to run %s (error)" % dispcmd)
102
            print("stdout was %s" % stdout)
103
        return None, p.returncode
104
    return stdout, p.returncode
105
106
107
def versions_from_parentdir(parentdir_prefix, root, verbose):