From 39c9132d2ce2de7ea9b6a1b5fd67e4b96f8b3f14 Mon Sep 17 00:00:00 2001 From: tinywrkb Date: Mon, 7 Sep 2020 15:32:59 +0300 Subject: [PATCH] libkkc-data: import debian py3 patch --- ...s-Import-upstream-py3-compat-version.patch | 173 ++++++++++++++++++ repos/community-x86_64/PKGBUILD | 18 +- 2 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 repos/community-x86_64/0001-tools-Import-upstream-py3-compat-version.patch diff --git a/repos/community-x86_64/0001-tools-Import-upstream-py3-compat-version.patch b/repos/community-x86_64/0001-tools-Import-upstream-py3-compat-version.patch new file mode 100644 index 00000000..05fbf6d0 --- /dev/null +++ b/repos/community-x86_64/0001-tools-Import-upstream-py3-compat-version.patch @@ -0,0 +1,173 @@ +From: Boyuan Yang +Date: Wed, 13 Nov 2019 19:34:30 -0500 +Subject: tools: Import upstream py3-compat version + +--- + configure.ac | 2 +- + tools/genfilter.py | 24 ++++++++++++------------ + tools/sortlm.py | 29 +++++++++++++---------------- + 3 files changed, 26 insertions(+), 29 deletions(-) + +diff --git a/configure.ac b/configure.ac +index c18208e..6a8ee1a 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -28,7 +28,7 @@ dnl Check for programs + AC_PROG_INSTALL + + dnl Check python +-AM_PATH_PYTHON ++AM_PATH_PYTHON([3]) + + AC_CONFIG_FILES([Makefile + data/Makefile +diff --git a/tools/genfilter.py b/tools/genfilter.py +index 97645d5..3a06d9d 100644 +--- a/tools/genfilter.py ++++ b/tools/genfilter.py +@@ -1,7 +1,7 @@ +-#!/usr/bin/python ++#!/usr/bin/python3 + +-# Copyright (C) 2011-2013 Daiki Ueno +-# Copyright (C) 2011-2013 Red Hat, Inc. ++# Copyright (C) 2011-2014 Daiki Ueno ++# Copyright (C) 2011-2014 Red Hat, Inc. + + # This program is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by +@@ -84,24 +84,24 @@ class FilterGenerator(object): + + def generate(self): + size = os.fstat(self.infile.fileno()).st_size +- n = size / self.record_size ++ n = size // self.record_size + m = int(math.ceil(-n*math.log10(ERROR_RATE) / + math.pow(math.log10(2), 2))) +- m = (m/8 + 1)*8 ++ m = (m//8 + 1)*8 + inmem = mmap.mmap(self.infile.fileno(), + size, + access=mmap.ACCESS_READ) +- outmem = bytearray(m/8) +- for i in xrange(0, n): ++ outmem = bytearray(m//8) ++ for i in range(0, n): + offset = i*self.record_size + b0, b1 = struct.unpack("=LL", inmem[offset:offset+8]) +- for k in xrange(0, 4): ++ for k in range(0, 4): + h = murmur_hash3_32(b0, b1, k) + h = int(h * (m / float(0xFFFFFFFF))) +- outmem[h/8] |= (1 << (h%8)) ++ outmem[h//8] |= (1 << (h%8)) + inmem.close() +- # Convert bytearray to str, for Python 2.6 compatibility. +- self.outfile.write(str(outmem)) ++ # Convert bytearray to bytes, for Python 3 compatibility. ++ self.outfile.write(bytes(outmem)) + + if __name__ == '__main__': + import sys +@@ -110,7 +110,7 @@ if __name__ == '__main__': + parser = argparse.ArgumentParser(description='filter') + parser.add_argument('infile', type=argparse.FileType('r'), + help='input file') +- parser.add_argument('outfile', type=argparse.FileType('w'), ++ parser.add_argument('outfile', type=argparse.FileType('wb'), + help='output file') + parser.add_argument('record_size', type=int, + help='record size') +diff --git a/tools/sortlm.py b/tools/sortlm.py +index 9c76afe..fe80ddc 100644 +--- a/tools/sortlm.py ++++ b/tools/sortlm.py +@@ -1,7 +1,7 @@ +-#!/usr/bin/python ++#!/usr/bin/python3 + +-# Copyright (C) 2011-2013 Daiki Ueno +-# Copyright (C) 2011-2013 Red Hat, Inc. ++# Copyright (C) 2011-2014 Daiki Ueno ++# Copyright (C) 2011-2014 Red Hat, Inc. + + # This program is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by +@@ -40,10 +40,10 @@ class SortedGenerator(object): + self.__min_cost = 0.0 + + def read(self): +- print "reading N-grams" ++ print("reading N-grams") + self.__read_tries() + self.__read_ngrams() +- print "min cost = %lf" % self.__min_cost ++ print("min cost = %lf" % self.__min_cost) + + def __read_tries(self): + while True: +@@ -58,7 +58,7 @@ class SortedGenerator(object): + line = self.__infile.readline() + if line == "": + break +- line = line.strip() ++ line = line.strip('\n') + if line == "": + break + match = self.__ngram_line_regex.match(line) +@@ -89,7 +89,7 @@ class SortedGenerator(object): + line = self.__infile.readline() + if line == "": + break +- line = line.strip() ++ line = line.strip('\n') + if line == "": + break + match = self.__ngram_line_regex.match(line) +@@ -125,14 +125,11 @@ class SortedGenerator(object): + def quantize(cost, min_cost): + return max(0, min(65535, int(cost * 65535 / min_cost))) + +- def cmp_header(a, b): +- return cmp(a[0], b[0]) +- +- print "writing 1-gram file" ++ print("writing 1-gram file") + unigram_offsets = {} + unigram_file = open("%s.1gram" % self.__output_prefix, "wb") + offset = 0 +- for ids, value in sorted(self.__ngram_entries[0].iteritems()): ++ for ids, value in sorted(self.__ngram_entries[0].items()): + unigram_offsets[ids[0]] = offset + s = struct.pack("=HHH", + quantize(value[0], self.__min_cost), +@@ -143,13 +140,13 @@ class SortedGenerator(object): + offset += 1 + unigram_file.close() + +- print "writing 2-gram file" ++ print("writing 2-gram file") + bigram_offsets = {} + bigram_file = open("%s.2gram" % self.__output_prefix, "wb") + keys = self.__ngram_entries[1].keys() + items = [(struct.pack("=LL", ids[1], unigram_offsets[ids[0]]), ids) for ids in keys] + offset = 0 +- for header, ids in sorted(items, cmp=cmp_header): ++ for header, ids in sorted(items, key=lambda x: x[0]): + value = self.__ngram_entries[1][ids] + bigram_offsets[ids] = offset + s = struct.pack("=HH", +@@ -160,11 +157,11 @@ class SortedGenerator(object): + bigram_file.close() + + if len(self.__ngram_entries[2]) > 0: +- print "writing 3-gram file" ++ print("writing 3-gram file") + trigram_file = open("%s.3gram" % self.__output_prefix, "wb") + keys = self.__ngram_entries[2].keys() + items = [(struct.pack("=LL", ids[2], bigram_offsets[(ids[0], ids[1])]), ids) for ids in keys] +- for header, ids in sorted(items, cmp=cmp_header): ++ for header, ids in sorted(items, key=lambda x: x[0]): + value = self.__ngram_entries[2][ids] + s = struct.pack("=H", + quantize(value[0], self.__min_cost)) diff --git a/repos/community-x86_64/PKGBUILD b/repos/community-x86_64/PKGBUILD index c920c566..887fa847 100644 --- a/repos/community-x86_64/PKGBUILD +++ b/repos/community-x86_64/PKGBUILD @@ -4,18 +4,25 @@ pkgname=libkkc-data pkgver=0.2.7 -pkgrel=2 +pkgrel=3 _kkcver=0.3.5 pkgdesc="Language model data package for libkkc" arch=('x86_64') url="https://github.com/ueno/libkkc" license=('GPL') -makedepends=('python2-marisa') -source=(https://github.com/ueno/libkkc/releases/download/v$_kkcver/libkkc-data-$pkgver.tar.xz) +makedepends=('python-marisa') +source=(https://github.com/ueno/libkkc/releases/download/v$_kkcver/libkkc-data-$pkgver.tar.xz + 0001-tools-Import-upstream-py3-compat-version.patch) + +prepare() { + cd "${pkgname}-${pkgver}" + patch -Np1 -i "${srcdir}"/0001-tools-Import-upstream-py3-compat-version.patch +} build() { cd "${pkgname}-${pkgver}" - ./configure PYTHON=/usr/bin/python2 --prefix=/usr + autoreconf -vi + ./configure --prefix=/usr make } @@ -24,4 +31,5 @@ package() { make DESTDIR="$pkgdir" install } -sha512sums=('61c0cd8c0fa41ed8df49cac6709eebb245cc965d7e192b1ba945e95f2fc46aca8aa48c16e1977a12c157c55dab6b9f4c30f4905806725eca6e697b762eb7cbd7') +sha512sums=('61c0cd8c0fa41ed8df49cac6709eebb245cc965d7e192b1ba945e95f2fc46aca8aa48c16e1977a12c157c55dab6b9f4c30f4905806725eca6e697b762eb7cbd7' + '2036ce563e01a69e3ab3a2068f1a63c3e885d47b2078c482f3eb705af0395ab7e0de7f7ed644db8b27fd1dc7f5a4ec42d643166ddbce14ede123d140c90962f1') -- 2.28.0