refactor: modularize dynamic module and port class creation logic - #180
refactor: modularize dynamic module and port class creation logic#180bhagathkrishnacdac wants to merge 3 commits into
Conversation
Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
gab-arrobo
left a comment
There was a problem hiding this comment.
@bhagathkrishnacdac,
Thank you for your contribution. I see multiple "trailing whitespace" warning when trying to apply your patch locally. This seems to happen across the multiple contributions/PRs. Thank you!
pr.patch:70: trailing whitespace.
def _collect_module_and_driver_names(cli):
pr.patch:71: trailing whitespace.
"""Collect module class names and port driver names from BESS."""
pr.patch:72: trailing whitespace.
class_names = [str(i) for i in cli.bess.list_mclasses().names]
pr.patch:73: trailing whitespace.
driver_names = [str(i) for i in cli.bess.list_drivers().driver_names]
pr.patch:76: trailing whitespace.
def _find_duplicate_names(rsvd, class_names, driver_names):
warning: squelched 67 whitespace errors
warning: 72 lines add whitespace errors.
``
There was a problem hiding this comment.
Pull request overview
Refactors bessctl/commands.py to reduce cognitive complexity in _get_bess_module_and_port_creators by decomposing BESS RPC name collection, namespace-collision detection, and dynamic type construction into focused helper functions.
Changes:
- Extracted helper to collect module class names and port driver names from the BESS daemon.
- Isolated duplicate-name detection and formatting into dedicated helpers.
- Split dynamic
type()creator construction into separate module/port creator helpers.
Suppressed comments (1)
bessctl/commands.py:792
- The refactor removed the in-code rationale around why duplicate names are considered a BESS fault and what invariants the C++ layer already enforces. Keeping that context near the duplicate-detection logic will help future maintainers avoid weakening the constraints unintentionally.
"""Find duplicate names between reserved names, modules, and drivers."""
counts = collections.Counter(rsvd.keys())
counts.update(class_names)
counts.update(driver_names)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _collect_module_and_driver_names(cli): | ||
| """Collect module class names and port driver names from BESS.""" | ||
| class_names = [str(i) for i in cli.bess.list_mclasses().names] | ||
| driver_names = [str(i) for i in cli.bess.list_drivers().driver_names] | ||
| return class_names, driver_names |
|
@bhagathkrishnacdac, |
Description
This PR refactors _get_bess_module_and_port_creators to address cognitive complexity. The original monolithic function, which managed BESS RPC lookups, namespace collision checks, exception formatting, and dynamic Python type generation, has been decomposed into small, single-responsibility helper functions.
Key Changes