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

Todo: enum list of models #124

Open
caglorithm opened this issue Jan 19, 2021 · 2 comments
Open

Todo: enum list of models #124

caglorithm opened this issue Jan 19, 2021 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement Enhancing neurolib.

Comments

@caglorithm
Copy link
Member

There should be a way to list all available models. Similar to how TVB handles it would be nice: http://docs.thevirtualbrain.com/_modules/tvb/simulator/models.html

@caglorithm caglorithm self-assigned this Jan 19, 2021
@caglorithm caglorithm added documentation Improvements or additions to documentation enhancement Enhancing neurolib. labels Jan 19, 2021
@caglorithm
Copy link
Member Author

caglorithm commented Feb 18, 2021

Still don't know how to solve this in the best way. This is what I've been imagining:
Ideally, the user could do

import neurolib
print(neurolib.models)

and get a list of the model's module names (e.g., neurolib.models.aln), and the name and the description attribute of each model.

This gets the name of all submodules for example (in neurolib/__init__py). But then? Do I need to import them to get the attributes of each model class? Seems a bit overkill.

import pkgutil
import neurolib.models

package = neurolib.models

models = []
for _, modname, _ in pkgutil.walk_packages(
    path=package.__path__, prefix=package.__name__ + ".", onerror=lambda x: None
):
    if modname.split(".")[-1] == "model":
        models.append(modname)

image

Obviously the easiest way would be to hardcode a list. But that's not fun, innit?

@jajcayn
Copy link
Collaborator

jajcayn commented Feb 18, 2021

I think you actually need to import them in order to get the info stored in the class itself... so some packages define something like __all__ = [] as a list in some __init__ file which also then can work like "from neurolib.models import *" and it'll import only stuff that is inside __all__...
that can be also used to print out available models I guess?

however, print(neurolib.models) won't work I am afraid..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement Enhancing neurolib.
Projects
None yet
Development

No branches or pull requests

2 participants