audreyfeldroy / audreyfeldroy/complexity
Encoding varies between systems
- Dominant language
- Python
- Stars
- 118
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
I'm using version 0.9.1 of *complexity* with Python 3. There is no encoding specified when parsing templates and writeing the result to a file. When no encoding is specified, Python 3 uses a default encoding which depends on the system.[¹][1] This might cause different results on different systems while using the same input. This is a problem because the build of a webseite should not depend on the system it is running on. Also note that *complexity* already specifies an encoding when using Python 2 in contrast to Python 3.
I noticed the problem as I tried to run my build on a system where ASCII is used as default encoding. I got the following error:
```
Traceback (most recent call last):
File "./install", line 27, in
main()
File "./install", line 22, in main
complexity("src/", "www/")
File "/***/site-packages/complexity/main.py", line 78, in complexity
generate_html(templates_dir, output_dir, context, unexpanded_templates)
File "/***/site-packages/complexity/generate.py", line 135, in generate_html
generate_html_file(template_filepath, output_dir, env, context, force_unexpanded)
File "/***/site-packages/complexity/generate.py", line 82, in generate_html_file
fh.write(rendered_html)
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 1432: ordinal not in range(128)
```
The behavior can be reproduced by setting an environemt variable as noted in the [here][2].
```
$ LC_ALL=C.ascii complexity src/
```
For example, the following template file cannot be encoded as ASCII and will result in the shown error:
```
“Quoted”
```
[1]: https://docs.python.org/3/library/functions.html#open
"Python 3 documentation of function open"
[2]: https://docs.python.org/3/library/locale.html#locale.getdefaultlocale
"Python 3 documentation of getdefaultlocale"
Contributor guide
Research direction
Start in complexity/generate.py at generate_html_file, then trace its callers in complexity/main.py. Reproduce the failure with LC_ALL=C.ascii complexity src/ and a template containing “Quoted”; done means template parsing and output writing use a consistent encoding across systems without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100