Skip to content

fix(output): standardize --output to work for all formats#1193

Open
shifa-khan wants to merge 1 commit into
python-wheel-build:mainfrom
shifa-khan:1177
Open

fix(output): standardize --output to work for all formats#1193
shifa-khan wants to merge 1 commit into
python-wheel-build:mainfrom
shifa-khan:1177

Conversation

@shifa-khan

@shifa-khan shifa-khan commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Wire -o into plain formats for list-versions (versions, requirements) and list-overrides (no --details), removing inconsistent warn-and-ignore behavior. Matches the find-updates reference implementation.

Closes: #1177

@shifa-khan shifa-khan requested a review from a team as a code owner June 9, 2026 22:22
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1018923b-ba2c-42f9-9d00-9c09f05a8027

📥 Commits

Reviewing files that changed from the base of the PR and between 65e3a3d and 085e5df.

📒 Files selected for processing (5)
  • src/fromager/clickext.py
  • src/fromager/commands/list_overrides.py
  • src/fromager/commands/package.py
  • tests/test_list_overrides.py
  • tests/test_list_versions.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/fromager/commands/package.py
  • tests/test_list_versions.py
  • tests/test_list_overrides.py
  • src/fromager/commands/list_overrides.py

📝 Walkthrough

Walkthrough

This PR standardizes --output file support across two CLI commands to resolve inconsistent behavior (#1177). list-overrides now writes plain package names to file when --output is provided (without --details), and list-versions now writes version pins to file for versions and requirements formats. Both commands previously ignored --output for plain formats with warnings. The export helpers (_export_table, _export_versions_plain) are enhanced to accept an optional output path and write to file or stdout accordingly. Tests verify file creation with expected content.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately captures the main change: standardizing --output to work across all formats in list-versions and list-overrides commands.
Description check ✅ Passed Description clearly relates to the changeset by mentioning wiring -o into plain formats for list-versions and list-overrides, removing warn-and-ignore behavior, and referencing the closed issue #1177.
Linked Issues check ✅ Passed Changes fully address issue #1177 requirements: --output now works for plain formats in list-versions (versions, requirements) and list-overrides (no --details), warnings removed, tests added, and implementation matches find-updates reference.
Out of Scope Changes check ✅ Passed All changes align with PR scope: core output-file implementations in clickext.py, command handlers in list_overrides.py and package.py, and tests for plain-format file output; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mergify mergify Bot added the ci label Jun 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/fromager/commands/list_overrides.py (1)

30-37: ⚡ Quick win

Add a .. versionchanged:: note for the new --output behavior.

This updates user-facing CLI semantics, but there’s no Sphinx version directive documenting the change in the command docs/docstring.

Suggested patch
 def list_overrides(
@@
 ) -> None:
-    """List all of the packages with overrides in the current configuration."""
+    """List all of the packages with overrides in the current configuration.
+
+    .. versionchanged:: X.Y.Z
+       ``--output`` now applies to plain output (without ``--details``) and writes
+       package names to the specified file.
+    """

As per coding guidelines, **/*.{rst,py}: Use Sphinx versionadded, versionremoved, versionchanged directives for user-facing changes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fromager/commands/list_overrides.py` around lines 30 - 37, The CLI gained
a new --output/ -o Click option but the command docstring/docs are missing a
Sphinx directive documenting this behavior change; update the command's
docstring or the Sphinx documentation for the list_overrides command to include
a ".. versionchanged::" entry describing the new --output behavior (mentioning
the option name and that output can be written to a file instead of stdout),
placing the directive near other CLI option documentation so readers see the
change; update the docstring in src/fromager/commands/list_overrides.py (the
function/class that defines the command and help text) accordingly.

Source: Coding guidelines

src/fromager/commands/package.py (1)

124-125: ⚡ Quick win

Document the list-versions --output contract change with .. versionchanged::.

The command’s user-facing behavior changed for versions/requirements, but there’s no Sphinx version directive capturing it.

Suggested patch
 def list_versions(
@@
 ) -> None:
     """List all available versions for a package requirement specifier.
@@
     Use --ignore-per-package-overrides to see what the global cooldown
     policy would block without per-package exemptions.
+
+    .. versionchanged:: X.Y.Z
+       ``--output`` now applies to plain ``versions`` and ``requirements`` formats.
     """

As per coding guidelines, **/*.{rst,py}: Use Sphinx versionadded, versionremoved, versionchanged directives for user-facing changes.

Also applies to: 233-237

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fromager/commands/package.py` around lines 124 - 125, The public behavior
of the list-versions/requirements CLI changed: the --output flag now writes to a
file instead of stdout but there is no Sphinx version directive documenting
this; add a ".. versionchanged:: <new-version>" entry in the user-facing docs
(the RST page(s) that document the list-versions and requirements commands)
describing that "list-versions --output" (and requirements --output) now writes
output to a file path instead of stdout and showing the new expected
usage/format; mirror the same note for the other instance referenced (the change
also applies to the block around lines 233-237) so both command docs get the
versionchanged directive and a brief example of the new behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_list_overrides.py`:
- Around line 234-237: The test's stdout leak assertions are incomplete: add an
assertion to check that "test-pkg" is not present in result.stdout alongside the
existing checks for "test-other-pkg" and "test-pkg-library" so that any
plain-output leak of "test-pkg" will fail; update the assertions around
result.stdout in tests/test_list_overrides.py to include assert "test-pkg" not
in result.stdout.

In `@tests/test_list_versions.py`:
- Around line 332-348: Update the two tests that write to an output file
(test_list_versions_output_file_versions_format and the similar test for pins
format) to also assert that the CLI produced no plain version/pin data on stdout
when --output/-o is used: after invoking via _invoke_list_versions (which
returns the click CliRunner Result), add an assertion like assert
result.output.strip() == "" (or result.stdout/strip depending on test helper) to
ensure stdout is empty; keep the existing file-content assertions unchanged.

---

Nitpick comments:
In `@src/fromager/commands/list_overrides.py`:
- Around line 30-37: The CLI gained a new --output/ -o Click option but the
command docstring/docs are missing a Sphinx directive documenting this behavior
change; update the command's docstring or the Sphinx documentation for the
list_overrides command to include a ".. versionchanged::" entry describing the
new --output behavior (mentioning the option name and that output can be written
to a file instead of stdout), placing the directive near other CLI option
documentation so readers see the change; update the docstring in
src/fromager/commands/list_overrides.py (the function/class that defines the
command and help text) accordingly.

In `@src/fromager/commands/package.py`:
- Around line 124-125: The public behavior of the list-versions/requirements CLI
changed: the --output flag now writes to a file instead of stdout but there is
no Sphinx version directive documenting this; add a ".. versionchanged::
<new-version>" entry in the user-facing docs (the RST page(s) that document the
list-versions and requirements commands) describing that "list-versions
--output" (and requirements --output) now writes output to a file path instead
of stdout and showing the new expected usage/format; mirror the same note for
the other instance referenced (the change also applies to the block around lines
233-237) so both command docs get the versionchanged directive and a brief
example of the new behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dd4a8c25-9993-439f-98d8-d7cab0f72e2c

📥 Commits

Reviewing files that changed from the base of the PR and between 49908e9 and 65e3a3d.

📒 Files selected for processing (4)
  • src/fromager/commands/list_overrides.py
  • src/fromager/commands/package.py
  • tests/test_list_overrides.py
  • tests/test_list_versions.py

Comment thread tests/test_list_overrides.py
Comment thread tests/test_list_versions.py
Comment thread src/fromager/commands/package.py Outdated
else:
print(row["version"])
fh: typing.TextIO
if output:

@dhellmann dhellmann Jun 11, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the pattern used here, which avoids duplicating the logic to produce the output. Some of the other changes duplicate logic that is simple today but that could change over time.

I recommend you go 1 step further and create a context manager function that takes as input the path or None value and manages the file handle for you. That would eliminate another source of duplication and allow you to do something like

with get_file_handle_or_console(output) as fh:
    # logic to produce the output and send it to fh

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.

@dhellmann Thanks for the feedback. Updated in latest version.

@shifa-khan shifa-khan self-assigned this Jun 12, 2026
Wire -o into plain formats for `list-versions` (versions, requirements)
and `list-overrides` (no --details), removing inconsistent warn-and-ignore behavior.

Add `output_file_or_stdout()` context manager to `clickext` to
deduplicate file-handle management across export functions.

Closes: python-wheel-build#1177

Signed-off-by: shifa-khan <shikhan@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize --output to work for all formats

2 participants