Closed Hboni closed 4 years ago
During my search, I also found that between my BV python3 and BV python2, when I try
locale.getpreferredencoding()
, in python2 I getUTF-8
and in python3 I getANSI_X3.4-1968
. I was wondering if it is better to change the encoding in the code (as I did), or if we can change something in the distro to change the preferred encoding value?
The question is, what environment are you using to run your Python 3 version? You should check that the LANG
environment variable is set. We do it in base images of casa-distro containers, e.g.:
The question is, what environment are you using to run your Python 3 version? You should check that the LANG environment variable is set. We do it in base images of casa-distro containers, e.g.:
My python3 setup is in ubuntu18, and the LANG
is only C
, the link only show Dockerfile for Ubuntu16, but I don't see the same option in the Ubuntu18 Dockerfile.
If at all possible, it would be better to avoid an explicit check of the Python version, and use the same code under Python 2 and Python 3. I would suggest to try io.open, which is the open function of Python 3 backported to Python 2. io.open(filePath, 'r', encoding='utf-8') should work under both versions.
I agree to avoid python version check. io.open()
seems to work, I just need to refactor the generateDocumentation
process, to work in python2 (string/unicode problems)
I don't see the same option in the Ubuntu18 Dockerfile.
Indeed, it looks like I forgot Ubuntu 18.04 :-/ Fixing it now https://github.com/brainvisa/casa-distro/pull/97
Maybe this option fixes the initial issue, and so my modifications are not useful anymore, with this ubuntu18 casa-distro :stuck_out_tongue:
Maybe this option fixes the initial issue, and so my modifications are not useful anymore, with this ubuntu18 casa-distro stuck_out_tongue
Maybe. You can try it by just setting the LANG environment variable in your container (export LANG=C.UTF-8
). Still, it is good to have code that does not depend on a particular environment to run correctly :-)
I agree that we should not depend on the LANG variable, which is a user setting, whereas we require UTF-8 for internal needs of brainvisa. Using io.open()
seems OK for me.
Changing the LANG
to C.UTF-8
initially solve the problem.
I pushed some modifications to use io.open
and fixes documentation generation.
The process
generateDocumentation
in theTools
toolbox doesn't seem to work in python3 for me.The first error is :
To fix it, choosing 'utf-8' as
encoding
parameter when translation files are read fix it. Then another bug appears for nearly every file :As before, adding
encoding
parameter when open html file fixes it. To keep compatibility with python 2, I added a check of the python version to only use theencoding
parameter in python3.During my search, I also found that between my BV python3 and BV python2, when I try
locale.getpreferredencoding()
, in python2 I getUTF-8
and in python3 I getANSI_X3.4-1968
. I was wondering if it is better to change the encoding in the code (as I did), or if we can change something in the distro to change the preferred encoding value?