Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unpacking wheels that contain files with commas in their names #427

Merged
merged 16 commits into from Dec 22, 2021

Conversation

hoodmane
Copy link
Contributor

I am trying to move Pyodide over to using wheels to distribute packages pyodide/pyodide#2027. After building the wheel, we need to do some postprocessing so we use python -m wheel unpack wheel-name.whl, then rearrange the wheel as appropriate, then pack the wheel again. The PyPa wheel package does not correctly handle commas in file names.

In particular, python -m wheel unpack breaks on the statsmodels wheel because of the following files:

statsmodels/datasets/tests/raw.github.com,vincentarelbundock,Rdatasets,master,csv,car,Duncan.csv.zip
statsmodels/datasets/tests/raw.github.com,vincentarelbundock,Rdatasets,master,datasets.csv.zip
statsmodels/datasets/tests/raw.github.com,vincentarelbundock,Rdatasets,master,doc,car,rst,Duncan.rst.zip

This PR fixes the problem.

@pfmoore
Copy link
Member

pfmoore commented Dec 15, 2021

The correct fix here is probably to use the stdlib csv library - the RECORD file is defined as being csv format, so using the library is far better than hand-parsing the format.

@agronholm
Copy link
Contributor

Yes, I was just thinking the same.

@hoodmane
Copy link
Contributor Author

Okay, I will do that. This was just the smallest code change that fixes my problem. =)

@hoodmane
Copy link
Contributor Author

hoodmane commented Dec 15, 2021

Also, the code coverage report lists line 79 that I added to wheelfile.py as not covered. Did I not add the test correctly? It certainly breaks locally without my change and works with it.

@codecov
Copy link

codecov bot commented Dec 15, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@0acd203). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #427   +/-   ##
=======================================
  Coverage        ?   80.85%           
=======================================
  Files           ?       12           
  Lines           ?      982           
  Branches        ?        0           
=======================================
  Hits            ?      794           
  Misses          ?      188           
  Partials        ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0acd203...363ba2f. Read the comment docs.

Copy link
Contributor

@agronholm agronholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple nits.

src/wheel/util.py Outdated Show resolved Hide resolved
src/wheel/wheelfile.py Outdated Show resolved Hide resolved
@hoodmane
Copy link
Contributor Author

Thanks for the very prompt review!

@hoodmane
Copy link
Contributor Author

There's an odd set of test failures. Maybe there was a reason that you weren't using csv here?

hoodmane and others added 2 commits December 15, 2021 15:37
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
Copy link
Contributor

@agronholm agronholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more nits.

src/wheel/wheelfile.py Outdated Show resolved Hide resolved
src/wheel/wheelfile.py Outdated Show resolved Hide resolved
src/wheel/wheelfile.py Outdated Show resolved Hide resolved
src/wheel/wheelfile.py Outdated Show resolved Hide resolved
src/wheel/wheelfile.py Outdated Show resolved Hide resolved
@agronholm
Copy link
Contributor

Supremely annoying to have the test suite fail on Python 2.7. I really need to ditch that, but until I get the time, I have to deal with those test failures.

@agronholm
Copy link
Contributor

With that latest change, tests now pass on Python 2.7 but not on Windows. Investigating.

@pfmoore
Copy link
Member

pfmoore commented Dec 21, 2021

It's probably because record should be opened in binary mode. You don't want to wrap a text file object in a TextIOWrapper...

@agronholm
Copy link
Contributor

agronholm commented Dec 21, 2021

But it is being opened in binary mode. You can't open files from a ZipFile any other way.

@pfmoore
Copy link
Member

pfmoore commented Dec 22, 2021

Oops sorry. I was reading the code in GitHub and didn’t expand to get enough context. Apologies for the noise.

@pfmoore
Copy link
Member

pfmoore commented Dec 22, 2021

Are you assuming that the default encoding for TextIOWrapper is utf-8? That isn’t always true on Windows, so that might be the issue. (To be clear, this is just something I often see go wrong on windows, I’ve not had time to review the actual test failure. I’ll try to take a proper look later.)

@agronholm
Copy link
Contributor

Are you assuming that the default encoding for TextIOWrapper is utf-8? That isn’t always true on Windows, so that might be the issue. (To be clear, this is just something I often see go wrong on windows, I’ve not had time to review the actual test failure. I’ll try to take a proper look later.)

I suspected that when I saw the failures on Windows, but I haven't had a chance to test that assumption yet. I will look into it later today (unless OP resolves it first).

@agronholm agronholm merged commit 5846dac into pypa:main Dec 22, 2021
@agronholm
Copy link
Contributor

Yup, that was it. Thanks @hoodmane !

agronholm added a commit that referenced this pull request Dec 22, 2021
@hoodmane
Copy link
Contributor Author

Thanks @agronholm and @pfmoore!

@hoodmane hoodmane deleted the handle-files-with-commas branch December 23, 2021 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants