Skip to content

Move MetaWarning classes into new module #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 27, 2025
Merged

Conversation

Pennycook
Copy link
Contributor

@Pennycook Pennycook commented Dec 17, 2024

Related issues

Part of #36, #96.

The CLI is the least well-tested part of Code Base Investigator, because its legacy implementation lived outside of the codebasin/ package and was therefore difficult to test. Refactoring common CLI functionality into a dedicated module, using functions with well-defined interfaces, will make this functionality more reliable.

Proposed changes

  • Move Formatter, MetaWarning and WarningAggregator into a new module.
  • Add missing docstrings.
  • Add unit tests for Formatter, MetaWarning and WarningAggregator.

@Pennycook Pennycook added the refactor Improvements to code structure label Dec 17, 2024
@Pennycook Pennycook added this to the 2.0.0 milestone Dec 17, 2024
codebasin/cli.py Outdated
Copy link
Contributor

@laserkelvin laserkelvin Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's just me, but the naming of this module doesn't seem to really fit its contents?

It's called cli.py but it contains logging stuff, and if we're moving things around, would it make sense to name it something that maps better? (log_utils.py?)

Otherwise, refactors and new tests look good to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I can see the confusion. I'll explain my logic, and you can tell me if it makes sense 😆.

The thinking behind this "cli" module was that it would contain things that were only useful for the user-facing command-line interface, but which might be shared across commands (e.g., the Formatter is currently used by both codebasin and cbicov).

I was basically looking for a way to separate things that we use to build the user-facing CLI from the modules and interfaces that we (eventually) want people to be able to use when importing the codebasin package into another script.

Maybe it would be better to have this as something like a cli package, containing a logging.py? Or an _internal package containing a logging.py? I'm definitely open to suggestions here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After offline discussion, we're considering using _detail to align with the C++ idea of "implementation details".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed this module from "cli" to "_detail.logging" in 9108dce. Please let me know if it's not what you expected.

@Pennycook Pennycook changed the title Move MetaWarning classes into new cli module Move MetaWarning classes into new module Feb 27, 2025
Moving them out of __main__.py will make it easier to re-use them across
different command-line interfaces, and may make them easier to test.

While moving them, I also added the missing docstrings.

Signed-off-by: John Pennycook <[email protected]>
Signed-off-by: John Pennycook <[email protected]>
Signed-off-by: John Pennycook <[email protected]>
This renaming is effectively two changes, based on code review feedback:

- The module is moved into a separate _detail package, to highlight that
  its contents are an implementation detail and not part of CBI's public
  interface.

- The module is renamed from "cli" to "logging", since the three classes
  it defines (Formatter, MetaWarning, WarningAggregator) are all related
  to logging.

Signed-off-by: John Pennycook <[email protected]>
@Pennycook Pennycook merged commit c681012 into intel:main Feb 27, 2025
3 of 4 checks passed
@Pennycook Pennycook deleted the cli branch February 27, 2025 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Improvements to code structure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants