Match class names and attributes for %config magic
(self, text:str)
| 1282 | return comp |
| 1283 | |
| 1284 | def magic_config_matches(self, text:str) -> List[str]: |
| 1285 | """ Match class names and attributes for %config magic """ |
| 1286 | texts = text.strip().split() |
| 1287 | |
| 1288 | if len(texts) > 0 and (texts[0] == 'config' or texts[0] == '%config'): |
| 1289 | # get all configuration classes |
| 1290 | classes = sorted(set([ c for c in self.shell.configurables |
| 1291 | if c.__class__.class_traits(config=True) |
| 1292 | ]), key=lambda x: x.__class__.__name__) |
| 1293 | classnames = [ c.__class__.__name__ for c in classes ] |
| 1294 | |
| 1295 | # return all classnames if config or %config is given |
| 1296 | if len(texts) == 1: |
| 1297 | return classnames |
| 1298 | |
| 1299 | # match classname |
| 1300 | classname_texts = texts[1].split('.') |
| 1301 | classname = classname_texts[0] |
| 1302 | classname_matches = [ c for c in classnames |
| 1303 | if c.startswith(classname) ] |
| 1304 | |
| 1305 | # return matched classes or the matched class with attributes |
| 1306 | if texts[1].find('.') < 0: |
| 1307 | return classname_matches |
| 1308 | elif len(classname_matches) == 1 and \ |
| 1309 | classname_matches[0] == classname: |
| 1310 | cls = classes[classnames.index(classname)].__class__ |
| 1311 | help = cls.class_get_help() |
| 1312 | # strip leading '--' from cl-args: |
| 1313 | help = re.sub(re.compile(r'^--', re.MULTILINE), '', help) |
| 1314 | return [ attr.split('=')[0] |
| 1315 | for attr in help.strip().splitlines() |
| 1316 | if attr.startswith(texts[1]) ] |
| 1317 | return [] |
| 1318 | |
| 1319 | def magic_color_matches(self, text:str) -> List[str] : |
| 1320 | """ Match color schemes for %colors magic""" |