comparison setup.py @ 226:7b6ea46ea111

setup.py: clean up use of os.popen
author Mathias De Mare <mathias.de_mare@nokia.com>
date Tue, 14 Mar 2023 10:23:08 +0100
parents 3f9dd44be8c2
children
comparison
equal deleted inserted replaced
225:fba806958dba 226:7b6ea46ea111
1 import os, time 1 import os, time, subprocess
2 from distutils.core import setup 2 from distutils.core import setup
3 3
4 # query Mercurial for version number, or pull from PKG-INFO 4 # query Mercurial for version number, or pull from PKG-INFO
5 version = 'unknown' 5 version = 'unknown'
6 if os.path.isdir('.hg'): 6 if os.path.isdir('.hg'):
7 cmd = "hg id -i -t" 7 cmd = ["hg", "id", "-i", "-t"]
8 l = os.popen(cmd).read().split() 8 l = subprocess.check_output(cmd, universal_newlines=True).split()
9 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags 9 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
10 l.pop() 10 l.pop()
11 if len(l) > 1: # tag found 11 if len(l) > 1: # tag found
12 version = l[-1] 12 version = l[-1]
13 if l[0].endswith('+'): # propagate the dirty status to the tag 13 if l[0].endswith('+'): # propagate the dirty status to the tag
14 version += '+' 14 version += '+'
15 elif len(l) == 1: # no tag found 15 elif len(l) == 1: # no tag found
16 cmd1 = 'hg parents --template "{latesttag}"' 16 cmd1 = ['hg', 'parents', '--template', '{latesttag}']
17 cmd2 = 'hg parents --template "{latesttagdistance}"' 17 cmd2 = ['hg', 'parents', '--template', '{latesttagdistance}']
18 version = os.popen(cmd1).read() + ".dev" + os.popen(cmd2).read() 18 version = "%s.dev%s" % (
19 subprocess.check_output(cmd1, universal_newlines=True),
20 subprocess.check_output(cmd2, universal_newlines=True)
21 )
19 if version.endswith('+'): 22 if version.endswith('+'):
20 version += time.strftime('%Y%m%d') 23 version += time.strftime('%Y%m%d')
21 elif os.path.exists('.hg_archival.txt'): 24 elif os.path.exists('.hg_archival.txt'):
22 kw = dict([[t.strip() for t in l.split(':', 1)] 25 kw = dict([[t.strip() for t in l.split(':', 1)]
23 for l in open('.hg_archival.txt')]) 26 for l in open('.hg_archival.txt')])