Skip to content

Refactor language coverage module#1240

Open
kunalsz wants to merge 3 commits intomandiant:masterfrom
kunalsz:refactor-language-coverage
Open

Refactor language coverage module#1240
kunalsz wants to merge 3 commits intomandiant:masterfrom
kunalsz:refactor-language-coverage

Conversation

@kunalsz
Copy link
Copy Markdown
Contributor

@kunalsz kunalsz commented Mar 18, 2026

Resolves #1213

Introduces language/cli_common.py, deduplicating the argument parsing , logging setup, and PE validation logic into one file.
Makes it easier for setting up new languages

Signed-off-by: kunalsz <kunalavengers@gmail.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the language coverage modules by extracting and centralizing common CLI-related functionalities into a new shared module. This change aims to reduce code duplication across different language-specific tools, making the codebase more modular, easier to maintain, and more straightforward to extend when integrating new languages.

Highlights

  • New Common CLI Module: Introduced floss/language/cli_common.py to centralize common command-line interface (CLI) argument parsing, logging setup, and PE file validation logic.
  • Code Deduplication: Refactored floss/language/go/coverage.py and floss/language/rust/coverage.py to utilize the new common CLI utilities, removing redundant code.
  • Improved Maintainability: The refactoring simplifies the process of adding support for new languages by providing reusable components for common CLI operations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a good refactoring that deduplicates common CLI logic for language coverage scripts into floss/language/cli_common.py. This improves maintainability and makes it easier to add support for new languages. My feedback focuses on improving the new configure_logging function to correctly handle the --quiet flag, which was previously defined but not used, and making the logging setup more robust.

Comment thread floss/language/cli_common.py Outdated
Comment on lines +28 to +31
def configure_logging(debug):
level = logging.DEBUG if debug else logging.INFO
logging.basicConfig(level=level)
logging.getLogger().setLevel(level)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The configure_logging function doesn't handle the --quiet argument. It should set the logging level to CRITICAL when quiet is true to suppress all but fatal errors. Additionally, the call to logging.getLogger().setLevel(level) is redundant because logging.basicConfig() already configures the root logger's level. I've updated the function to handle this, removed the redundant call, and added type hints for clarity.

Suggested change
def configure_logging(debug):
level = logging.DEBUG if debug else logging.INFO
logging.basicConfig(level=level)
logging.getLogger().setLevel(level)
def configure_logging(debug: bool, quiet: bool):
level = logging.CRITICAL if quiet else (logging.DEBUG if debug else logging.INFO)
logging.basicConfig(level=level)

Comment thread floss/language/go/coverage.py Outdated
else:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)
configure_logging(debug=args.debug)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To correctly handle the --quiet command-line flag, you need to pass args.quiet to the updated configure_logging function.

Suggested change
configure_logging(debug=args.debug)
configure_logging(debug=args.debug, quiet=args.quiet)

Comment thread floss/language/rust/coverage.py Outdated
pe = pefile.PE(args.path)
except pefile.PEFormatError as err:
logger.debug(f"NOT a valid PE file: {err}")
configure_logging(debug=args.debug)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To correctly handle the --quiet command-line flag, you need to pass args.quiet to the updated configure_logging function.

Suggested change
configure_logging(debug=args.debug)
configure_logging(debug=args.debug, quiet=args.quiet)

@kunalsz
Copy link
Copy Markdown
Contributor Author

kunalsz commented Apr 9, 2026

Hi @mr-tz , if you are available can you review this 🙃

@williballenthin
Copy link
Copy Markdown
Collaborator

@kunalsz this code style is not consistent with the rest of the codebase. the code and message read like AI slop. please go back and demonstrate more effort working with the project or we'll close out this PR.

Signed-off-by: kunalsz <kunalavengers@gmail.com>
@kunalsz
Copy link
Copy Markdown
Contributor Author

kunalsz commented Apr 9, 2026

Hi @williballenthin, sorry if it came across that way. I made a few improvements, but the logger messages were taken directly from the original code before the refactor

Comment thread floss/language/cli_common.py Outdated
@@ -0,0 +1,58 @@
# Copyright 2023 Google LLC
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why does this say 2023?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used that from the other file, I'll update that to 2026

Comment thread floss/language/cli_common.py Outdated
logging.getLogger().setLevel(logging.INFO)


def open_pe_or_none(path: str):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i don't think this function is worth it. let's remove.

Signed-off-by: kunalsz <kunalavengers@gmail.com>
@kunalsz kunalsz requested a review from williballenthin April 14, 2026 13:32
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.

Refactor proposal: deduplicate language “coverage” CLI boilerplate (Go/Rust)

2 participants