Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support simple import notation #31

Closed
wd15 opened this issue Sep 19, 2014 · 3 comments
Closed

Support simple import notation #31

wd15 opened this issue Sep 19, 2014 · 3 comments

Comments

@wd15
Copy link
Contributor

wd15 commented Sep 19, 2014

For example instead of the followoing command, >>> from fipy.viewers.gistViewer.grid1DGistViewer import Grid1DGistViewer one would issue the following command, >>> from fipy import Grid1DGistViewer To do this requires placing the main fipy objects in the fipy __init__ Grid1DGistViewer = fipy.viewers.gistViewer.grid1DGistViewer.Grid1DGistViewer

Imported from trac ticket #32, created by wd15 on 03-10-2005 at 10:17, last modified: 03-17-2005 at 09:25

@guyer
Copy link
Member

guyer commented Sep 19, 2014

Logged In: YES user_id=121894 Rather than placing everything in the main fipy/__init__.py, which will be a fragile maintenance nightmare, I think we will want to treat each layer of __init__.py hierarchically. I think the key is to use the __all__ mechanism to define what classes are exported from each level.

Trac comment by jguyer on 03-10-2005 at 10:43

@guyer
Copy link
Member

guyer commented Sep 19, 2014

Logged In: YES user_id=121894 Actually, __all__ may not be the correct solution. I think that would require each level of __init__.py to actually import all of its subclasses, which is wasteful (and will break on things like viewers that the user hasn't installed). Probably we will need to define our own import command with __import__()

Trac comment by jguyer on 03-10-2005 at 10:57

@guyer
Copy link
Member

guyer commented Sep 19, 2014

Logged In: YES user_id=121894 Abbreviated syntax now supported by way of import hooks in fipy/ __init__.py (c.f. PEP 302 <http://www.python.org/peps/pep-0302.html>). Simple hierarchical search for file name consistent with class name. Can fail in the face of redundancies. Full import syntax is always supported.

Trac comment by jguyer on 03-17-2005 at 09:25

@wd15 wd15 closed this as completed Sep 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants