refactor: modularize dynamic module and port class creation logic - #180
Open
bhagathkrishnacdac wants to merge 1 commit into
Open
refactor: modularize dynamic module and port class creation logic#180bhagathkrishnacdac wants to merge 1 commit into
bhagathkrishnacdac wants to merge 1 commit into
Conversation
Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
gab-arrobo
requested changes
Aug 3, 2026
gab-arrobo
left a comment
Contributor
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.
Comment on lines
+782
to
+786
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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