Code Duplication    Length = 32-32 lines in 2 locations

versioneer.py 1 location

@@ 453-484 (lines=32) @@
450
    return decorate
451
452
453
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
454
    """Call the given command(s)."""
455
    assert isinstance(commands, list)
456
    p = None
457
    for c in commands:
458
        try:
459
            dispcmd = str([c] + args)
460
            # remember shell=False, so use git.cmd on windows, not just git
461
            p = subprocess.Popen([c] + args, cwd=cwd, stdout=subprocess.PIPE,
462
                                 stderr=(subprocess.PIPE if hide_stderr
463
                                         else None))
464
            break
465
        except EnvironmentError:
466
            e = sys.exc_info()[1]
467
            if e.errno == errno.ENOENT:
468
                continue
469
            if verbose:
470
                print("unable to run %s" % dispcmd)
471
                print(e)
472
            return None
473
    else:
474
        if verbose:
475
            print("unable to find command, tried %s" % (commands,))
476
        return None
477
    stdout = p.communicate()[0].strip()
478
    if sys.version_info[0] >= 3:
479
        stdout = stdout.decode()
480
    if p.returncode != 0:
481
        if verbose:
482
            print("unable to run %s (error)" % dispcmd)
483
        return None
484
    return stdout
485
LONG_VERSION_PY['git'] = '''
486
# This file helps to compute a version number in source trees obtained from
487
# git-archive tarball (such as those provided by githubs download-from-tag

bbarchivist/_version.py 1 location

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