Mercurial > python-hglib
changeset 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 | fba806958dba |
children | 484b56ac4aec |
files | setup.py |
diffstat | 1 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/setup.py Tue Mar 14 14:35:58 2023 +0100 +++ b/setup.py Tue Mar 14 10:23:08 2023 +0100 @@ -1,11 +1,11 @@ -import os, time +import os, time, subprocess from distutils.core import setup # query Mercurial for version number, or pull from PKG-INFO version = 'unknown' if os.path.isdir('.hg'): - cmd = "hg id -i -t" - l = os.popen(cmd).read().split() + cmd = ["hg", "id", "-i", "-t"] + l = subprocess.check_output(cmd, universal_newlines=True).split() while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags l.pop() if len(l) > 1: # tag found @@ -13,9 +13,12 @@ if l[0].endswith('+'): # propagate the dirty status to the tag version += '+' elif len(l) == 1: # no tag found - cmd1 = 'hg parents --template "{latesttag}"' - cmd2 = 'hg parents --template "{latesttagdistance}"' - version = os.popen(cmd1).read() + ".dev" + os.popen(cmd2).read() + cmd1 = ['hg', 'parents', '--template', '{latesttag}'] + cmd2 = ['hg', 'parents', '--template', '{latesttagdistance}'] + version = "%s.dev%s" % ( + subprocess.check_output(cmd1, universal_newlines=True), + subprocess.check_output(cmd2, universal_newlines=True) + ) if version.endswith('+'): version += time.strftime('%Y%m%d') elif os.path.exists('.hg_archival.txt'):