launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #29576
[Merge] ~cjwatson/launchpad:unsixify-tagfile-parsing into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:unsixify-tagfile-parsing into launchpad:master.
Commit message:
Remove six from code dealing with parsed tagfiles
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/436152
`parse_tagfile_content` always returns header values as bytes (now type-annotated), so we can just use `.decode`/`.encode` rather than `six.ensure_*`.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:unsixify-tagfile-parsing into launchpad:master.
diff --git a/lib/lp/archiveuploader/changesfile.py b/lib/lp/archiveuploader/changesfile.py
index 61c722c..6f0f81d 100644
--- a/lib/lp/archiveuploader/changesfile.py
+++ b/lib/lp/archiveuploader/changesfile.py
@@ -15,8 +15,6 @@ __all__ = [
import os
-import six
-
from lp.archiveuploader.buildinfofile import BuildInfoFile
from lp.archiveuploader.dscfile import DSCFile, SignableTagFile
from lp.archiveuploader.nascentuploadfile import (
@@ -267,7 +265,7 @@ class ChangesFile(SignableTagFile):
# Urgency is recommended but not mandatory. Default to 'low'
self._dict["Urgency"] = b"low"
- raw_urgency = six.ensure_text(self._dict["Urgency"]).lower()
+ raw_urgency = self._dict["Urgency"].decode().lower()
if raw_urgency not in self.urgency_map:
yield UploadWarning(
"Unable to grok urgency %s, overriding with 'low'"
@@ -326,7 +324,7 @@ class ChangesFile(SignableTagFile):
For example, 'hoary' or 'hoary-security'.
"""
- return six.ensure_text(self._dict["Distribution"])
+ return self._dict["Distribution"].decode()
@property
def architectures(self):
@@ -335,24 +333,22 @@ class ChangesFile(SignableTagFile):
For instance ['source', 'all'] or ['source', 'i386', 'amd64']
or ['source'].
"""
- return set(six.ensure_text(self._dict["Architecture"]).split())
+ return set(self._dict["Architecture"].decode().split())
@property
def binaries(self):
"""Return set of binary package names listed."""
- return set(
- six.ensure_text(self._dict.get("Binary", "")).strip().split()
- )
+ return set(self._dict.get("Binary", "").decode().strip().split())
@property
def converted_urgency(self):
"""Return the appropriate SourcePackageUrgency item."""
- return self.urgency_map[six.ensure_text(self._dict["Urgency"]).lower()]
+ return self.urgency_map[self._dict["Urgency"].decode().lower()]
@property
def version(self):
"""Return changesfile claimed version."""
- return six.ensure_text(self._dict["Version"])
+ return self._dict["Version"].decode()
@classmethod
def formatChangesComment(cls, comment):
@@ -376,17 +372,17 @@ class ChangesFile(SignableTagFile):
@property
def date(self):
"""Return changesfile date."""
- return six.ensure_text(self._dict["Date"])
+ return self._dict["Date"].decode()
@property
def source(self):
"""Return changesfile claimed source name."""
- return six.ensure_text(self._dict["Source"])
+ return self._dict["Source"].decode()
@property
def architecture_line(self):
"""Return changesfile archicteture line."""
- return six.ensure_text(self._dict["Architecture"])
+ return self._dict["Architecture"].decode()
@property
def simulated_changelog(self):
diff --git a/lib/lp/archiveuploader/dscfile.py b/lib/lp/archiveuploader/dscfile.py
index e7516ff..59b5087 100644
--- a/lib/lp/archiveuploader/dscfile.py
+++ b/lib/lp/archiveuploader/dscfile.py
@@ -23,7 +23,6 @@ import shutil
import tempfile
import warnings
-import six
from debian.deb822 import Deb822Dict, PkgRelation
from zope.component import getUtility
@@ -220,8 +219,8 @@ class SignableTagFile:
raise UploadError("Invalid Maintainer.")
if person is None and self.policy.create_people:
- package = six.ensure_text(self._dict["Source"])
- version = six.ensure_text(self._dict["Version"])
+ package = self._dict["Source"].decode()
+ version = self._dict["Version"].decode()
if self.policy.distroseries and self.policy.pocket:
policy_suite = "%s/%s" % (
self.policy.distroseries.name,
@@ -344,8 +343,7 @@ class DSCFile(SourceUploadFile, SignableTagFile):
if self.format is None:
raise EarlyReturnUploadError(
- "Unsupported source format: %s"
- % six.ensure_str(self._dict["Format"])
+ "Unsupported source format: %s" % self._dict["Format"].decode()
)
#
@@ -354,19 +352,19 @@ class DSCFile(SourceUploadFile, SignableTagFile):
@property
def source(self):
"""Return the DSC source name."""
- return six.ensure_text(self._dict["Source"])
+ return self._dict["Source"].decode()
@property
def dsc_version(self):
"""Return the DSC source version."""
- return six.ensure_text(self._dict["Version"])
+ return self._dict["Version"].decode()
@property
def format(self):
"""Return the DSC format."""
try:
return SourcePackageFormat.getTermByToken(
- six.ensure_text(self._dict["Format"])
+ self._dict["Format"].decode()
).value
except LookupError:
return None
@@ -374,12 +372,12 @@ class DSCFile(SourceUploadFile, SignableTagFile):
@property
def architecture(self):
"""Return the DSC source architecture."""
- return six.ensure_text(self._dict["Architecture"])
+ return self._dict["Architecture"].decode()
@property
def binary(self):
"""Return the DSC claimed binary line."""
- return six.ensure_text(self._dict["Binary"])
+ return self._dict["Binary"].decode()
#
# DSC file checks.
@@ -449,7 +447,7 @@ class DSCFile(SourceUploadFile, SignableTagFile):
for field_name in ["Build-Depends", "Build-Depends-Indep"]:
field = self._dict.get(field_name, None)
if field is not None:
- field = six.ensure_text(field)
+ field = field.decode()
if field.startswith("ARRAY"):
yield UploadError(
"%s: invalid %s field produced by a broken version "
diff --git a/lib/lp/archiveuploader/tagfiles.py b/lib/lp/archiveuploader/tagfiles.py
index 7470f27..7815394 100644
--- a/lib/lp/archiveuploader/tagfiles.py
+++ b/lib/lp/archiveuploader/tagfiles.py
@@ -7,6 +7,7 @@ __all__ = ["TagFileParseError", "parse_tagfile", "parse_tagfile_content"]
import tempfile
+from typing import Dict, Optional
import apt_pkg
@@ -19,7 +20,9 @@ class TagFileParseError(Exception):
pass
-def parse_tagfile_content(content, filename=None):
+def parse_tagfile_content(
+ content: bytes, filename: Optional[str] = None
+) -> Dict[str, bytes]:
"""Parses a tag file and returns a dictionary where each field is a key.
The mandatory first argument is the contents of the tag file as a
@@ -56,7 +59,7 @@ def parse_tagfile_content(content, filename=None):
return trimmed_dict
-def parse_tagfile(filename):
+def parse_tagfile(filename: str) -> Dict[str, bytes]:
"""Parses a tag file and returns a dictionary where each field is a key.
The mandatory first argument is the filename of the tag file, and
diff --git a/lib/lp/archiveuploader/tests/nascentupload-closing-bugs.rst b/lib/lp/archiveuploader/tests/nascentupload-closing-bugs.rst
index 68eff30..4a47593 100644
--- a/lib/lp/archiveuploader/tests/nascentupload-closing-bugs.rst
+++ b/lib/lp/archiveuploader/tests/nascentupload-closing-bugs.rst
@@ -82,7 +82,7 @@ This new version fixes bug #6 according its changesfiles:
>>> print(bar2_src.changes.changed_by["person"].name)
kinnison
- >>> print(six.ensure_str(bar2_src.changes._dict["Launchpad-bugs-fixed"]))
+ >>> print(bar2_src.changes._dict["Launchpad-bugs-fixed"].decode())
6
>>> print(bar2_src.changes.changes_comment)
diff --git a/lib/lp/archiveuploader/tests/nascentuploadfile.rst b/lib/lp/archiveuploader/tests/nascentuploadfile.rst
index 357205c..78bfed5 100644
--- a/lib/lp/archiveuploader/tests/nascentuploadfile.rst
+++ b/lib/lp/archiveuploader/tests/nascentuploadfile.rst
@@ -274,8 +274,8 @@ Some fields extracted from the tag_file are required, they are always
present in ChangesFile and DSCFile:
>>> sig_file._dict = {}
- >>> sig_file._dict["Source"] = "some-source"
- >>> sig_file._dict["Version"] = "6.6.6"
+ >>> sig_file._dict["Source"] = b"some-source"
+ >>> sig_file._dict["Version"] = b"6.6.6"
After initialising sig_file we can parse addresses and look them up in
Launchpad:
diff --git a/lib/lp/archiveuploader/tests/test_dscfile.py b/lib/lp/archiveuploader/tests/test_dscfile.py
index b3365a2..23a15ca 100644
--- a/lib/lp/archiveuploader/tests/test_dscfile.py
+++ b/lib/lp/archiveuploader/tests/test_dscfile.py
@@ -168,8 +168,8 @@ class TestSignableTagFile(TestCaseWithFactory):
tagfile.logger = DevNullLogger()
tagfile.policy = FakePolicy(None, None, create_people=True)
tagfile._dict = {
- "Source": "arbitrary-source-package-name",
- "Version": "1.0",
+ "Source": b"arbitrary-source-package-name",
+ "Version": b"1.0",
}
return tagfile
diff --git a/lib/lp/soyuz/doc/soyuz-upload.rst b/lib/lp/soyuz/doc/soyuz-upload.rst
index f32f5f7..b456a95 100644
--- a/lib/lp/soyuz/doc/soyuz-upload.rst
+++ b/lib/lp/soyuz/doc/soyuz-upload.rst
@@ -60,14 +60,14 @@ been uploaded over FTP.
... tf = {}
...
... if "Source" in tf:
- ... package_names.append(six.ensure_text(tf["Source"]))
+ ... package_names.append(tf["Source"].decode())
...
... send_filepaths = [changes_filepath]
... if "Files" in tf:
... send_filepaths.extend(
... [
... os.path.join(test_files_dir, line.split()[-1])
- ... for line in six.ensure_text(tf["Files"]).splitlines()
+ ... for line in tf["Files"].decode().splitlines()
... if line
... ]
... )
diff --git a/lib/lp/soyuz/scripts/gina/archive.py b/lib/lp/soyuz/scripts/gina/archive.py
index f283190..ad06de5 100644
--- a/lib/lp/soyuz/scripts/gina/archive.py
+++ b/lib/lp/soyuz/scripts/gina/archive.py
@@ -20,7 +20,6 @@ import tempfile
from collections import defaultdict
import apt_pkg
-import six
from lp.services.scripts import log
from lp.soyuz.scripts.gina import call
@@ -236,10 +235,8 @@ class PackagesMap:
for section in sources:
try:
src_tmp = dict(section)
- src_tmp["Component"] = six.ensure_binary(
- info_set.component
- )
- src_name = six.ensure_text(src_tmp["Package"])
+ src_tmp["Component"] = info_set.component.encode()
+ src_name = src_tmp["Package"].decode()
except KeyError:
log.exception(
"Invalid Sources stanza in %s",
@@ -267,10 +264,8 @@ class PackagesMap:
try:
bin_tmp = dict(section)
# The component isn't listed in the tagfile.
- bin_tmp["Component"] = six.ensure_binary(
- info_set.component
- )
- bin_name = six.ensure_text(bin_tmp["Package"])
+ bin_tmp["Component"] = info_set.component.encode()
+ bin_name = bin_tmp["Package"].decode()
except KeyError:
log.exception(
"Invalid Releases stanza in %s",
@@ -284,10 +279,8 @@ class PackagesMap:
for section in dibinaries:
try:
dibin_tmp = dict(section)
- dibin_tmp["Component"] = six.ensure_binary(
- info_set.component
- )
- dibin_name = six.ensure_text(dibin_tmp["Package"])
+ dibin_tmp["Component"] = info_set.component.encode()
+ dibin_name = dibin_tmp["Package"].decode()
except KeyError:
log.exception(
"Invalid D-I Releases stanza in %s" % info_set.difile
diff --git a/lib/lp/soyuz/scripts/tests/test_gina.py b/lib/lp/soyuz/scripts/tests/test_gina.py
index 3c37297..edff14e 100644
--- a/lib/lp/soyuz/scripts/tests/test_gina.py
+++ b/lib/lp/soyuz/scripts/tests/test_gina.py
@@ -11,7 +11,6 @@ from textwrap import dedent
from unittest import TestLoader
import apt_pkg
-import six
import transaction
from fixtures import EnvironmentVariableFixture
from testtools.matchers import MatchesSetwise, MatchesStructure
@@ -338,7 +337,7 @@ class TestSourcePackageData(TestCaseWithFactory):
)
dsc_contents = parse_tagfile(dsc_path)
- dsc_contents["Directory"] = six.ensure_binary(pool_dir)
+ dsc_contents["Directory"] = pool_dir.encode()
dsc_contents["Package"] = b"foo"
dsc_contents["Component"] = b"main"
dsc_contents["Section"] = b"misc"
@@ -409,7 +408,7 @@ class TestSourcePackageData(TestCaseWithFactory):
)
dsc_contents = parse_tagfile(dsc_path)
- dsc_contents["Directory"] = six.ensure_binary(pool_dir)
+ dsc_contents["Directory"] = pool_dir.encode()
dsc_contents["Package"] = b"foo"
dsc_contents["Component"] = b"main"
dsc_contents["Section"] = b"misc"