Drop any command whose name is also a namespace prefix of another. e.g. a command "io" cannot coexist with "io.connect": the wrapper for "io" would overwrite the namespace object. These are rare/accidental; skip them and warn rather than emit broken code.
(commands)
| 350 | |
| 351 | |
| 352 | def drop_namespace_collisions(commands): |
| 353 | """Drop any command whose name is also a namespace prefix of another. |
| 354 | |
| 355 | e.g. a command "io" cannot coexist with "io.connect": the wrapper for "io" |
| 356 | would overwrite the namespace object. These are rare/accidental; skip them |
| 357 | and warn rather than emit broken code. |
| 358 | """ |
| 359 | names = {c["name"] for c in commands} |
| 360 | prefixes = set() |
| 361 | for name in names: |
| 362 | parts = name.split(".") |
| 363 | for i in range(1, len(parts)): |
| 364 | prefixes.add(".".join(parts[:i])) |
| 365 | |
| 366 | kept, dropped = [], [] |
| 367 | for cmd in commands: |
| 368 | if cmd["name"] in prefixes: |
| 369 | dropped.append(cmd["name"]) |
| 370 | else: |
| 371 | kept.append(cmd) |
| 372 | |
| 373 | for name in dropped: |
| 374 | print( |
| 375 | "[sdk] skipping '%s' (name collides with a namespace)" % name, |
| 376 | file=sys.stderr, |
| 377 | ) |
| 378 | return kept |
| 379 | |
| 380 | |
| 381 | def collect_symbols(commands): |