Merge ~pappacena/turnip:fix-bytes-str-mix into turnip:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: 476a7ddb75e5e83cd5c128ec24180996e807c331
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/turnip:fix-bytes-str-mix
Merge into: turnip:master
Prerequisite: ~pappacena/turnip:make-target-py3-check
Diff against target: 134 lines (+21/-13)
6 files modified
Makefile (+4/-4)
turnip/helpers.py (+5/-1)
turnip/pack/helpers.py (+4/-1)
turnip/pack/tests/test_git.py (+3/-1)
turnip/pack/tests/test_helpers.py (+1/-1)
turnip/pack/tests/test_hooks.py (+4/-5)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+383912@code.launchpad.net

This proposal supersedes a proposal from 2020-05-13.

Commit message

Fixing bytes/str confusions to make it more compatible with python3.

To post a comment you must log in.
~pappacena/turnip:fix-bytes-str-mix updated
2321c0b... by Thiago F. Pappacena

Fixing a few more binary/str mixing

Revision history for this message
Colin Watson (cjwatson) wrote :

Could you fix the mis-sorted imports? Otherwise good.

review: Approve
~pappacena/turnip:fix-bytes-str-mix updated
476a7dd... by Thiago F. Pappacena

Sorting imports

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2index 9e6bb12..8407a6a 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -1,8 +1,8 @@
6 # Copyright 2005-2015 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9-ENV := $(CURDIR)/env
10-PY3_ENV := $(CURDIR)/py3env
11+ENV ?= $(CURDIR)/env
12+PY3_ENV ?= $(CURDIR)/py3env
13 PIP_CACHE = $(CURDIR)/pip-cache
14
15 PYTHON := $(ENV)/bin/python
16@@ -12,7 +12,7 @@ PIP := $(ENV)/bin/pip
17 VIRTUALENV := virtualenv
18
19 DEPENDENCIES_URL := https://git.launchpad.net/~canonical-launchpad-branches/turnip/+git/dependencies
20-PIP_SOURCE_DIR := dependencies
21+PIP_SOURCE_DIR ?= dependencies
22
23 PIP_ARGS ?= --quiet
24 ifneq ($(PIP_SOURCE_DIR),)
25@@ -83,7 +83,7 @@ pip-check: $(ENV)
26 check: pip-check test lint
27
28 check-python3:
29- $(MAKE) check VENV_ARGS="-p python3" ENV="$(PY3_ENV)"
30+ VENV_ARGS="-p python3" ENV="$(PY3_ENV)" $(MAKE) check
31
32 check-python-compat: check check-python3
33
34diff --git a/turnip/helpers.py b/turnip/helpers.py
35index a423aff..77e12ed 100644
36--- a/turnip/helpers.py
37+++ b/turnip/helpers.py
38@@ -9,12 +9,16 @@ from __future__ import (
39
40 import os.path
41
42+import six
43+
44
45 def compose_path(root, path):
46 # Construct the full path, stripping any leading slashes so we
47 # resolve absolute paths within the root.
48+ root = six.ensure_binary(root, "utf-8")
49 full_path = os.path.abspath(os.path.join(
50- root, path.lstrip(os.path.sep.encode('utf-8'))))
51+ root,
52+ path.lstrip(six.ensure_binary(os.path.sep, 'utf-8'))))
53 if not full_path.startswith(os.path.abspath(root)):
54 raise ValueError('Path not contained within root')
55 return full_path
56diff --git a/turnip/pack/helpers.py b/turnip/pack/helpers.py
57index f4381bb..533c967 100644
58--- a/turnip/pack/helpers.py
59+++ b/turnip/pack/helpers.py
60@@ -19,6 +19,7 @@ from tempfile import (
61 )
62
63 from pygit2 import Repository
64+import six
65 import yaml
66
67 import turnip.pack.hooks
68@@ -156,7 +157,9 @@ def ensure_hooks(repo_root):
69 target_name = 'hook.py'
70
71 def hook_path(name):
72- return os.path.join(repo_root, 'hooks', name)
73+ root = six.ensure_text(repo_root, "utf8")
74+ name = six.ensure_text(name, "utf8")
75+ return os.path.join(root, 'hooks', name)
76
77 if not os.path.exists(hook_path(target_name)):
78 need_target = True
79diff --git a/turnip/pack/tests/test_git.py b/turnip/pack/tests/test_git.py
80index 98ece7c..e5738a4 100644
81--- a/turnip/pack/tests/test_git.py
82+++ b/turnip/pack/tests/test_git.py
83@@ -12,6 +12,7 @@ import os.path
84
85 from fixtures import TempDir
86 from pygit2 import init_repository
87+import six
88 from testtools import TestCase
89 from testtools.matchers import (
90 ContainsDict,
91@@ -192,9 +193,10 @@ class TestPackBackendProtocol(TestCase):
92 # spawnProcess with appropriate arguments.
93 self.proto.requestReceived(
94 b'git-upload-pack', b'/foo.git', {b'host': b'example.com'})
95+ full_path = os.path.join(six.ensure_binary(self.root), b'foo.git')
96 self.assertEqual(
97 (b'git',
98- [b'git', b'upload-pack', os.path.join(self.root, b'foo.git')],
99+ [b'git', b'upload-pack', full_path],
100 {}),
101 self.proto.test_process)
102
103diff --git a/turnip/pack/tests/test_helpers.py b/turnip/pack/tests/test_helpers.py
104index e01406b..a7a3870 100644
105--- a/turnip/pack/tests/test_helpers.py
106+++ b/turnip/pack/tests/test_helpers.py
107@@ -125,7 +125,7 @@ class TestDecodeRequest(TestCase):
108 req = b'git-upload-pack /test_repo\0host=git.launchpad.test\0\0'
109 self.assertEqual(
110 (b'git-upload-pack', b'/test_repo',
111- {b'host': 'git.launchpad.test'}),
112+ {b'host': b'git.launchpad.test'}),
113 helpers.decode_request(req))
114
115 def test_without_parameters(self):
116diff --git a/turnip/pack/tests/test_hooks.py b/turnip/pack/tests/test_hooks.py
117index 746214e..cc785d8 100644
118--- a/turnip/pack/tests/test_hooks.py
119+++ b/turnip/pack/tests/test_hooks.py
120@@ -283,11 +283,10 @@ class TestPostReceiveHook(HookTestMixin, TestCase):
121 default_branch = subprocess.check_output(
122 ['git', 'symbolic-ref', 'HEAD']
123 ).rstrip(b'\n')
124- pushed_branch = str(default_branch + 'notdefault')
125- yield self.assertMergeProposalURLReceived([(
126- b'%s' % pushed_branch,
127- self.old_sha1, self.new_sha1)],
128- {b'%s' % pushed_branch: ['push']})
129+ pushed_branch = default_branch + b'notdefault'
130+ yield self.assertMergeProposalURLReceived(
131+ [(pushed_branch, self.old_sha1, self.new_sha1)],
132+ {pushed_branch: ['push']})
133 finally:
134 os.chdir(curdir)
135

Subscribers

People subscribed via source and target branches