Skip to content

Commit

Permalink
Fix NameSelector serialization (#704)
Browse files Browse the repository at this point in the history
* fix NameSelector inversion

* Always set `_config_pos_init`
  • Loading branch information
Helveg committed Apr 4, 2023
1 parent c7a8441 commit 79785f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions bsb/config/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __call__(meta_subject, *args, _parent=None, _key=None, **kwargs):
instance = meta_subject.__new__(
meta_subject, _parent=_parent, _key=_key, **kwargs
)
instance._config_pos_init = getattr(instance, "_config_pos_init", False)
# Call the end user's __init__ with the rewritten arguments, if one is defined
if has_own_init:
sig = inspect.signature(instance.__init__)
Expand Down
5 changes: 5 additions & 0 deletions bsb/morphologies/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def pick(self, morphology):
class NameSelector(MorphologySelector, classmap_entry="by_name"):
names = config.list(type=str, required=True)

def __inv__(self):
if self._config_pos_init:
return self.names[0]
return self.__tree__()

def _cache_patterns(self):
self._pnames = {n: n.replace("*", r".*").replace("|", "\\|") for n in self.names}
self._patterns = {n: re.compile(f"^{pat}$") for n, pat in self._pnames.items()}
Expand Down

0 comments on commit 79785f3

Please sign in to comment.