audreyfeldroy / complexity

A refreshingly simple static site generator, for those who like to work in HTML.
Other
118 stars 32 forks source link

Encoding varies between systems #48

Open JojOatXGME opened 5 years ago

JojOatXGME commented 5 years ago

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.¹ 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 <module>
    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.

$ 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”
"Python 3 documentation of function open"
"Python 3 documentation of getdefaultlocale"