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

Fix UTF-8 encoding errors when running EasyBuild with Python 3.0.x-3.6.x #3565

Merged
merged 9 commits into from
Feb 18, 2021

Conversation

Flamefire
Copy link
Contributor

@Flamefire Flamefire commented Feb 4, 2021

When the system encoding is not UTF-8 Python 3 will try to decode files as ASCII which fails
This adds a test to CI with LC_ALL=C to enforce this situation and test cases reproducing failures in read_file, write_file and apply_regex_substitutions as seen in the wild

Example: easybuilders/easybuild-easyblocks#2279 the failing text is valid UTF-8 (likely)

It seems only Python 3 < 3.7 is affected because in 3.7 a "UTF-8" mode was introduced which opens files as UTF-8 by default: https://www.python.org/dev/peps/pep-0540/

Fixes easybuilders/easybuild-easyblocks#2279
fixed easybuilders/easybuild-easyblocks#2329

This change makes sure files are opened with utf-8 encoding in Python 3 (Python 2 doesn't really care). This applies to read_file/write_file and friends as well as the logger which also opens files and if no encoding is specified it will run into the same situation: It uses the default encoding which may be ASCII and then fail to log UTF-8 encoded strings. Example: Dumping an EC with an UTF-8 char in the description

@Flamefire Flamefire force-pushed the utf8_fileread branch 4 times, most recently from 4b4df70 to b8b12c8 Compare February 4, 2021 16:10
@Flamefire Flamefire changed the title Add tests reproducing failure in handling UTF-8 files Fix UTF-8 encoding errors on Python 3.0-3.6 Feb 4, 2021
@Flamefire Flamefire marked this pull request as ready for review February 4, 2021 16:41
@easybuilders easybuilders deleted a comment from boegelbot Feb 5, 2021
@boegel boegel added the bug fix label Feb 5, 2021
@boegel boegel added this to the 4.3.3 (next release) milestone Feb 5, 2021
.github/workflows/unit_tests.yml Outdated Show resolved Hide resolved
easybuild/base/fancylogger.py Show resolved Hide resolved
easybuild/base/optcomplete.py Outdated Show resolved Hide resolved
easybuild/scripts/fix_docs.py Outdated Show resolved Hide resolved
easybuild/scripts/mk_tmpl_easyblock_for.py Outdated Show resolved Hide resolved
easybuild/tools/configobj.py Outdated Show resolved Hide resolved
easybuild/tools/configobj.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
test/framework/utilities.py Outdated Show resolved Hide resolved
test/framework/filetools.py Show resolved Hide resolved
When the system encoding is not UTF-8 Python 3 will try to decode files
as ASCII which fails
This adds a test to CI with LC_ALL=C to enforce this situation and test
cases reproducing failures in read_file, write_file and apply_regex_substitutions as seen in the wild
.github/workflows/unit_tests.yml Show resolved Hide resolved
.github/workflows/unit_tests.yml Show resolved Hide resolved
easybuild/base/fancylogger.py Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Show resolved Hide resolved
easybuild/tools/filetools.py Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
test/framework/filetools.py Show resolved Hide resolved
test/framework/modulestool.py Outdated Show resolved Hide resolved
@boegel boegel changed the title Fix UTF-8 encoding errors on Python 3.0-3.6 Fix UTF-8 encoding errors when running EasyBuild with Python 3.0.x-3.6.x Feb 17, 2021
@boegel boegel merged commit 34bce45 into easybuilders:develop Feb 18, 2021
Comment on lines +1408 to +1410
cache_dir = os.path.dirname(cache_fp)
if not os.path.exists(cache_dir):
mkdir(cache_dir, parents=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FTR: write_file already does this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants