Skip to content

Instantly share code, notes, and snippets.

@agoose77
Created August 19, 2015 11:30
Show Gist options
  • Save agoose77/14b6cb777d5f6ac5f574 to your computer and use it in GitHub Desktop.
Save agoose77/14b6cb777d5f6ac5f574 to your computer and use it in GitHub Desktop.
from __future__ import print_function
import sys
import os
current_directory = os.path.split(os.path.abspath(__file__))[0]
sys.path.append(current_directory + "/" + "..")
import hive
def get_last(n, a):
while True:
if not hasattr(n, a):
return n
n = getattr(n, a)
class C:
def __init__(self, name="<internal>"):
self.name = name
def print_name(self):
pass
def get_plug(self, o):
o()
def build_h(cls, i, ex, args):
print("Build hive", args.i)
is_root = args.root
if is_root:
ex.plug = hive.plugin(cls.print_name)
if args.i:
ex.h = SomeHive(args.i-1, False, name="<internal>")
else:
ex.sock = hive.socket(cls.get_plug)
if is_root:
hive.connect(ex.plug, get_last(ex, "h").sock)
def declare_h(args):
args.i = hive.parameter("int", 2)
args.root = hive.parameter("bool", True)
SomeHive = hive.hive("H1", build_h, cls=C, declarator=declare_h)
# This works
h1 = SomeHive()
# This doesn't
h2 = SomeHive()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment