Skip to content

Commit f11c5a3

Browse files
committed
devtools: make github-merge.py use py3
This makes github-merge.py the first developer tool to go all Python 3 (for context see #7717). The changes are straightforward as the script already was `from __future__ import division,print_function,unicode_literals`. However urllib2 changed name, and json will only accept unicode data not bytes. This retains py2 compatibility for now: not strictly necessary as it's not used by the build system - but it was easy.
1 parent 4900641 commit f11c5a3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

contrib/devtools/github-merge.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# Copyright (c) 2016 Bitcoin Core Developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -19,6 +19,11 @@
1919
from sys import stdin,stdout,stderr
2020
import argparse
2121
import subprocess
22+
import json,codecs
23+
try:
24+
from urllib.request import Request,urlopen
25+
except:
26+
from urllib2 import Request,urlopen
2227

2328
# External tools (can be overridden using environment)
2429
GIT = os.getenv('GIT','git')
@@ -38,7 +43,7 @@ def git_config_get(option, default=None):
3843
Get named configuration option from git repository.
3944
'''
4045
try:
41-
return subprocess.check_output([GIT,'config','--get',option]).rstrip()
46+
return subprocess.check_output([GIT,'config','--get',option]).rstrip().decode('utf-8')
4247
except subprocess.CalledProcessError as e:
4348
return default
4449

@@ -47,18 +52,19 @@ def retrieve_pr_title(repo,pull):
4752
Retrieve pull request title from github.
4853
Return None if no title can be found, or an error happens.
4954
'''
50-
import urllib2,json
5155
try:
52-
req = urllib2.Request("https://api.github.com/repos/"+repo+"/pulls/"+pull)
53-
result = urllib2.urlopen(req)
54-
result = json.load(result)
55-
return result['title']
56+
req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull)
57+
result = urlopen(req)
58+
reader = codecs.getreader('utf-8')
59+
obj = json.load(reader(result))
60+
return obj['title']
5661
except Exception as e:
5762
print('Warning: unable to retrieve pull title from github: %s' % e)
5863
return None
5964

6065
def ask_prompt(text):
6166
print(text,end=" ",file=stderr)
67+
stderr.flush()
6268
reply = stdin.readline().rstrip()
6369
print("",file=stderr)
6470
return reply

0 commit comments

Comments
 (0)