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

open with utf-8 support #231

Merged
merged 1 commit into from
Apr 28, 2016
Merged

open with utf-8 support #231

merged 1 commit into from
Apr 28, 2016

Conversation

acaire
Copy link
Contributor

@acaire acaire commented Apr 13, 2016

Without this fix, pex will raise pex.resolver.Untranslateable due to
non utf-8 characters in setup.py or init.py:

$ pex -r requirements.txt -c foobar -o foobar.pex
**** Failed to install pygments-markdown-lexer-0.1.0.dev39. stdout:

**** Failed to install pygments-markdown-lexer-0.1.0.dev39. stderr:
Traceback (most recent call last):
File "", line 7, in
File "/tmp/virtualenv/lib/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 158: ordinal not in range(128)

Traceback (most recent call last):
File "/tmp/virtualenv/bin/pex", line 11, in
sys.exit(main())
File "/tmp/virtualenv/lib/python3.4/site-packages/pex/bin/pex.py", line 509, in main
pex_builder = build_pex(reqs, options, resolver_options_builder)
File "/tmp/virtualenv/lib/python3.4/site-packages/pex/bin/pex.py", line 471, in build_pex
resolveds = resolver.resolve(resolvables)
File "/tmp/virtualenv/lib/python3.4/site-packages/pex/resolver.py", line 200, in resolve
dist = self.build(package, resolvable.options)
File "/tmp/virtualenv/lib/python3.4/site-packages/pex/resolver.py", line 257, in build
dist = super(CachingResolver, self).build(package, options)
File "/tmp/virtualenv/lib/python3.4/site-packages/pex/resolver.py", line 168, in build
raise Untranslateable('Package %s is not translateable by %s' % (package, translator))
pex.resolver.Untranslateable: Package SourcePackage('file:///root/.pex/build/pygments-markdown-lexer-0.1.0.dev39.zip') is not translateable by ChainedTranslator(WheelTranslator, EggTranslator, SourceTranslator)

@@ -32,12 +32,12 @@ def function_wrapper(self, *args, **kw):


class InstallerBase(object):
SETUP_BOOTSTRAP_HEADER = "import sys"
SETUP_BOOTSTRAP_HEADER = "import sys; from codecs import open"
Copy link
Contributor

@kwlzn kwlzn Apr 21, 2016

Choose a reason for hiding this comment

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

any reason to not just use io.open here instead? it should be in python 2.6 and up and also supports an encoding= kwarg - and is the default open in python3.

I think you could also avoid the semicolon by using the multiple import syntax at the module level:

...
SETUP_BOOTSTRAP_HEADER = "import io, sys"
...
exec(compile(io.open(..., encoding='utf-8')...
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just took this SO question as gospel in terms of speed improvements but admittedly didn't do any benchmarks - I'll push again with io.open

Without this fix, pex will raise pex.resolver.Untranslateable due to
non utf-8 characters in setup.py or \__init\__.py:

$ pex -r requirements.txt -c foobar -o foobar.pex
**** Failed to install pygments-markdown-lexer-0.1.0.dev39. stdout:

**** Failed to install pygments-markdown-lexer-0.1.0.dev39. stderr:
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "/tmp/virtualenv/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 158: ordinal not in range(128)

Traceback (most recent call last):
  File "/tmp/virtualenv/bin/pex", line 11, in <module>
    sys.exit(main())
  File "/tmp/virtualenv/lib/python3.4/site-packages/pex/bin/pex.py", line 509, in main
    pex_builder = build_pex(reqs, options, resolver_options_builder)
  File "/tmp/virtualenv/lib/python3.4/site-packages/pex/bin/pex.py", line 471, in build_pex
    resolveds = resolver.resolve(resolvables)
  File "/tmp/virtualenv/lib/python3.4/site-packages/pex/resolver.py", line 200, in resolve
    dist = self.build(package, resolvable.options)
  File "/tmp/virtualenv/lib/python3.4/site-packages/pex/resolver.py", line 257, in build
    dist = super(CachingResolver, self).build(package, options)
  File "/tmp/virtualenv/lib/python3.4/site-packages/pex/resolver.py", line 168, in build
    raise Untranslateable('Package %s is not translateable by %s' % (package, translator))
pex.resolver.Untranslateable: Package SourcePackage('file:///root/.pex/build/pygments-markdown-lexer-0.1.0.dev39.zip') is not translateable by ChainedTranslator(WheelTranslator, EggTranslator, SourceTranslator)
@acaire
Copy link
Contributor Author

acaire commented Apr 27, 2016

@kwlzn cheers for the feedback - Updated.

@kwlzn kwlzn merged commit 5aea7d0 into pex-tool:master Apr 28, 2016
@kwlzn
Copy link
Contributor

kwlzn commented Apr 28, 2016

@acaire merged - thanks for the PR!

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.

2 participants