xolox / python-deb-pkg-tools

Debian packaging tools
https://pypi.python.org/pypi/deb-pkg-tools
MIT License
42 stars 11 forks source link

Python 3.4 bugfix: avoid crashing #5

Closed mathieui closed 9 years ago

mathieui commented 9 years ago
  File "/home/build/soft/soft-venv/lib/python3.4/site-packages/deb_pkg_tools/checks.py", line 93, in check_duplicate_files
    fields, contents = inspect_package(archive.filename, cache=cache)
  File "/home/build/soft/soft-venv/lib/python3.4/site-packages/deb_pkg_tools/package.py", line 312, in inspect_package
    return (inspect_package_fields(archive, cache),
  File "/home/build/soft/soft-venv/lib/python3.4/site-packages/deb_pkg_tools/package.py", line 350, in inspect_package_fields
    return cache[archive].control_fields
  File "/home/build/soft/soft-venv/lib/python3.4/site-packages/cached_property.py", line 49, in __get__
    value = self.func(obj)
  File "/home/build/soft/soft-venv/lib/python3.4/site-packages/deb_pkg_tools/cache.py", line 313, in control_fields
    control_fields = inspect_package_fields(self.pathname)
  File "/home/build/soft/soft-venv/lib/python3.4/site-packages/cached_property.py", line 49, in __get__
    value = self.func(obj)
  File "/home/build/soft/soft-venv/lib/python3.4/site-packages/deb_pkg_tools/cache.py", line 289, in pathname
    return str(self['pathname']).decode(self.cache.character_encoding)
AttributeError: 'str' object has no attribute 'decode'

I haven't tested this on python 2 yet, though.

coveralls commented 9 years ago

Coverage Status

Coverage increased (+0.76%) to 94.65% when pulling 55692975d737acdc5109362c02889adac6dd9d85 on mathieui:master into 9d516b0962d2dfd3ac5f57624d8878bb8ad8474e on xolox:master.

xolox commented 9 years ago

Hi mathieui and thanks for the pull request! Funny enough I was working on this exact same issue when I saw the notification of your pull request :-).

As you can see from my most recent commit (9d516b0962d2dfd3ac5f57624d8878bb8ad8474e) I was struggling to understand the interaction between Python 2.x, Python 3.x, the SQLite module and UTF-8 encoding.

Travis CI says that your change fixes Python 3.4 support and retains Python 2.x support but I was experimenting with removing the str() call myself as well and in my local testing with Tox it fails on Python 2.6 and Python 2.7, as follows:

Traceback (most recent call last):
  File "/home/peter/projects/python/deb-pkg-tools/deb_pkg_tools/cli.py", line 146, in main
    cache.collect_garbage()
  File "/home/peter/projects/python/deb-pkg-tools/deb_pkg_tools/cache.py", line 178, in collect_garbage
    delete_cursor.execute('delete from package_cache where pathname = ?', (package.pathname,))
  File "/home/peter/projects/python/deb-pkg-tools/.tox/py26/lib/python2.6/site-packages/cached_property.py", line 49, in __get__
    value = self.func(obj)
  File "/home/peter/projects/python/deb-pkg-tools/deb_pkg_tools/cache.py", line 297, in pathname
    return self['pathname'].decode(self.cache.character_encoding)
AttributeError: 'buffer' object has no attribute 'decode'

Traceback (most recent call last):
  File "/home/peter/projects/python/deb-pkg-tools/deb_pkg_tools/cli.py", line 146, in main
    cache.collect_garbage()
  File "/home/peter/projects/python/deb-pkg-tools/deb_pkg_tools/cache.py", line 175, in collect_garbage
    delete_cursor.execute('delete from package_cache where pathname = ?', (package.pathname,))
  File "/home/peter/projects/python/deb-pkg-tools/.tox/py27/local/lib/python2.7/site-packages/cached_property.py", line 49, in __get__
    value = self.func(obj)
  File "/home/peter/projects/python/deb-pkg-tools/deb_pkg_tools/cache.py", line 289, in pathname
    return self['pathname'].decode(self.cache.character_encoding)
AttributeError: 'buffer' object has no attribute 'decode'

I've now merged your pull request but changed the implementation to use codecs.decode(). According to my Tox based testing this works on Python 2.6, Python 2.7, Python 3.4 and PyPy. Let's hope Travis CI agrees :-).

Thanks again for the contribution! I've released this change as deb-pkg-tools 1.29.4 on PyPI and GitHub.

xolox commented 9 years ago

Thanks again for the prod, Travis CI just confirmed that Python 3.4 compatibility has been restored. The build is green again :-).

mathieui commented 9 years ago

Thanks a lot, that was fast :)