Enaml - Relative imports of Python modules

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Enaml - Relative imports of Python modules

Jaidev Deshpande
Hi,

Suppose I have the file structure:

/enaml_relativeimports
        some_module.py
        __init__.py
        /enaml_views
                enamlview.enaml
                __init__.py
        
Both the __init__.py files are empty. I want to import a class from some_module.py into the enamlview.enaml file, like this:

from ..some_module import MyClass

This gives the following traceback:

Traceback (most recent call last):
  File "/home/jaidev/EPD/bin/enaml-run", line 9, in <module>
    load_entry_point('enaml==0.2.1', 'console_scripts', 'enaml-run')()
  File "/home/jaidev/enaml/enaml/runner.py", line 100, in main
    code = EnamlCompiler.compile(ast, enaml_file)
  File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 372, in compile
    compiler.visit(module_ast)
  File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
    method(node)
  File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 414, in visit_Module
    self.visit(item)
  File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
    method(node)
  File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 425, in visit_Python
    py_code = compile(node.py_ast, self.filename, mode='exec')
TypeError: ImportFrom field "names" must be a list, not a alias


What could I be doing wrong? 

(BTW, the inverse of this works, i.e. if there was a file in the root folder that wanted to import from some python module or an enaml widget from a subfolder, that happens properly.)

Thanks

--
JD

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Enaml - Relative imports of Python modules

Robert Kern
On Tue, Nov 20, 2012 at 8:34 PM, Jaidev Deshpande
<[hidden email]> wrote:

> Hi,
>
> Suppose I have the file structure:
>
> /enaml_relativeimports
>         some_module.py
>         __init__.py
>         /enaml_views
>                 enamlview.enaml
>                 __init__.py
>
> Both the __init__.py files are empty. I want to import a class from
> some_module.py into the enamlview.enaml file, like this:
>
> from ..some_module import MyClass
>
> This gives the following traceback:
>
> Traceback (most recent call last):
>   File "/home/jaidev/EPD/bin/enaml-run", line 9, in <module>
>     load_entry_point('enaml==0.2.1', 'console_scripts', 'enaml-run')()
>   File "/home/jaidev/enaml/enaml/runner.py", line 100, in main
>     code = EnamlCompiler.compile(ast, enaml_file)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 372, in
> compile
>     compiler.visit(module_ast)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 414, in
> visit_Module
>     self.visit(item)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 425, in
> visit_Python
>     py_code = compile(node.py_ast, self.filename, mode='exec')
> TypeError: ImportFrom field "names" must be a list, not a alias
>
>
> What could I be doing wrong?

Nothing. The Enaml parser seems to be broken for this syntax. Use an
absolute import for now.

--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Enaml - Relative imports of Python modules

Jaidev Deshpande
On Wed, Nov 21, 2012 at 2:09 AM, Robert Kern <[hidden email]> wrote:
On Tue, Nov 20, 2012 at 8:34 PM, Jaidev Deshpande
<[hidden email]> wrote:
> Hi,
>
> Suppose I have the file structure:
>
> /enaml_relativeimports
>         some_module.py
>         __init__.py
>         /enaml_views
>                 enamlview.enaml
>                 __init__.py
>
> Both the __init__.py files are empty. I want to import a class from
> some_module.py into the enamlview.enaml file, like this:
>
> from ..some_module import MyClass
>
> This gives the following traceback:
>
> Traceback (most recent call last):
>   File "/home/jaidev/EPD/bin/enaml-run", line 9, in <module>
>     load_entry_point('enaml==0.2.1', 'console_scripts', 'enaml-run')()
>   File "/home/jaidev/enaml/enaml/runner.py", line 100, in main
>     code = EnamlCompiler.compile(ast, enaml_file)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 372, in
> compile
>     compiler.visit(module_ast)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 414, in
> visit_Module
>     self.visit(item)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 425, in
> visit_Python
>     py_code = compile(node.py_ast, self.filename, mode='exec')
> TypeError: ImportFrom field "names" must be a list, not a alias
>
>
> What could I be doing wrong?

Nothing. The Enaml parser seems to be broken for this syntax. Use an
absolute import for now.


Okay, thanks.
 
--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



--
JD

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Enaml - Relative imports of Python modules

Chris Colbert


On Tue, Nov 20, 2012 at 3:47 PM, Jaidev Deshpande <[hidden email]> wrote:
On Wed, Nov 21, 2012 at 2:09 AM, Robert Kern <[hidden email]> wrote:
On Tue, Nov 20, 2012 at 8:34 PM, Jaidev Deshpande
<[hidden email]> wrote:
> Hi,
>
> Suppose I have the file structure:
>
> /enaml_relativeimports
>         some_module.py
>         __init__.py
>         /enaml_views
>                 enamlview.enaml
>                 __init__.py
>
> Both the __init__.py files are empty. I want to import a class from
> some_module.py into the enamlview.enaml file, like this:
>
> from ..some_module import MyClass
>
> This gives the following traceback:
>
> Traceback (most recent call last):
>   File "/home/jaidev/EPD/bin/enaml-run", line 9, in <module>
>     load_entry_point('enaml==0.2.1', 'console_scripts', 'enaml-run')()
>   File "/home/jaidev/enaml/enaml/runner.py", line 100, in main
>     code = EnamlCompiler.compile(ast, enaml_file)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 372, in
> compile
>     compiler.visit(module_ast)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 414, in
> visit_Module
>     self.visit(item)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 425, in
> visit_Python
>     py_code = compile(node.py_ast, self.filename, mode='exec')
> TypeError: ImportFrom field "names" must be a list, not a alias
>
>
> What could I be doing wrong?

Nothing. The Enaml parser seems to be broken for this syntax. Use an
absolute import for now.


Okay, thanks.
 
--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



--
JD

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Enaml - Relative imports of Python modules

Chris Colbert
Fixed: https://github.com/enthought/enaml/pull/208


On Thu, Nov 22, 2012 at 10:30 AM, Chris Colbert <[hidden email]> wrote:


On Tue, Nov 20, 2012 at 3:47 PM, Jaidev Deshpande <[hidden email]> wrote:
On Wed, Nov 21, 2012 at 2:09 AM, Robert Kern <[hidden email]> wrote:
On Tue, Nov 20, 2012 at 8:34 PM, Jaidev Deshpande
<[hidden email]> wrote:
> Hi,
>
> Suppose I have the file structure:
>
> /enaml_relativeimports
>         some_module.py
>         __init__.py
>         /enaml_views
>                 enamlview.enaml
>                 __init__.py
>
> Both the __init__.py files are empty. I want to import a class from
> some_module.py into the enamlview.enaml file, like this:
>
> from ..some_module import MyClass
>
> This gives the following traceback:
>
> Traceback (most recent call last):
>   File "/home/jaidev/EPD/bin/enaml-run", line 9, in <module>
>     load_entry_point('enaml==0.2.1', 'console_scripts', 'enaml-run')()
>   File "/home/jaidev/enaml/enaml/runner.py", line 100, in main
>     code = EnamlCompiler.compile(ast, enaml_file)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 372, in
> compile
>     compiler.visit(module_ast)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 414, in
> visit_Module
>     self.visit(item)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 425, in
> visit_Python
>     py_code = compile(node.py_ast, self.filename, mode='exec')
> TypeError: ImportFrom field "names" must be a list, not a alias
>
>
> What could I be doing wrong?

Nothing. The Enaml parser seems to be broken for this syntax. Use an
absolute import for now.


Okay, thanks.
 
--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



--
JD

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev




_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Enaml - Relative imports of Python modules

Jaidev Deshpande



On Thu, Nov 22, 2012 at 9:13 PM, Chris Colbert <[hidden email]> wrote:
Fixed: https://github.com/enthought/enaml/pull/208


Thanks!
 

On Thu, Nov 22, 2012 at 10:30 AM, Chris Colbert <[hidden email]> wrote:


On Tue, Nov 20, 2012 at 3:47 PM, Jaidev Deshpande <[hidden email]> wrote:
On Wed, Nov 21, 2012 at 2:09 AM, Robert Kern <[hidden email]> wrote:
On Tue, Nov 20, 2012 at 8:34 PM, Jaidev Deshpande
<[hidden email]> wrote:
> Hi,
>
> Suppose I have the file structure:
>
> /enaml_relativeimports
>         some_module.py
>         __init__.py
>         /enaml_views
>                 enamlview.enaml
>                 __init__.py
>
> Both the __init__.py files are empty. I want to import a class from
> some_module.py into the enamlview.enaml file, like this:
>
> from ..some_module import MyClass
>
> This gives the following traceback:
>
> Traceback (most recent call last):
>   File "/home/jaidev/EPD/bin/enaml-run", line 9, in <module>
>     load_entry_point('enaml==0.2.1', 'console_scripts', 'enaml-run')()
>   File "/home/jaidev/enaml/enaml/runner.py", line 100, in main
>     code = EnamlCompiler.compile(ast, enaml_file)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 372, in
> compile
>     compiler.visit(module_ast)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 414, in
> visit_Module
>     self.visit(item)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 83, in visit
>     method(node)
>   File "/home/jaidev/enaml/enaml/core/enaml_compiler.py", line 425, in
> visit_Python
>     py_code = compile(node.py_ast, self.filename, mode='exec')
> TypeError: ImportFrom field "names" must be a list, not a alias
>
>
> What could I be doing wrong?

Nothing. The Enaml parser seems to be broken for this syntax. Use an
absolute import for now.


Okay, thanks.
 
--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



--
JD

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev




_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev




--
JD

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev