Skip to content

refactor: modularize protobuf module loader and add directory safety checks - #190

Open
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:bess-code-complexity-refactor
Open

refactor: modularize protobuf module loader and add directory safety checks#190
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:bess-code-complexity-refactor

Conversation

@bhagathkrishnacdac

Copy link
Copy Markdown

Description
This PR refactors _import_modules in the pybess module importer to resolve cognitive complexity, eliminate nested functions, and enforce better directory safety constraints.

Key Changes

  • Modularized Discovery Logic: Decomposed the nested dynamic importer logic into independent, single-responsibility functions:
    • _discover_protobuf_modules: Scans search paths for available protobuf definitions.
    • _get_modules_from_directory: Processes individual directory structures to find valid _msg_pb2 targets.
    • _keep_protobuf_name: Standardized filter to isolate CLI-bound argument, config, and response schemas.
    • _handle_collision_error: Formats and prints compilation namespace collisions before exit.
  • Directory Exist Check: Added os.path.isdir(dirpath) validation to _get_modules_from_directory to prevent unhandled OSError crashes if subdirectory structures (such as ports/) are absent in plugin folders.

…checks

Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
@bhagathkrishnacdac
bhagathkrishnacdac requested a review from a team August 2, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant