Skip to content

fix(framework): Fix flwr no args update check#6939

Draft
mohammadnaseri wants to merge 4 commits intomainfrom
fix-flwr-no-args-update-check
Draft

fix(framework): Fix flwr no args update check#6939
mohammadnaseri wants to merge 4 commits intomainfrom
fix-flwr-no-args-update-check

Conversation

@mohammadnaseri
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc14a54a30

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


@app.callback(invoke_without_command=True)
def main(
ctx: typer.Context,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep callback callable without injected Typer context

Adding a required ctx parameter breaks direct invocations of main outside Typer’s command runner, which now raises TypeError before the callback logic runs. In this repo, framework/py/flwr/cli/cli_test.py calls app_module.main(version=False) directly to verify update-check behavior, so this change introduces an immediate regression for those call paths unless ctx is made optional or those callers are updated.

Useful? React with 👍 / 👎.

@mohammadnaseri mohammadnaseri changed the title Edit fix(framework): Fix flwr no args update check Apr 2, 2026
Base automatically changed from update-check-before-argparse to main April 2, 2026 14:19
Copilot AI review requested due to automatic review settings April 2, 2026 14:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the flwr CLI startup behavior so that invoking flwr with no subcommand can still run the update-check logic while showing help output.

Changes:

  • Removed no_args_is_help from the Typer app configuration and added explicit “no args” help handling in the callback.
  • Updated the CLI callback signature to accept a Typer/Click context and used it to render help.
  • Adjusted CLI tests to construct a Click context and pass it into main().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
framework/py/flwr/cli/app.py Reworks no-args behavior by printing help in the callback (after update check) and exiting.
framework/py/flwr/cli/cli_test.py Updates tests to provide a Click context to the callback and imports the Click command object.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if ctx.invoked_subcommand is None and len(sys.argv) == 1:
typer.echo(ctx.get_help())
raise typer.Exit(code=2)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The new no-args handling prints help and then exits with code=2. Previously no_args_is_help=True would show help without treating it as a usage error; changing the exit code can be a breaking CLI behavior change for scripts. If the intent is still “show help on bare flwr”, consider exiting with code 0 (or otherwise matching the previous Click/Typer behavior).

Suggested change
raise typer.Exit(code=2)
raise typer.Exit()

Copilot uses AI. Check for mistakes.
typer.secho(f"Flower version: {package_version}", fg="blue")
raise typer.Exit()

if ctx.invoked_subcommand is None and len(sys.argv) == 1:
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The no-args detection uses len(sys.argv) == 1, which couples behavior to global process state and can be incorrect for programmatic invocations/tests where sys.argv doesn’t reflect the arguments passed to Typer. Prefer deriving this from the Click/Typer context (e.g., checking whether any args/subcommand were provided via the context) instead of sys.argv.

Suggested change
if ctx.invoked_subcommand is None and len(sys.argv) == 1:
if ctx.invoked_subcommand is None and not ctx.args and not ctx.params:

Copilot uses AI. Check for mistakes.
Comment on lines 127 to 145
def test_flwr_callback_checks_for_update(monkeypatch: pytest.MonkeyPatch) -> None:
"""The top-level flwr callback should perform the startup update check."""

class _SentinelError(Exception):
pass

captured: dict[str, str] = {}

def _raise_sentinel(process_name: str | None = None) -> None:
if process_name is not None:
captured["process_name"] = process_name
raise _SentinelError()

monkeypatch.setattr(app_module, "warn_if_flwr_update_available", _raise_sentinel)

with pytest.raises(_SentinelError):
app_module.main(version=False)
app_module.main(_make_context(), version=False)

assert captured == {"process_name": "flwr"}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

This PR is intended to fix the “no args” update-check path, but the tests currently exercise main() directly with the test runner’s sys.argv (which won’t be the bare flwr case). Add a test that invokes the CLI with no arguments (e.g., via CliRunner.invoke(app, [])) and asserts the update check is performed (and that help/exit code match the intended behavior).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4707f96baf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

typer.secho(f"Flower version: {package_version}", fg="blue")
raise typer.Exit()

if ctx.invoked_subcommand is None and len(sys.argv) == 1:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Detect no-arg invocations from Click context

Checking len(sys.argv) == 1 is not a reliable way to detect an empty flwr invocation when the CLI is called programmatically with explicit args (for example via Click/Typer test runners), because Click parses the provided arg list without updating process-wide sys.argv. In those calls, ctx.invoked_subcommand is None but this condition is false, so the callback skips the help/exit path and returns success with no output, which is a behavioral regression from the prior no_args_is_help=True behavior.

Useful? React with 👍 / 👎.

@github-actions github-actions bot added the Maintainer Used to determine what PRs (mainly) come from Flower maintainers. label Apr 2, 2026
@mohammadnaseri mohammadnaseri changed the title fix(framework): Fix flwr no args update check draft: fix(framework): Fix flwr no args update check Apr 2, 2026
@mohammadnaseri mohammadnaseri changed the title draft: fix(framework): Fix flwr no args update check fix(framework): Fix flwr no args update check Apr 2, 2026
@mohammadnaseri mohammadnaseri marked this pull request as draft April 2, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Maintainer Used to determine what PRs (mainly) come from Flower maintainers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants