convert goopy to python3
This commit is contained in:
parent
da5df1bf2e
commit
695255ea5d
@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile,v 1.14 2021/02/23 19:39:15 sthen Exp $
|
||||
# $OpenBSD: Makefile,v 1.15 2021/02/28 04:02:06 daniel Exp $
|
||||
|
||||
COMMENT= Google utilities written in Python
|
||||
|
||||
@ -13,7 +13,6 @@ PERMIT_PACKAGE= Yes
|
||||
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=goog-goopy/}
|
||||
|
||||
MODULES= lang/python
|
||||
MODPY_VERSION = ${MODPY_DEFAULT_VERSION_2}
|
||||
|
||||
do-test:
|
||||
@cd ${WRKSRC}/goopy && ${MAKE_ENV} \
|
||||
|
@ -1,12 +1,133 @@
|
||||
$OpenBSD: patch-goopy_functional_py,v 1.1.1.1 2005/03/22 13:15:03 xsa Exp $
|
||||
--- goopy/functional.py.orig Mon Mar 21 19:26:00 2005
|
||||
+++ goopy/functional.py Mon Mar 21 19:26:07 2005
|
||||
@@ -184,7 +184,7 @@ def maximum(cmp, lst):
|
||||
$OpenBSD: patch-goopy_functional_py,v 1.2 2021/02/28 04:02:07 daniel Exp $
|
||||
Index: goopy/functional.py
|
||||
--- goopy/functional.py.orig
|
||||
+++ goopy/functional.py
|
||||
@@ -31,8 +31,8 @@
|
||||
Handy things for functional style programming.
|
||||
"""
|
||||
|
||||
for i in xrange(1, len(lst)):
|
||||
-from __future__ import nested_scopes
|
||||
|
||||
+
|
||||
import math as _math
|
||||
|
||||
def some(f, lst):
|
||||
@@ -58,7 +58,7 @@ def find(p, lst, start=0):
|
||||
-1 if there is none.
|
||||
"""
|
||||
|
||||
- for i in xrange(start, len(lst)):
|
||||
+ for i in range(start, len(lst)):
|
||||
if p(lst[i]):
|
||||
return i
|
||||
|
||||
@@ -94,7 +94,7 @@ def remove_duplicates(lst, key=None):
|
||||
if key == None:
|
||||
for v in lst:
|
||||
try:
|
||||
- if not d.has_key(v):
|
||||
+ if v not in d:
|
||||
result.append(v)
|
||||
d[v] = 1
|
||||
except TypeError:
|
||||
@@ -103,7 +103,7 @@ def remove_duplicates(lst, key=None):
|
||||
for v in lst:
|
||||
thiskey = key(v)
|
||||
try:
|
||||
- if not d.has_key(thiskey):
|
||||
+ if thiskey not in d:
|
||||
result.append(v)
|
||||
d[thiskey] = 1
|
||||
except TypeError:
|
||||
@@ -117,7 +117,7 @@ def transpose(seq_of_seqs):
|
||||
SEQ_OF_SEQS must be rectangular for this to make sense.
|
||||
"""
|
||||
|
||||
- return zip(*seq_of_seqs)
|
||||
+ return list(zip(*seq_of_seqs))
|
||||
|
||||
def intersection(a, b):
|
||||
"""
|
||||
@@ -134,7 +134,7 @@ def intersection(a, b):
|
||||
d = {}
|
||||
for x in b:
|
||||
d[x] = 1
|
||||
- c = [x for x in a if d.has_key(x)]
|
||||
+ c = [x for x in a if x in d]
|
||||
except TypeError: # really want HashError
|
||||
c = [x for x in a if x in b]
|
||||
return c
|
||||
@@ -178,11 +178,11 @@ def maximum(cmp, lst):
|
||||
"""
|
||||
|
||||
if not lst:
|
||||
- raise ValueError, 'empty list'
|
||||
+ raise ValueError('empty list')
|
||||
|
||||
maxval = lst[0]
|
||||
|
||||
- for i in xrange(1, len(lst)):
|
||||
+ for i in range(1, len(lst)):
|
||||
v = lst[i]
|
||||
- if cmp(maxval, v) <= 0:
|
||||
+ if cmp(maxval, v) < 0:
|
||||
if cmp(maxval, v) < 0:
|
||||
maxval = v
|
||||
@@ -199,11 +199,11 @@ def minimum(cmp, lst):
|
||||
"""
|
||||
|
||||
return maxval
|
||||
if not lst:
|
||||
- raise ValueError, 'empty list'
|
||||
+ raise ValueError('empty list')
|
||||
|
||||
minval = lst[0]
|
||||
|
||||
- for i in xrange(1, len(lst)):
|
||||
+ for i in range(1, len(lst)):
|
||||
v = lst[i]
|
||||
if cmp(minval, v) > 0:
|
||||
minval = v
|
||||
@@ -251,8 +251,7 @@ def stddev(lst):
|
||||
def lebesgue_norm(p, lst):
|
||||
"""l_norm(p, lst) -> Lebesgue norm with parameter P for number list LST"""
|
||||
|
||||
- return ((sum(map(lambda x: float(abs(x)) ** p,
|
||||
- lst))
|
||||
+ return ((sum([float(abs(x)) ** p for x in lst])
|
||||
/ float(len(lst)))
|
||||
** (1.0 / p))
|
||||
|
||||
@@ -263,7 +262,7 @@ def list2dict(lst):
|
||||
"""
|
||||
|
||||
d = {}
|
||||
- for i in xrange(len(lst)):
|
||||
+ for i in range(len(lst)):
|
||||
d[i] = lst[i]
|
||||
return d
|
||||
|
||||
@@ -274,7 +273,7 @@ def mapdict(f, d):
|
||||
"""
|
||||
|
||||
d1 = {}
|
||||
- for k, v in d.items():
|
||||
+ for k, v in list(d.items()):
|
||||
d1[k] = f(v)
|
||||
return d1
|
||||
|
||||
@@ -287,7 +286,7 @@ def cyclic_pairs(lst):
|
||||
n = len(lst)
|
||||
assert(n >= 2)
|
||||
cps = []
|
||||
- for i in xrange(n - 1):
|
||||
+ for i in range(n - 1):
|
||||
cps.append((lst[i], lst[i + 1]))
|
||||
cps.append((lst[n - 1], lst[0]))
|
||||
return cps
|
||||
@@ -312,7 +311,7 @@ def number_of_trailing(p, lst):
|
||||
"""
|
||||
|
||||
n = len(lst)
|
||||
- for i in xrange(n - 1, -1, -1):
|
||||
+ for i in range(n - 1, -1, -1):
|
||||
if not p(lst[i]):
|
||||
return (n - 1) - i
|
||||
return len(lst)
|
||||
|
85
devel/goopy/patches/patch-goopy_functional_unittest_py
Normal file
85
devel/goopy/patches/patch-goopy_functional_unittest_py
Normal file
@ -0,0 +1,85 @@
|
||||
$OpenBSD: patch-goopy_functional_unittest_py,v 1.1 2021/02/28 04:02:07 daniel Exp $
|
||||
|
||||
Index: goopy/functional_unittest.py
|
||||
--- goopy/functional_unittest.py.orig
|
||||
+++ goopy/functional_unittest.py
|
||||
@@ -32,56 +32,56 @@
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
-from functional import *
|
||||
+from goopy.functional import *
|
||||
|
||||
|
||||
class functionalUnitTest(unittest.TestCase):
|
||||
def testSomeEvery(self):
|
||||
- assert some(lambda x: x == 5, range(10))
|
||||
- assert not every(lambda x: x == 5, range(10))
|
||||
+ assert some(lambda x: x == 5, list(range(10)))
|
||||
+ assert not every(lambda x: x == 5, list(range(10)))
|
||||
assert not some(lambda x: x == 5, [6] * 10)
|
||||
assert every(lambda x: x == 6, [6] * 10)
|
||||
|
||||
n = 0
|
||||
- for a, b in cyclic_pairs(range(5)):
|
||||
+ for a, b in cyclic_pairs(list(range(5))):
|
||||
assert a == ((b - 1) % 5)
|
||||
n += 1
|
||||
assert n == 5
|
||||
|
||||
- a = range(10)
|
||||
- b = range(5, 15)
|
||||
- c = range(20, 30)
|
||||
+ a = list(range(10))
|
||||
+ b = list(range(5, 15))
|
||||
+ c = list(range(20, 30))
|
||||
assert not intersection(a, c)
|
||||
def same_set(a, b):
|
||||
- return dict(zip(a, a)) == dict(zip(b, b))
|
||||
- assert same_set(intersection(a, b), range(5, 10))
|
||||
+ return dict(list(zip(a, a))) == dict(list(zip(b, b)))
|
||||
+ assert same_set(intersection(a, b), list(range(5, 10)))
|
||||
|
||||
def testParitionList(self):
|
||||
- matched, unmatched = partition_list(lambda x: x % 2, range(5))
|
||||
- self.assertEquals(matched, [1, 3])
|
||||
- self.assertEquals(unmatched, [0, 2, 4])
|
||||
+ matched, unmatched = partition_list(lambda x: x % 2, list(range(5)))
|
||||
+ self.assertEqual(matched, [1, 3])
|
||||
+ self.assertEqual(unmatched, [0, 2, 4])
|
||||
|
||||
def testRemoveDuplicates(self):
|
||||
- self.assertEquals(remove_duplicates(range(0, 10)
|
||||
- + range(5, 15)
|
||||
- + range(2, 12)),
|
||||
- range(0, 15))
|
||||
+ self.assertEqual(remove_duplicates(list(range(0, 10))
|
||||
+ + list(range(5, 15))
|
||||
+ + list(range(2, 12))),
|
||||
+ list(range(0, 15)))
|
||||
|
||||
def testTranspose(self):
|
||||
- self.assertEquals(transpose([range(i, i + 20)
|
||||
+ self.assertEqual(transpose([list(range(i, i + 20))
|
||||
for i in range(10)]),
|
||||
[tuple(range(j, j + 10))
|
||||
for j in range(20)])
|
||||
|
||||
def testFlatten(self):
|
||||
- self.assertEquals(flatten1(zip(range(0, 10, 2), range(1, 11, 2))),
|
||||
- range(0, 10))
|
||||
- self.assertEquals(flatten1(dict([(x, x) for x in range(3)]).items()),
|
||||
+ self.assertEqual(flatten1(list(zip(list(range(0, 10, 2)), list(range(1, 11, 2))))),
|
||||
+ list(range(0, 10)))
|
||||
+ self.assertEqual(flatten1(list(dict([(x, x) for x in range(3)]).items())),
|
||||
[0, 0, 1, 1, 2, 2])
|
||||
|
||||
- self.assertEquals(flatten([7,(6,[5,4],3),2,1]), [7,6,5,4,3,2,1])
|
||||
- self.assertEquals(flatten((4,5,3,2,1)), [4,5,3,2,1])
|
||||
- self.assertEquals(flatten(zip(zip(range(0,10,2)), range(1,11,2))),
|
||||
+ self.assertEqual(flatten([7,(6,[5,4],3),2,1]), [7,6,5,4,3,2,1])
|
||||
+ self.assertEqual(flatten((4,5,3,2,1)), [4,5,3,2,1])
|
||||
+ self.assertEqual(flatten(list(zip(list(zip(list(range(0,10,2)))), list(range(1,11,2))))),
|
||||
[0,1,2,3,4,5,6,7,8,9])
|
||||
|
||||
if __name__ == '__main__':
|
@ -1,10 +1,10 @@
|
||||
@comment $OpenBSD: PLIST,v 1.1.1.1 2005/03/22 13:15:03 xsa Exp $
|
||||
lib/python${MODPY_VERSION}/
|
||||
lib/python${MODPY_VERSION}/site-packages/
|
||||
@comment $OpenBSD: PLIST,v 1.2 2021/02/28 04:02:07 daniel Exp $
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy-0.1-py${MODPY_VERSION}.egg-info
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/__init__.py
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/__init__.pyc
|
||||
${MODPY_COMMENT}lib/python${MODPY_VERSION}/site-packages/goopy/${MODPY_PYCACHE}/
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/${MODPY_PYCACHE}__init__.${MODPY_PYC_MAGIC_TAG}pyc
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/${MODPY_PYCACHE}functional.${MODPY_PYC_MAGIC_TAG}pyc
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/${MODPY_PYCACHE}functional_unittest.${MODPY_PYC_MAGIC_TAG}pyc
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/functional.py
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/functional.pyc
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/functional_unittest.py
|
||||
lib/python${MODPY_VERSION}/site-packages/goopy/functional_unittest.pyc
|
||||
|
Loading…
x
Reference in New Issue
Block a user