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

Include outside models and symbols #180

Open
shyamd opened this issue Jan 12, 2019 · 2 comments
Open

Include outside models and symbols #180

shyamd opened this issue Jan 12, 2019 · 2 comments

Comments

@shyamd
Copy link
Contributor

shyamd commented Jan 12, 2019

It would be nice to have a means of making my own module outside of propnet that kept its own models and symbols, but propnet when started up, etc. could find them.

One way to do this might be ot have an environment varibale like PROPNET_MODULES that could reference places for it to look, or go the fireworks method and allow for some of configuration file that does this.

Something that might help with this pattern would be to move the Model/Symbol registry into class-registry pattern:

import abc


class ClassRegistry(abc.ABCMeta):
    def __init__(cls, name, bases, nmspc):
        super(ClassRegistry, cls).__init__(name, bases, nmspc)
        cls._instances = dict()

    def __call__(cls, *args, **kwargs):

        # First get the name
        if "name" in kwargs:
            name = kwargs["id"]
        elif len(args) < 1:
            raise TypeError("Can't get a propnet object without a name")
        else:
            id = args[0]
            args = args[1:]

        # If there isn't already an instance with this name
        # Let's make a new Model object
        if name not in cls._instances:
            new_object = super(ClassRegistry, cls).__call__(*args, **kwargs)
            cls._instances[id] = new_object

        return cls._instances[id]

class Model(metaclass=ClassRegistry):
    ...
@mkhorton
Copy link
Collaborator

I think Python explicitly supports this via the concept of plugins, I think this is a good idea:

https://packaging.python.org/guides/creating-and-discovering-plugins/

@mkhorton
Copy link
Collaborator

(and regardless of plugins, I think using a registry pattern is a good suggestion, would be more graceful than the current hard-coded default folder)

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