Skip to content

Commit 6bfb71b

Browse files
committed
Fixes to SocketpuppetConsumer for handling dotfiles
1. Update requirements_dev.txt to include base requirements, as these are necessary for starting the server and performing any tests. 2. Use Reflex.__subclasses__() rather than name checking for reflex subclass detection, which will be more consistent and allow users to name their reflexes whatever they want. 3. Clear falsey values from the filepaths detected in the load_reflexes_from_config function, which is a tenuous solution to not including vim-generated dotfiles in the module loading process. undo style changes
1 parent 182bb6e commit 6bfb71b

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-r requirements_test.txt
2+
-r requirements.txt
23

34
django-extensions
45
invoke

sockpuppet/consumer.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from django.conf import settings
1717

1818
from .channel import Channel
19-
from .reflex import PROTECTED_VARIABLES
19+
from .reflex import PROTECTED_VARIABLES, Reflex
2020
from .element import Element
2121
from .utils import classify
2222

@@ -109,34 +109,36 @@ def group_send(self, recipient, message):
109109
send(recipient, message)
110110

111111
def load_reflexes_from_config(self, config):
112-
def append_reflex(module):
113-
# TODO only import classes that are actually that inherits Reflex
114-
for classname in dir(module):
115-
if 'reflex' in classname.lower():
116-
ReflexClass = getattr(module, classname)
117-
self.reflexes[ReflexClass.__name__] = ReflexClass
112+
def append_reflex():
113+
self.reflexes.update(
114+
{
115+
ReflexClass.__name__: ReflexClass
116+
for ReflexClass in Reflex.__subclasses__()
117+
}
118+
)
118119

119120
modpath = config.module.__path__[0]
120121

121122
for dirpath, dirnames, filenames in walk(modpath):
122123
if dirpath == modpath and 'reflexes.py' in filenames:
123124
# classes in reflexes.py
124125
import_path = '{}.reflexes'.format(config.name)
125-
module = import_module(import_path)
126+
import_module(import_path)
127+
append_reflex()
126128

127-
append_reflex(module)
128129
elif dirpath == path.join(modpath, 'reflexes'):
129130
# assumes reflexes folder is placed directly in app.
130131
import_path = '{config_name}.reflexes.{reflex_file}'
131132

132133
for filename in filenames:
133-
name = filename.split('.')[0]
134+
# eliminates empty values in the filename before getting the
135+
# module name from the filename.
136+
name = [file for file in filename.split('.') if file][0]
134137
full_import_path = import_path.format(
135138
config_name=config.name, reflex_file=name
136139
)
137-
module = import_module(full_import_path)
138-
139-
append_reflex(module)
140+
import_module(full_import_path)
141+
append_reflex()
140142

141143
def reflex_message(self, data, **kwargs):
142144
logger.debug('Json: %s', data)

0 commit comments

Comments
 (0)