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

encoding in __boot__.py #105

Closed
ronaldoussoren opened this issue Mar 25, 2013 · 5 comments
Closed

encoding in __boot__.py #105

ronaldoussoren opened this issue Mar 25, 2013 · 5 comments
Labels
enhancement New feature or request

Comments

@ronaldoussoren
Copy link
Owner

Original report by Ivan Romanko (Bitbucket: ivanromanko, GitHub: ivanromanko).


There is "with open" in generated app/Contents/Resources/boot.py.
This open contains

#!python

with open(path, 'rU') as fp:
        source = fp.read() + "\n"

Is it possible to add explicit encoding there via option or permanent change?
I'm too stupid to make this change myself.

#!python

with open(path, 'rU', encoding('utf-8')) as fp:
        source = fp.read() + "\n"

I need this because of

#!python

Traceback (most recent call last):
  File "/Users/ivan/#del#/yadmin/dist/yadmin.app/Contents/Resources/__boot__.py", line 316, in <module>
    _run()
  File "/Users/ivan/#del#/yadmin/dist/yadmin.app/Contents/Resources/__boot__.py", line 310, in _run
    source = fp.read() + "\n"
  File "encodings/ascii.pyc", line 26, in decode
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 28: ordinal not in range(128)
@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


It is currently not possible to change the encoding. I'm not yet sure as to what is the best approach to fix this issue.

The easiest workaround if you are using python 3 (which you likely are given the error message) is to patch py2app/bootstrap/build_app.py in the py2app source or installation tree. Look for the open statement and add , encoding='UTF-8' after the last argument:

with open(path, 'rU', encoding='UTF-8') as fp:

The final solution will either try to determine the encoding (PEP 263 with the appropriate default encoding), or will just compile the script to a pyc file when building the app bundle (just like all other source files are compiled). The latter is more likely as compiling the source file is useful for other reasons as well (see #47)

@ronaldoussoren
Copy link
Owner Author

Original comment by Ivan Romanko (Bitbucket: ivanromanko, GitHub: ivanromanko).


Thanks a lot, Ronald!
You make great project!

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Reopened because I want to fix this properly in a future release, and keeping the issue open ensures that I won't forget about this problem.

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Allow encodings other than ASCII in the main script

This primarily affects Python 3.x because source files
are read as text files and this means the encoding needs
to be specified when it isn't ASCII.

There is some code duplication, but that cannot easily be
avoided.

Fixes #105

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


merge, fixes #105

@ronaldoussoren ronaldoussoren added minor enhancement New feature or request labels Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant