diff --git a/hy_odoo/odoo.hy b/hy_odoo/odoo.hy index fbcf0a6..714f023 100644 --- a/hy_odoo/odoo.hy +++ b/hy_odoo/odoo.hy @@ -17,6 +17,7 @@ " Odoo macros " +(require [hy-odoo.xml [if-python2]]) (import [os [path]]) (import [hy-odoo.xml [xmlroot xmln]]) @@ -174,6 +175,7 @@ "Transforms hy to py for translation purpose" (import astor) (import [os.path [dirname]] + [io [open :as iopen]] [hy.lex [hy-parse]] [hy.compiler [hy-compile]] [hy.errors [filtered-hy-exceptions]]) @@ -186,10 +188,15 @@ (for [hy-file hy-files] (setv hy-path (% "%s/%s.hy" (, (dirname module-path) hy-file)) - hy-source (with [o (open hy-path "r")] (.read o)) + hy-source (with [o (iopen hy-path "r" :encoding "utf-8")] (.read o)) output-path (.replace hy-path ".hy" ".py") - output-py (% "# %s\n%s" (, "Generate from Hy AST, for Babel translation purpose only. For real source code, please see and use HY source" (hytopy hy-source hy-path)))) - (with [f (open output-path "w")] (.write f output-py)))) + content ["# Generate from Hy AST, for Babel translation purpose only." + "# For real source code, please see and use HY source." + (hytopy hy-source hy-path)]) + (if-python2 + (.insert content 0 "# -*- coding: utf-8 -*-") (continue)) + (setv output-py (.join "\n" content)) + (with [f (iopen output-path "w")] (.write f output-py)))) ; Migrations diff --git a/setup.py b/setup.py index 0844254..0edbdc5 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="hy_odoo", - version="0.5.0", + version="0.5.1", packages=find_packages(), package_data={ 'hy_odoo': ['*.hy'],