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
diff --git a/Makefile b/Makefile
index 9e6bb12..8407a6a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
1# Copyright 2005-2015 Canonical Ltd. This software is licensed under the1# Copyright 2005-2015 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4ENV := $(CURDIR)/env4ENV ?= $(CURDIR)/env
5PY3_ENV := $(CURDIR)/py3env5PY3_ENV ?= $(CURDIR)/py3env
6PIP_CACHE = $(CURDIR)/pip-cache6PIP_CACHE = $(CURDIR)/pip-cache
77
8PYTHON := $(ENV)/bin/python8PYTHON := $(ENV)/bin/python
@@ -12,7 +12,7 @@ PIP := $(ENV)/bin/pip
12VIRTUALENV := virtualenv12VIRTUALENV := virtualenv
1313
14DEPENDENCIES_URL := https://git.launchpad.net/~canonical-launchpad-branches/turnip/+git/dependencies14DEPENDENCIES_URL := https://git.launchpad.net/~canonical-launchpad-branches/turnip/+git/dependencies
15PIP_SOURCE_DIR := dependencies15PIP_SOURCE_DIR ?= dependencies
1616
17PIP_ARGS ?= --quiet17PIP_ARGS ?= --quiet
18ifneq ($(PIP_SOURCE_DIR),)18ifneq ($(PIP_SOURCE_DIR),)
@@ -83,7 +83,7 @@ pip-check: $(ENV)
83check: pip-check test lint83check: pip-check test lint
8484
85check-python3:85check-python3:
86 $(MAKE) check VENV_ARGS="-p python3" ENV="$(PY3_ENV)"86 VENV_ARGS="-p python3" ENV="$(PY3_ENV)" $(MAKE) check
8787
88check-python-compat: check check-python388check-python-compat: check check-python3
8989
diff --git a/turnip/helpers.py b/turnip/helpers.py
index a423aff..77e12ed 100644
--- a/turnip/helpers.py
+++ b/turnip/helpers.py
@@ -9,12 +9,16 @@ from __future__ import (
99
10import os.path10import os.path
1111
12import six
13
1214
13def compose_path(root, path):15def compose_path(root, path):
14 # Construct the full path, stripping any leading slashes so we16 # Construct the full path, stripping any leading slashes so we
15 # resolve absolute paths within the root.17 # resolve absolute paths within the root.
18 root = six.ensure_binary(root, "utf-8")
16 full_path = os.path.abspath(os.path.join(19 full_path = os.path.abspath(os.path.join(
17 root, path.lstrip(os.path.sep.encode('utf-8'))))20 root,
21 path.lstrip(six.ensure_binary(os.path.sep, 'utf-8'))))
18 if not full_path.startswith(os.path.abspath(root)):22 if not full_path.startswith(os.path.abspath(root)):
19 raise ValueError('Path not contained within root')23 raise ValueError('Path not contained within root')
20 return full_path24 return full_path
diff --git a/turnip/pack/helpers.py b/turnip/pack/helpers.py
index f4381bb..533c967 100644
--- a/turnip/pack/helpers.py
+++ b/turnip/pack/helpers.py
@@ -19,6 +19,7 @@ from tempfile import (
19 )19 )
2020
21from pygit2 import Repository21from pygit2 import Repository
22import six
22import yaml23import yaml
2324
24import turnip.pack.hooks25import turnip.pack.hooks
@@ -156,7 +157,9 @@ def ensure_hooks(repo_root):
156 target_name = 'hook.py'157 target_name = 'hook.py'
157158
158 def hook_path(name):159 def hook_path(name):
159 return os.path.join(repo_root, 'hooks', name)160 root = six.ensure_text(repo_root, "utf8")
161 name = six.ensure_text(name, "utf8")
162 return os.path.join(root, 'hooks', name)
160163
161 if not os.path.exists(hook_path(target_name)):164 if not os.path.exists(hook_path(target_name)):
162 need_target = True165 need_target = True
diff --git a/turnip/pack/tests/test_git.py b/turnip/pack/tests/test_git.py
index 98ece7c..e5738a4 100644
--- a/turnip/pack/tests/test_git.py
+++ b/turnip/pack/tests/test_git.py
@@ -12,6 +12,7 @@ import os.path
1212
13from fixtures import TempDir13from fixtures import TempDir
14from pygit2 import init_repository14from pygit2 import init_repository
15import six
15from testtools import TestCase16from testtools import TestCase
16from testtools.matchers import (17from testtools.matchers import (
17 ContainsDict,18 ContainsDict,
@@ -192,9 +193,10 @@ class TestPackBackendProtocol(TestCase):
192 # spawnProcess with appropriate arguments.193 # spawnProcess with appropriate arguments.
193 self.proto.requestReceived(194 self.proto.requestReceived(
194 b'git-upload-pack', b'/foo.git', {b'host': b'example.com'})195 b'git-upload-pack', b'/foo.git', {b'host': b'example.com'})
196 full_path = os.path.join(six.ensure_binary(self.root), b'foo.git')
195 self.assertEqual(197 self.assertEqual(
196 (b'git',198 (b'git',
197 [b'git', b'upload-pack', os.path.join(self.root, b'foo.git')],199 [b'git', b'upload-pack', full_path],
198 {}),200 {}),
199 self.proto.test_process)201 self.proto.test_process)
200202
diff --git a/turnip/pack/tests/test_helpers.py b/turnip/pack/tests/test_helpers.py
index e01406b..a7a3870 100644
--- a/turnip/pack/tests/test_helpers.py
+++ b/turnip/pack/tests/test_helpers.py
@@ -125,7 +125,7 @@ class TestDecodeRequest(TestCase):
125 req = b'git-upload-pack /test_repo\0host=git.launchpad.test\0\0'125 req = b'git-upload-pack /test_repo\0host=git.launchpad.test\0\0'
126 self.assertEqual(126 self.assertEqual(
127 (b'git-upload-pack', b'/test_repo',127 (b'git-upload-pack', b'/test_repo',
128 {b'host': 'git.launchpad.test'}),128 {b'host': b'git.launchpad.test'}),
129 helpers.decode_request(req))129 helpers.decode_request(req))
130130
131 def test_without_parameters(self):131 def test_without_parameters(self):
diff --git a/turnip/pack/tests/test_hooks.py b/turnip/pack/tests/test_hooks.py
index 746214e..cc785d8 100644
--- a/turnip/pack/tests/test_hooks.py
+++ b/turnip/pack/tests/test_hooks.py
@@ -283,11 +283,10 @@ class TestPostReceiveHook(HookTestMixin, TestCase):
283 default_branch = subprocess.check_output(283 default_branch = subprocess.check_output(
284 ['git', 'symbolic-ref', 'HEAD']284 ['git', 'symbolic-ref', 'HEAD']
285 ).rstrip(b'\n')285 ).rstrip(b'\n')
286 pushed_branch = str(default_branch + 'notdefault')286 pushed_branch = default_branch + b'notdefault'
287 yield self.assertMergeProposalURLReceived([(287 yield self.assertMergeProposalURLReceived(
288 b'%s' % pushed_branch,288 [(pushed_branch, self.old_sha1, self.new_sha1)],
289 self.old_sha1, self.new_sha1)],289 {pushed_branch: ['push']})
290 {b'%s' % pushed_branch: ['push']})
291 finally:290 finally:
292 os.chdir(curdir)291 os.chdir(curdir)
293292

Subscribers

People subscribed via source and target branches