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

Default to utf-8 for csv opening. #5712

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions news/1399.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix unicode filename issues on Windows
5 changes: 3 additions & 2 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import compileall
import csv
import hashlib
import io
import logging
import os.path
import re
Expand Down Expand Up @@ -80,15 +81,15 @@ def rehash(path, blocksize=1 << 20):
return (digest, str(length)) # type: ignore


def open_for_csv(name, mode):
def open_for_csv(name, mode, encoding='utf8'):
Copy link
Member

Choose a reason for hiding this comment

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

encoding is not used... You really need to add a test for this.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! I had copied over the changes from my local copy of pip.
Would you have any guidance as to where/how to add a test for this case? The error occurs when installing wheels which have unicode module names.

Copy link
Member

Choose a reason for hiding this comment

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

Create a minimal project that triggers the bug, add its sources to tests/data/src/ and a resulting wheel to tests/data/packages/, then add a test similar to test_basic_install_from_wheel in tests/functional/test_install_wheel.py. Do that without your changes, run your new test with something like tox -- -k test_install_wheel_with_unicode_filenames, and make sure you can reproduce the failure, then fix the test by adding your changes. Check Python 2 still work, and push.

You also need to add a news entry: https://pip.pypa.io/en/stable/development/#adding-a-news-entry

Copy link
Member

Choose a reason for hiding this comment

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

And encoding is not a valid open keyword argument in Python 2.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the guidance! I will work on this and get back to you.

Copy link
Author

Choose a reason for hiding this comment

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

Hello,
I just made some changes for open and added a test. Will see how the pull request works now (I am not working from a Windows machine at the moment).
Could you help with the wheel test please? I could not figure out how to point a new wheel test to the new unicode_file example in the data folder.
Also, mypy seems to be failing but I am not sure why.

Thanks!

Copy link
Author

Choose a reason for hiding this comment

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

Hello,
Any help please?
Many thanks for your support!

# type: (str, Text) -> IO
Copy link
Member

Choose a reason for hiding this comment

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

# type: (str, Text, str)

if sys.version_info[0] < 3:
nl = {} # type: Dict[str, Any]
bin = 'b'
else:
nl = {'newline': ''} # type: Dict[str, Any]
bin = ''
return open(name, mode + bin, **nl)
return io.open(name, mode + bin, **nl)


def replace_python_tag(wheelname, new_tag):
Expand Down
8 changes: 8 additions & 0 deletions tests/data/src/unicode_files/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from setuptools import setup, find_packages

setup(
name="வணக்கம்",
packages=find_packages(),
version='0.0.1',
description="A sample unicode project",
)
Empty file.
Empty file.