Projet

Général

Profil

0001-misc-PEP-440-compliant-version-number-15562.patch

Emmanuel Cazenave, 26 septembre 2019 15:50

Télécharger (2,46 ko)

Voir les différences:

Subject: [PATCH 1/2] misc: PEP 440 compliant version number (#15562)

 setup.py | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)
setup.py
51 51

  
52 52

  
53 53
class eo_sdist(sdist):
54

  
55 54
    def run(self):
56
        print "creating VERSION file"
57 55
        if os.path.exists('VERSION'):
58 56
            os.remove('VERSION')
59 57
        version = get_version()
......
61 59
        version_file.write(version)
62 60
        version_file.close()
63 61
        sdist.run(self)
64
        print "removing VERSION file"
65 62
        if os.path.exists('VERSION'):
66 63
            os.remove('VERSION')
67 64

  
......
79 76
    return r
80 77

  
81 78
def get_version():
79
    '''Use the VERSION, if absent generates a version with git describe, if not
80
       tag exists, take 0.0- and add the length of the commit log.
81
    '''
82 82
    if os.path.exists('VERSION'):
83
        version_file = open('VERSION', 'r')
84
        version = version_file.read()
85
        version_file.close()
86
        return version
83
        with open('VERSION', 'r') as v:
84
            return v.read()
87 85
    if os.path.exists('.git'):
88
        p = subprocess.Popen(['git','describe','--match=v*'], stdout=subprocess.PIPE)
86
        p = subprocess.Popen(
87
            ['git', 'describe', '--dirty=.dirty', '--match=v*'],
88
            stdout=subprocess.PIPE, stderr=subprocess.PIPE
89
        )
89 90
        result = p.communicate()[0]
90
        version = result.split()[0][1:]
91
        version = version.replace('-', '.')
92
        return version
93
    return '0'
91
        if p.returncode == 0:
92
            result = result.decode('ascii').strip()[1:]  # strip spaces/newlines and initial v
93
            if '-' in result:  # not a tagged version
94
                real_number, commit_count, commit_hash = result.split('-', 2)
95
                version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
96
            else:
97
                version = result
98
            return version
99
        else:
100
            return '0.0.post%s' % len(
101
                    subprocess.check_output(
102
                            ['git', 'rev-list', 'HEAD']).splitlines())
103
    return '0.0'
104

  
94 105

  
95 106

  
96 107
cmdclass = {
97
-