Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions pool_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def hardlink_or_copy(src: AnyPath, dst: AnyPath) -> None:


@contextmanager
def in_dir(path: AnyPath) -> Generator[None, None, None]:
def in_dir(path: AnyPath) -> Generator[None]:
"""context manager to perform an operation within a specified directory"""
cwd = os.getcwd()
try:
Expand All @@ -162,7 +162,7 @@ def in_dir(path: AnyPath) -> Generator[None, None, None]:
class PackageCache:
"""Class representing the pool's package cache"""

def _list_binaries(self) -> Generator[str, None, None]:
def _list_binaries(self) -> Generator[str]:
"""List binaries in package cache -> list of package filenames"""
for filename in os.listdir(self.path):
filepath = join(self.path, filename)
Expand Down Expand Up @@ -431,7 +431,7 @@ def dup_branch(branch: str) -> None:
v = orig.rev_parse(tag)
assert v is not None
checkout.update_ref(f"refs/tags/{tag}", v)
except: # TODO don't use bare except!
except BaseException: # TODO don't use bare except!
continue

return checkout_path
Expand Down Expand Up @@ -729,14 +729,12 @@ def unregister(self, stock_ref: str) -> None:
blacklist: set[tuple[str, str]] = set()
for path, versions in stock.sources:
name = basename(path)
blacklist |= set([(name, version) for version in versions])
blacklist |= {(name, version) for version in versions}

blacklist |= set(
[
parse_package_filename(basename(path))
for path in stock.binaries
]
)
blacklist |= {
parse_package_filename(basename(path))
for path in stock.binaries
}

