Skip to content

Commit 74791f9

Browse files
authored
Use a decorator to register chares (#231)
1 parent 0aa892b commit 74791f9

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

charm4py/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
pass
2323

2424
if os.environ.get('CHARM_NOLOAD', '0') == '0':
25-
from .charm import charm, readonlies, Options
25+
from .charm import register, charm, readonlies, Options
2626
Reducer = charm.reducers
2727
Future = charm.createFuture
2828

charm4py/charm.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ def SECTION_ALL(obj):
4141
return 0
4242

4343

44+
def register(C):
45+
if ArrayMap in C.mro():
46+
charm.register(C, (GROUP,)) # register ArrayMap only as Group
47+
elif Chare in C.mro():
48+
charm.register(C)
49+
else:
50+
raise Charm4PyError("Class " + str(C) + " is not a Chare (can't register)")
51+
return C
52+
53+
4454
class Options(object):
4555

4656
def __str__(self):
@@ -477,6 +487,7 @@ def registerMainModule(self):
477487
self.registerInCharm(C)
478488

479489
def registerAs(self, C, charm_type_id):
490+
from .sections import SectionManager
480491
if charm_type_id == MAINCHARE:
481492
assert not self.mainchareRegistered, 'More than one entry point has been specified'
482493
self.mainchareRegistered = True

examples/multi-module/goodbye.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from charm4py import charm, Chare
1+
from charm4py import register, charm, Chare
22

33
# this will be set by Main chare
44
mainProxy = None
55

66

7+
@register
78
class Goodbye(Chare):
89

910
def SayGoodbye(self):

examples/multi-module/hello.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from charm4py import charm, Chare
1+
from charm4py import register, charm, Chare
22
import time
33

44
# this will be set by Main chare
55
bye_chares = None
66

77

8+
@register
89
class Hello(Chare):
910

1011
def SayHi(self):

examples/multi-module/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ def done(self):
2727
# Start a main chare of type Main. We specify to the charm runtime which
2828
# modules contain Chare definitions. Note that the __main__ module is always
2929
# searched for chare definitions, so we don't have to specify it
30-
charm.start(Main, modules=['hello', 'goodbye'])
30+
charm.start(Main)

0 commit comments

Comments
 (0)