MrMino / wheelfile

🔪🧀 API for creating and inspecting Python .whl files (wheels)
MIT License
29 stars 5 forks source link

Backporting support to python 3.6 #6

Closed e2thenegpii closed 3 years ago

e2thenegpii commented 3 years ago

At line 656 in wheelfile.py the following was causing heartache on python 3.6. Python 3.7 added the tell method on zipfile.ZipExtFile which is the actual type for buf as called from line 1371.

assert buf.tell() == 0, (
    f"Stale buffer given - current position: {buf.tell()}."
)

Additionally several tests use zipfile.Path which wasn't added until Python 3.8.

By adding a dependency on zipfile38 (which is a backport of zipfile from Python 3.8, if you couldn't guess :P ) all the zipfile dependencies just kind of resolve themselves. zipfile38 is not typed so I pulled the zipfile.pyi from typeshed and modified it so that it would always assume it was running on a Python 3.8 environment which is what zipfile38 provides. So both the mypy tests and pytests all pass

I ran the following to test on Python 3.6

docker run -it -v ~/wheelfile:/wheelfile python:3.6-buster /bin/bash
python -m pip install -r wheelfile/requirements-dev.txt
pytest wheelfile/
mypy wheelfile/

I've verified it works on Python 3.7 too using the same method.

MrMino commented 3 years ago

Thanks, will take a look on it tomorrow!