[jhbuild] hg: Port to Python 3
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jhbuild] hg: Port to Python 3
- Date: Sat, 19 Oct 2019 08:44:39 +0000 (UTC)
commit c9a80e57aaeb8576fa2d861fc096162eed1bd856
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sat Oct 19 10:41:14 2019 +0200
hg: Port to Python 3
Use sys.executable to run hg-update.py with the current interpreter.
Decode output of external commands everywhere to get the same result
with py2/3.
Change the hg-update.py shebang to python3 for Debian's linitan.
Fixes #39
jhbuild/versioncontrol/hg.py | 7 ++++---
scripts/hg-update.py | 6 +++---
2 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/jhbuild/versioncontrol/hg.py b/jhbuild/versioncontrol/hg.py
index a9406ca7..6e79b4e6 100644
--- a/jhbuild/versioncontrol/hg.py
+++ b/jhbuild/versioncontrol/hg.py
@@ -22,11 +22,12 @@ __all__ = []
__metaclass__ = type
import os
+import sys
from subprocess import Popen, PIPE
from jhbuild.errors import FatalError, CommandError
from jhbuild.versioncontrol import Repository, Branch, register_repo_type
-from jhbuild.utils import inpath, _, urlutils
+from jhbuild.utils import inpath, _, urlutils, udecode
class HgRepository(Repository):
"""A class representing a Mercurial repository.
@@ -97,7 +98,7 @@ class HgBranch(Branch):
else:
hg_update_path = os.path.join(PKGDATADIR, 'hg-update.py')
hg_update_path = os.path.normpath(hg_update_path)
- buildscript.execute([hg_update_path], 'hg', cwd=self.srcdir)
+ buildscript.execute([sys.executable, hg_update_path], 'hg', cwd=self.srcdir)
def checkout(self, buildscript):
if not inpath('hg', os.environ['PATH'].split(os.pathsep)):
@@ -111,7 +112,7 @@ class HgBranch(Branch):
cwd=self.srcdir)
except OSError as e:
raise CommandError(str(e))
- return hg.stdout.read().strip()
+ return udecode(hg.stdout.read()).strip()
def tree_id(self):
if not os.path.exists(self.srcdir):
diff --git a/scripts/hg-update.py b/scripts/hg-update.py
index 80cf8f6e..64c66396 100755
--- a/scripts/hg-update.py
+++ b/scripts/hg-update.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2
+#! /usr/bin/env python3
#
# hg-update - pull and update a mercurial repository
#
@@ -27,7 +27,7 @@ import re
from subprocess import Popen, call, PIPE, STDOUT
def get_parent():
- hg = Popen(['hg', 'parents', '--template', '{rev}'], stdout=PIPE)
+ hg = Popen(['hg', 'parents', '--template', '{rev}'], stdout=PIPE, universal_newlines=True)
try:
return hg.stdout.read().split()[0]
except IndexError:
@@ -43,7 +43,7 @@ def update():
env['HGMERGE'] = '/bin/false'
env['LANG'] = 'C'
hg = Popen(['hg', 'update', '--noninteractive'], stdout=PIPE,
- stderr=STDOUT, env=env)
+ stderr=STDOUT, env=env, universal_newlines=True)
out = hg.communicate()[0]
if hg.returncode != 0:
# Use CVS-like format for conflicts.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]