non-ascii characters in python files and no encoding specified

Issue #592 resolved
Nico Schlömer created an issue

On a default Dolfin config/install, I'm getting

-- Generating form files in demo, test, bench and dolfin directories. May take some time...
-- ----------------------------------------------------------------------------------------
CMake Error at CMakeLists.txt:883 (message):
  Generation of form files failed:

  Traceback (most recent call last):

    File "/usr/local/bin/ffc", line 213, in <module>
      sys.exit(main(sys.argv[1:]))
    File "/usr/local/bin/ffc", line 170, in main
      ufd = load_ufl_file(filename)
    File "/usr/local/lib/python2.7/dist-packages/ufl/algorithms/formfiles.py", line 193, in load_ufl_file
      namespace = execute_ufl_code(uflcode, filename)
    File "/usr/local/lib/python2.7/dist-packages/ufl/algorithms/formfiles.py", line 97, in execute_ufl_code
      m = __import__(basename)
    File "/home/nschloe/software/fenics/dolfin/pristine/demo/undocumented/poisson-disc/cpp/PoissonDisc_debug.py", line 4

  SyntaxError: Non-ASCII character '\xc3' in file
  /home/nschloe/software/fenics/dolfin/pristine/demo/undocumented/poisson-disc/cpp/PoissonDisc_debug.py
  on line 4, but no encoding declared; see
  http://www.python.org/peps/pep-0263.html for details

I believe the culprit is @martinal's "æ" (\xc3\xa6) in the copyright notice. I suggest for @martinal to change his name or, alternatively, to add

# -*- coding: utf-8 -*-

to the beginning of each generated file (right below #!/usr/bin/env python, if it exists).

Comments (10)

  1. Martin Sandve Alnæs

    Sorry, didnt read this properly, only fixed in dolfin site-packages/. I'll add the fix you suggest to ufl.

  2. Nico Schlömer reporter

    The tentative fix is incorrect. The header has to be

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    

    i.e., the line # -*- coding: utf-8 -*- cannot appear any later. Can be checked by executing

    #!/usr/bin/env python
    import re
    # -*- coding: utf-8 -*-
    # Copyright (C) 2015-2015 Martin Sandve Alnæs
    print('123')
    
  3. Log in to comment