Code Duplication    Length = 35-35 lines in 2 locations

versioneer.py 1 location

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

metpy/_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):