# HG changeset patch # User Mathias De Mare # Date 1678785788 -3600 # Node ID 7b6ea46ea11146adc3a2a70761864bf752c772c8 # Parent fba806958dba493dc0761439aacc00f39e813672 setup.py: clean up use of os.popen diff -r fba806958dba -r 7b6ea46ea111 setup.py --- 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'):