Projet

Général

Profil

0001-update-setup.py-helpers-33480.patch

Emmanuel Cazenave, 28 mai 2019 14:32

Télécharger (2,68 ko)

Voir les différences:

Subject: [PATCH] update setup.py helpers (#33480)

 setup.py | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)
setup.py
1 1
#! /usr/bin/env python
2 2
# -*- coding: utf-8 -*-
3 3

  
4
import glob
5 4
import os
6
import re
7 5
import subprocess
8 6
import sys
9 7

  
......
13 11
from distutils.cmd import Command
14 12
from setuptools import setup, find_packages
15 13

  
14

  
16 15
class eo_sdist(sdist):
17 16
    def run(self):
18 17
        if os.path.exists('VERSION'):
19 18
            os.remove('VERSION')
20 19
        version = get_version()
21
        version_file = open('VERSION', 'w')
22
        version_file.write(version)
23
        version_file.close()
20
        with open('VERSION', 'w') as fd:
21
            fd.write(version)
24 22
        sdist.run(self)
25 23
        if os.path.exists('VERSION'):
26 24
            os.remove('VERSION')
27 25

  
26

  
28 27
def get_version():
28
    '''Use the VERSION, if absent generates a version with git describe, if not
29
       tag exists, take 0.0- and add the length of the commit log.
30
    '''
29 31
    if os.path.exists('VERSION'):
30
        version_file = open('VERSION', 'r')
31
        version = version_file.read()
32
        version_file.close()
33
        return version
32
        with open('VERSION', 'r') as v:
33
            return v.read()
34 34
    if os.path.exists('.git'):
35
        p = subprocess.Popen(['git', 'describe', '--dirty', '--match=v*'], stdout=subprocess.PIPE)
35
        p = subprocess.Popen(
36
            ['git', 'describe', '--dirty=.dirty', '--match=v*'],
37
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
36 38
        result = p.communicate()[0]
37 39
        if p.returncode == 0:
38
            version = result.split()[0][1:]
39
            version = version.replace('-', '.')
40
            result = result.decode('ascii').strip()[1:]  # strip spaces/newlines and initial v
41
            if '-' in result:  # not a tagged version
42
                real_number, commit_count, commit_hash = result.split('-', 2)
43
                version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
44
            else:
45
                version = result
40 46
            return version
41
    return '0'
47
        else:
48
            return '0.0.post%s' % len(
49
                    subprocess.check_output(
50
                            ['git', 'rev-list', 'HEAD']).splitlines())
51
    return '0.0'
52

  
42 53

  
43 54
class compile_translations(Command):
44 55
    description = 'compile message catalogs to MO files via django compilemessages'
45
-