[ADD]Add new global macros and helpers

This commit is contained in:
Fabien BOURGEOIS 2020-04-27 11:32:10 +02:00
parent 18b963d2cd
commit 305d17609f
2 changed files with 37 additions and 2 deletions

View File

@ -137,7 +137,7 @@
(field {"name" "model" "eval" (+ "'" model "'")} [])
(field {"name" "value" "eval" action})]))
; Odoo Backend macros
; Odoo ORM macros
(defmacro/g! compute-fn [field dependencies body]
"Macro to make computed definition smoother"
@ -154,8 +154,43 @@
(setv fn-name f"_compute_{(mangle fname)}")
`(setv ~fname (~@body :compute ~fn-name)))
; Backend macros
(defmacro __ [sentence] `((py "_") ~sentence))
(defmacro logger []
`(do
(import logging)
(setv _logger (.getLogger logging --name--))))
(defmacro pdb []
`(do
(import [pdb [set-trace]])
(set-trace)))
; Hy-related helpers
(defn modulehytopy [module-path hy-files]
"Transforms hy to py for translation purpose"
(import astor)
(import [os.path [dirname]]
[hy.lex [hy-parse]]
[hy.compiler [hy-compile]]
[hy.errors [filtered-hy-exceptions]])
(defn hytopy [source path]
"Hy source to Py source"
(setv hst (with [(filtered-hy-exceptions)] (hy-parse source :filename path))
-ast (with [(filtered-hy-exceptions)] (hy-compile hst "__main__" :filename path :source source)))
(.to-source (. astor code-gen) -ast))
(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))
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))))
; Migrations
(defn generate-fn-name [filepath]

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name="hy_odoo",
version="0.4.0",
version="0.5.0",
packages=find_packages(),
package_data={
'hy_odoo': ['*.hy'],