wheel: Empty dirs change introduced is incompatible with distlib library

It looks like 0.33.2 change is incompatible with latest distlib package.

If I try to do distlib.wheel.install() it throws an error because folder ZipInfo object filename is not in the records: https://bitbucket.org/pypa/distlib/src/3b0fd333c8fb15bc04e570a23ee4836caefb7951/distlib/wheel.py#lines-521

I don’t see any details about Folders in PEP (https://www.python.org/dev/peps/pep-0427/), so not clear if this is something that should be addressed by wheel or distlib package.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 33 (30 by maintainers)

Commits related to this issue

Most upvoted comments

Easy way to reproduce: https://files.pythonhosted.org/packages/ff/1d/faec767bcb7b21156f6225d77da8cbf48dcb1f8e12dbc65663649073433a/azure_mgmt_iothub-0.8.0-py2.py3-none-any.whl

In [1]: import distlib.wheel

In [3]: w=distlib.wheel.Wheel("D:\\azure_mgmt_iothub-0.8.0-py2.py3-none-any.whl")

In [4]: w.verify()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-4-00bb035fd43f> in <module>()
----> 1 w.verify()

D:\VEnvs\testiot\Lib\site-packages\distlib\wheel.py in verify(self)
    795                 if u_arcname.endswith('/RECORD.jws'):
    796                     continue
--> 797                 row = records[u_arcname]
    798                 if row[2] and str(zinfo.file_size) != row[2]:
    799                     raise DistlibException('size mismatch for '

KeyError: 'azure/'

Python’s zipfile module does do this when building a zipfile from a directory tree:

But not when adding files individually, “by hand”. Honestly, though, the “why” of this isn’t important. The reality is that the wheel spec doesn’t require compatible wheels to include directory entries. It would be pretty simple to change the spec, at which point fixing the tools is non-controversial. Why waste energy debating what’s “right” when just proposing a spec change will likely go through with little or no problem?

I don’t think anybody is suggesting a format change for RECORD. But I’m beginning to think that maybe a PEP amendment is in order to address the issue of empty directories in a wheel, one way or another. In the meantime, how do you feel about my proposed fix? It would restore old behavior for 99.99% of projects.

Add a RECORD entry for those directories, but leave the hash empty

I’m -1 on changing the format of the RECORD.