File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -793,10 +793,26 @@ For example:
793793- `x.foo` is translated to `pygetattr(x, "foo")`
794794
795795Compound statements such as `begin`, `if`, `while` and `for` are supported.
796+ Import statements are supported, e.g.
797+ - `import foo, bar`
798+ - `from os.path import join as py_joinpath, exists`
796799
797800See the online documentation for more details.
798801"""
799802macro py (ex)
800803 esc (py_macro (ex, __module__, __source__))
801804end
805+
806+ macro py (keyword, modulename, ex)
807+ keyword == :from || return :( nothing )
808+
809+ d = Dict (isa (a. args[1 ], Symbol) ? a. args[1 ] => a. args[1 ] : a. args[1 ]. args[1 ] => a. args[2 ] for a in ex. args)
810+ vars = Expr (:tuple , values (d)... )
811+ imports = Tuple (keys (d))
812+
813+ esc (quote
814+ $ vars = pyimport ($ (string (modulename)) => $ (string .(imports)))
815+ end )
816+ end
817+
802818export @py
You can’t perform that action at this time.
0 commit comments