From e8fdd7a83cd556521e6082391326a9ebd45ac1f3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 12 Jun 2018 18:01:55 +0530 Subject: [PATCH] Migrate git hooks to py3 --- setup/git_post_checkout_hook.py | 8 +++----- setup/git_post_rewrite_hook.py | 4 +--- setup/git_pre_commit_hook.py | 14 ++++++++------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/setup/git_post_checkout_hook.py b/setup/git_post_checkout_hook.py index 24e393ed9b..74de3ad82a 100755 --- a/setup/git_post_checkout_hook.py +++ b/setup/git_post_checkout_hook.py @@ -1,7 +1,5 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # vim:fileencoding=utf-8 -from __future__ import (unicode_literals, division, absolute_import, - print_function) __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' @@ -19,9 +17,9 @@ base = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) os.chdir(base) if flags == '1': # A branch checkout - prev_branch, cur_branch = map(get_branch_name, (prev_rev, current_rev)) + prev_branch, cur_branch = list(map(get_branch_name, (prev_rev, current_rev))) - subprocess.check_call([sys.executable, 'setup.py', 'gui', '--summary']) + subprocess.check_call(['python2', 'setup.py', 'gui', '--summary']) # Remove .pyc files as some of them might have been orphaned for dirpath, dirnames, filenames in os.walk('.'): diff --git a/setup/git_post_rewrite_hook.py b/setup/git_post_rewrite_hook.py index c989a70032..bd059b11bf 100755 --- a/setup/git_post_rewrite_hook.py +++ b/setup/git_post_rewrite_hook.py @@ -1,7 +1,5 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # vim:fileencoding=utf-8 -from __future__ import (unicode_literals, division, absolute_import, - print_function) __license__ = 'GPL v3' __copyright__ = '2014, Kovid Goyal ' diff --git a/setup/git_pre_commit_hook.py b/setup/git_pre_commit_hook.py index b992208168..aa308215ae 100755 --- a/setup/git_pre_commit_hook.py +++ b/setup/git_pre_commit_hook.py @@ -1,14 +1,16 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2008, Kovid Goyal -from __future__ import absolute_import, division, print_function, unicode_literals + import importlib import json import re import socket import sys -import urllib +import urllib.error +import urllib.parse +import urllib.request from lxml import html @@ -41,14 +43,14 @@ class Bug: self.seen.add(bug) if int(bug) > 100000: # Launchpad bug - raw = urllib.urlopen(LAUNCHPAD_BUG % bug).read() + raw = urllib.request.urlopen(LAUNCHPAD_BUG % bug).read() try: h1 = html.fromstring(raw).xpath('//h1[@id="edit-title"]')[0] - summary = html.tostring(h1, method='text', encoding=unicode).strip() + summary = html.tostring(h1, method='text', encoding=str).strip() except: summary = 'Private bug' else: - summary = json.loads(urllib.urlopen(GITHUB_BUG % bug).read())['title'] + summary = json.loads(urllib.request.urlopen(GITHUB_BUG % bug).read())['title'] if summary: print('Working on bug:', summary) if int(bug) > 100000 and action != 'See':