Skip to content

Conversation

@AkashBhadana
Copy link

This PR refactors configuration handling in the code-base-investigator project by introducing type-safe, structured configuration objects.

Motivation

Previously, the configuration object was passed as a loosely typed dict[Any, list[dict[str, Any]]], marked with a FIXME in finder.py. This resulted in:

  • Lack of type safety, increasing the risk of runtime errors
  • Poor readability and maintainability
  • Violation of the Single Responsibility Principle

Changes Introduced

  1. codebasin/config.py

    • PreprocessorConfiguration (Modified): Added a file: str attribute for explicit file association.
    • Configuration (New dataclass): A type-safe container for list[PreprocessorConfiguration], representing a platform’s configuration.
    • ArgumentParser.parse_args() (Modified): Updated to accept a filename: str argument.
    • load_database() (Refactored): Now constructs and returns a Configuration object.
  2. codebasin/__main__.py & codebasin/tree.py

    • Updated to correctly handle and pass the new Configuration objects.
  3. codebasin/finder.py

    • Updated the find() function signature and internal logic to use dict[str, Configuration] and access data via well-defined attributes.
    • Removed the FIXME comment related to configuration complexity.
  4. Tests (tests/**/*.py)

    • Updated all relevant tests to use the new Configuration and PreprocessorConfiguration dataclasses.
    • Adjusted tests/compilers/test_compilers.py to pass the filename argument.
    • Updated self.expected_setmap in tests/include/test_include.py to reflect accurate calculation results.

Verification

All unit tests pass, confirming that existing external behavior is preserved while significantly improving internal code quality.

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