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

Handling encodings correctly #900

Closed
wants to merge 28 commits into from
Closed

Handling encodings correctly #900

wants to merge 28 commits into from

Conversation

yan12125
Copy link

Fixes #457

On Travis CI pypy 2.5.0 and pypy3 2.4.0 failed. On my machine pypy 5.1 works fine:

$ pypy virtualenv.py 中文
New pypy executable in /home/yen/tmp/virtualenv/中文/bin/pypy
Installing setuptools, pip, wheel...done.

And pypy3 gives a strange error:

$ pypy3 virtualenv.py 中文
New pypy executable in /home/yen/tmp/virtualenv/中文/bin/pypy3
Also creating executable in /home/yen/tmp/virtualenv/中文/bin/pypy
debug: OperationError:
debug:  operror-type: LookupError
debug:  operror-value: no codec search functions registered: can't find encoding
debug: OperationError:
debug:  operror-type: AttributeError
debug:  operror-value: stdout
ERROR: The executable /home/yen/tmp/virtualenv/中文/bin/pypy3 is not functioning
ERROR: It thinks sys.prefix is '/home/yen/tmp/virtualenv' (should be '/home/yen/tmp/virtualenv/中文')
ERROR: virtualenv is not compatible with this system or executable

I guess it's related to a PyPy bug. Reported to https://bitbucket.org/pypy/pypy/issues/2300.


This was migrated from #875 to reparent it to the master branch. Please see original pull request for any previous discussion.

@yan12125
Copy link
Author

Now only PyPy 3 fails. Let's wait for responses from PyPy.

An question: is it OK to just skip the non-ASCII test on PyPy3 and list it as a known issue?

@yan12125
Copy link
Author

Skipped PyPy3. PyPy3 is incomplete and full of hacky codes. I don't think virtualenv should completely support it.

@Ivoz
Copy link

Ivoz commented May 28, 2016

I'm worried this will only happen to work on linuxes with the default locale set as UTF-8. E.g, not on Windows.

@yan12125
Copy link
Author

You're right. Appveyor tests failed. I'll try to install Python on Windows and have a look.

@yan12125
Copy link
Author

Windows support fixed.

@Ivoz
Copy link

Ivoz commented May 29, 2016

@yan12125 could you split out the part of this dealing specifically with pypy into a dependant / independent (whichever suits) PR?

@yan12125
Copy link
Author

Did you mean changes to .travis.yml?

@Ivoz
Copy link

Ivoz commented May 29, 2016

and external/pypy-subprocess.patch and tests/test_cmdline.py

@yan12125 yan12125 mentioned this pull request May 29, 2016
@yan12125
Copy link
Author

Done at #927

@Ivoz
Copy link

Ivoz commented May 29, 2016

So I'm guessing you'd want to cherry-pick 27c8056 and 23f7268 onto a new branch and force push it onto encoding-fix, or something to that effect, to clean up this PR

@Ivoz Ivoz added the encoding label May 29, 2016
@yan12125
Copy link
Author

Done :)

@Ivoz
Copy link

Ivoz commented May 29, 2016

Uhh, maybe I wasn't clear enough. I mean remove all changes that are effectively in #927 from this PR / branch.

- ', out).write(sys.prefix.encode("utf-8"))']): # 1.7.2 a9454bce
+ ', out).write(sys.prefix.encode("utf-8"))'], # 1.7.2 a9454bce
+ ['-c', 'import sys;out=sys.stdout;prefix=sys.prefix;'
+ 'prefix=prefix.encode("utf-8") if sys.version_info[0]==3 else prefix;'
Copy link
Member

Choose a reason for hiding this comment

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

Consider switching this to detect python 2 else do the python 3 behavior.

@yan12125
Copy link
Author

yan12125 commented Jun 7, 2016

@Ivoz @dholth Done. Sorry for the late response.

@yan12125
Copy link
Author

Is there anything left that should be fixed?

virtualenv.py Outdated
@@ -1472,7 +1478,7 @@ def install_files(home_dir, bin_dir, prompt, files):
content = content.replace('__VIRTUAL_ENV__', home_dir)
content = content.replace('__VIRTUAL_NAME__', vname)
content = content.replace('__BIN_NAME__', os.path.basename(bin_dir))
writefile(os.path.join(bin_dir, name), content)
writefile(os.path.join(bin_dir, name), content, use_fsenc=(name == 'activate.bat'))
Copy link
Member

Choose a reason for hiding this comment

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

Should also use fsenc for deactivate.bat surely?

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 that. Changed.

@pfmoore
Copy link
Member

pfmoore commented Jul 26, 2016

Tests are failing on pypy. This should be fixed.

Also, I've added a number of comments. The most significant issue is that you're using the wrong encoding for bat files on Windows, but there also seem to be some unneeded changes which concern me.

@yan12125
Copy link
Author

Fixes for PyPy is in #927. Originally I put all changes in this PR, and split out supporting changes to #927, as requested by @Ivoz in #900 (comment)

@yan12125
Copy link
Author

A minor update after 49721c1. Can anyone have a look into #946, the first step to the whole solution?

@yan12125
Copy link
Author

yan12125 commented Feb 7, 2017

@pfmoore in #1014 you said:

... which as noted in that PR, is stalled on being refactored out into separate PRs.

Is there something else I have to do other than splitting out pypy codes into #946?

@pfmoore
Copy link
Member

pfmoore commented Feb 7, 2017

Sorry, I can't see how to create a lint to an individual comment, but up above I said:

Agreed. There seem to be 3 things going on in this PR:
...
As @Ivoz suggests, we need multiple PRs here. Otherwise, this PR will simply sit here and never get applied, as no-one is in a position to understand and approve the whole thing. I realise this is more work for you - hopefully you can see why it would be helpful.

You split out the PyPy changes (which is waiting for someone to review and comment on, but I can't help there as I know nothing about PyPy). You still need (IMO) to split out the general encoding stuff and the Windows script file bits.

I'd happily review the Windows script file bits, I don't have an issue with that. For encodings, it's going to be more complex, as we lack a good test suite, but I'm willing to do what I can (with the proviso that I'd like to see tests demonstrating problem cases, not just reports that can't be reproduced elsewhere...)

@gaborbernat
Copy link
Contributor

@yan12125 can you rebase this and fix the CI? thanks!

Copy link
Contributor

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

@yan12125 can you rebase this and fix the CI? thanks!

@yan12125
Copy link
Author

It's my honor that someone is still looking at my PR. However, as this PR fixes a Python2-only issue, and Python 2 is going to be dead soon, I won't put more efforts into it. If another developer still needs it, feel free to take my branch.

@yan12125 yan12125 closed this Dec 17, 2018
@yan12125 yan12125 deleted the encoding-fix branch January 24, 2021 10:42
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.

Problem with non ASCII car in path
7 participants