Browse Source

set_versions.py: use backward-compatible python argument in run

Some workers on the autobuilder reported the following error:

  File "./set_versions.py", line 102, in <module>
    subprocess.run(["git", "show", "yocto-%s" % release_series[activereleases[0]]], capture_output=True, check=True)
  File "/usr/lib64/python3.6/subprocess.py", line 423, in run
    with Popen(*popenargs, **kwargs) as process:
  TypeError: __init__() got an unexpected keyword argument 'capture_output'

See https://valkyrie.yoctoproject.org/#/builders/34/builds/86.

This is because capture_output was introduced in Python 3.7, and some of
the support distributions are still on Python 3.6. Since capture_output
is essentially just setting stdout and stderr to PIPE
(https://github.com/python/cpython/blob/3.13/Lib/subprocess.py#L547), do
it manually here to be compatible with older python versions.

This is also the case for the "text" parameter, introduced in 3.7 to
alias the universal_newlines parameter. Use "universal_newlines" to be
backward-compatible.

[ YOCTO #15687 ]

Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
Tested-by: Quentin Schulz <quentin.schulz@cherry.de> # openSUSE Leap
(From yocto-docs rev: 28850c974a3896895bc921c094071523218d6d07)

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Antonin Godard 10 months ago
parent
commit
3ed2348227
1 changed files with 8 additions and 8 deletions
  1. 8 8
      documentation/set_versions.py

+ 8 - 8
documentation/set_versions.py

@@ -99,12 +99,12 @@ docconfver = None
 
 # Test tags exist and inform the user to fetch if not
 try:
-    subprocess.run(["git", "show", "yocto-%s" % release_series[activereleases[0]]], capture_output=True, check=True)
+    subprocess.run(["git", "show", "yocto-%s" % release_series[activereleases[0]]], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
 except subprocess.CalledProcessError:
     sys.exit("Please run 'git fetch --tags' before building the documentation")
 
 # Try and figure out what we are
-tags = subprocess.run(["git", "tag", "--points-at", "HEAD"], capture_output=True, text=True).stdout
+tags = subprocess.run(["git", "tag", "--points-at", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout
 for t in tags.split():
     if t.startswith("yocto-"):
         ourversion = t[6:]
@@ -122,7 +122,7 @@ if ourversion:
                 bitbakeversion = bitbake_mapping[i]
 else:
     # We're floating on a branch
-    branch = subprocess.run(["git", "branch", "--show-current"], capture_output=True, text=True).stdout.strip()
+    branch = subprocess.run(["git", "branch", "--show-current"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.strip()
     ourbranch = branch
     if branch != "master" and branch not in release_series:
         # We're not on a known release branch so we have to guess. Compare the numbers of commits
@@ -130,7 +130,7 @@ else:
         possible_branch = None
         branch_count = 0
         for b in itertools.chain(release_series.keys(), ["master"]):
-            result = subprocess.run(["git", "log", "--format=oneline",  "HEAD..origin/" + b], capture_output=True, text=True)
+            result = subprocess.run(["git", "log", "--format=oneline",  "HEAD..origin/" + b], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
             if result.returncode == 0:
                 count = result.stdout.count('\n')
                 if not possible_branch or count < branch_count:
@@ -153,9 +153,9 @@ else:
     else:
         sys.exit("Unknown series for branch %s" % branch)
 
-    previoustags = subprocess.run(["git", "tag", "--merged", "HEAD"], capture_output=True, text=True).stdout
+    previoustags = subprocess.run(["git", "tag", "--merged", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout
     previoustags = [t[6:] for t in previoustags.split() if t.startswith("yocto-" + release_series[ourseries])]
-    futuretags = subprocess.run(["git", "tag", "--merged", ourbranch], capture_output=True, text=True).stdout
+    futuretags = subprocess.run(["git", "tag", "--merged", ourbranch], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout
     futuretags = [t[6:] for t in futuretags.split() if t.startswith("yocto-" + release_series[ourseries])]
 
     # Append .999 against the last known version
@@ -228,7 +228,7 @@ with open("sphinx-static/switchers.js.in", "r") as r, open("sphinx-static/switch
             for branch in activereleases + ([ourseries] if ourseries not in activereleases else []):
                 if branch == devbranch:
                     continue
-                branch_versions = subprocess.run('git tag --list yocto-%s*' % (release_series[branch]), shell=True, capture_output=True, text=True).stdout.split()
+                branch_versions = subprocess.run('git tag --list yocto-%s*' % (release_series[branch]), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.split()
                 branch_versions = sorted([v.replace("yocto-" +  release_series[branch] + ".", "").replace("yocto-" +  release_series[branch], "0") for v in branch_versions], key=int)
                 if not branch_versions:
                     continue
@@ -273,7 +273,7 @@ def tag_to_semver_like(v):
     v_maj, v_min, v_patch = v_semver.groups('0')
     return int("{:0>2}{:0>2}{:0>2}".format(v_maj, v_min, v_patch), 10)
 
-yocto_tags = subprocess.run(["git", "tag", "--list", "--sort=version:refname", "yocto-*"], capture_output=True, text=True).stdout
+yocto_tags = subprocess.run(["git", "tag", "--list", "--sort=version:refname", "yocto-*"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout
 yocto_tags = sorted(yocto_tags.split() + missing_tags, key=tag_to_semver_like)
 tags = [tag[6:] for tag in yocto_tags]