removelist = set(self.pkgcache.list()) & blacklist
for name, version in removelist:
Expand Down Expand Up @@ -936,7 +934,7 @@ def _list(
for stock in self.stocks:
for path, versions in stock.sources:
package = basename(path)
packages |= set([(package, version) for version in versions])
packages |= {(package, version) for version in versions}

if all_versions:
return list(packages)
Expand Down Expand Up @@ -1189,7 +1187,7 @@ def gc(self, recurse: bool = True, verbose: bool = True) -> None:
for stock in self.stocks:
for path, versions in stock.sources:
name = basename(path)
whitelist |= set([(name, version) for version in versions])
whitelist |= {(name, version) for version in versions}

whitelist |= {
parse_package_filename(basename(path))
Expand Down
30 changes: 15 additions & 15 deletions tests/classforked.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class Error(Exception):
class Pipe:
def __init__(self):
r, w = os.pipe()
self.r = os.fdopen(r, "r", 0)
self.w = os.fdopen(w, "w", 0)
self.r = os.fdopen(r, "rb", 0)
self.w = os.fdopen(w, "wb", 0)

import new
import types
class ProxyInstance:
"""This proxy class only proxies method invocations - no attributes"""
def __init__(self, r, w):
Expand All @@ -39,17 +39,17 @@ def __init__(self, r, w):
def _proxy(attrname):
def method(self, *args, **kws):
pickle.dump((attrname, args, kws), self.w)
self.w.flush()
error, val = pickle.load(self.r)
if error:
raise val
return val
return method

def __getattr__(self, name):
print "GETATTR"
print("GETATTR")
unbound_method = self._proxy(name)
method = new.instancemethod(unbound_method,
self, self.__class__)
method = types.MethodType(unbound_method, self)
setattr(self, name, method)
return method

Expand Down Expand Up @@ -87,20 +87,20 @@ def Foo():

ret = attr(*args, **kws)
pickle.dump((False, ret), w)
except Exception, e:
w.flush()
except Exception as e:
pickle.dump((True, e), w)
w.flush()

sys.exit(0)

return ProxyInstance(r, w)

print "caller pid: %d" % os.getpid()
print("caller pid: %d" % os.getpid())
foo = Foo()
print "1 + 1 = %d" % foo.add(1, 1)
print "dict: " + `foo.makedict("liraz", age=26)`
print("1 + 1 = %d" % foo.add(1, 1))
print("dict: " + repr(foo.makedict("liraz", age=26)))

print "foo pid: %d" % foo.getpid()
print "foo pid: %d" % foo.getpid()
print "foo uid: %d" % foo.getuid()


print("foo pid: %d" % foo.getpid())
print("foo pid: %d" % foo.getpid())
print("foo uid: %d" % foo.getuid())
11 changes: 5 additions & 6 deletions tests/constructor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class B(object):
def __init__(self, b):
print "B.__init__"
print("B.__init__")
self.b = b

def get(self):
Expand All @@ -10,14 +10,13 @@ class A(B):
def __new__(self, a):
return a
return B(a)
print "__new__(%s)" % `a`
print("__new__(%s)" % repr(a))
a = object.__new__(self, a)
print "foo"
print("foo")
return a

# return super(A, self).__new__(self, a) ## equivalent

def __init__(self, a):
print "__init__(%s)" % `a`
self.a = a

print("__init__(%s)" % repr(a))
self.a = a
6 changes: 4 additions & 2 deletions tests/debversion.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import re


def deb_compare_versions(a, b):
"""Compare a with b according to Debian versioning criteria"""

def normalize(v):
return re.sub(r'(\D|\b)0+', r'\1', v).rstrip("-")

return cmp(normalize(a), normalize(b))


def main():
dcv = deb_compare_versions
assert dcv('1', '2') < 0
Expand All @@ -18,6 +20,6 @@ def main():
assert dcv('1.1', '1-1') > 0
assert dcv('1', '1-000') == 0


if __name__ == "__main__":
main()

1 change: 0 additions & 1 deletion tests/emulcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ def __setitem__(self, key, val):

def __iter__(self):
return iter(self.arr)

5 changes: 2 additions & 3 deletions tests/modifydefault.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ def func(var, arr=[]):

return arr

print `func(1)`
print `func(2)`

print(repr(func(1)))
print(repr(func(2)))
11 changes: 4 additions & 7 deletions tests/nestedclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ def __init__(self, var):

class B:
def foo(s):
print s
print self
print self.var
print(s)
print(self)
print(self.var)

self.B = B

a = A(666)
b = a.B()
b.foo()



b.foo()
10 changes: 2 additions & 8 deletions tests/printtrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ def main():
if __name__=="__main__":
try:
main()
except Exception, e:
except Exception as e:
traceback.print_exc(file=sys.stderr)

# raise e.__class__, e, sys.exc_traceback






# raise e.__class__, e, sys.exc_traceback
8 changes: 3 additions & 5 deletions tests/setattr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ def __setattr__(self, attrname, val):
object.__setattr__(self, attrname, val)
return

print "__setattr__(%s, %s)" % (`attrname`, `val`)
print("__setattr__(%s, %s)" % (repr(attrname), repr(val)))

a = A(111)
print a.a
print a.b


print(a.a)
print(a.b)
13 changes: 6 additions & 7 deletions tests/test__new__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ def __init__(self, b):
self.b = b

class A(object):
def __new__(self, a):
print "__new__(%s)" % `a`
return object.__new__(self, a)
# return super(A, self).__new__(self, a) ## equivalent
def __new__(cls, a):
print("__new__(%s)" % repr(a))
return object.__new__(cls)
# return super(A, cls).__new__(cls) ## equivalent

def __init__(self, a):
print "__init__(%s)" % `a`
self.a = a

print("__init__(%s)" % repr(a))
self.a = a
16 changes: 6 additions & 10 deletions tests/testpty.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@
if pid == 0:
os.close(slave)
while True:
print "child"
os.write(master, "ping")
print("child")
os.write(master, b"ping")
buf = os.read(master, 4)
if not buf:
break
print "master read: " + buf
print("master read: " + buf.decode())

sys.exit(0)

else:
os.close(master)
buf = os.read(slave, 4)
if buf:
print "slave read: " + buf
os.write(slave, "pong")
print("slave read: " + buf.decode())
os.write(slave, b"pong")
os.close(slave)
time.sleep(5)




time.sleep(5)