Skip to content

Commit

Permalink
refactor(framework) Unify get_fab_metadata and `get_metadata_from_c…
Browse files Browse the repository at this point in the history
…onfig` (#4843)
  • Loading branch information
panh99 authored Jan 22, 2025
1 parent 8cbc216 commit 1c03c29
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
9 changes: 2 additions & 7 deletions src/py/flwr/cli/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import tomli
import typer

from flwr.common.config import get_fab_config, validate_config
from flwr.common.config import get_fab_config, get_metadata_from_config, validate_config


def get_fab_metadata(fab_file: Union[Path, bytes]) -> tuple[str, str]:
Expand All @@ -38,12 +38,7 @@ def get_fab_metadata(fab_file: Union[Path, bytes]) -> tuple[str, str]:
Tuple[str, str]
The `fab_id` and `fab_version` of the given Flower App Bundle.
"""
conf = get_fab_config(fab_file)

return (
f"{conf['tool']['flwr']['app']['publisher']}/{conf['project']['name']}",
conf["project"]["version"],
)
return get_metadata_from_config(get_fab_config(fab_file))


def load_and_validate(
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def validate_and_install(
)
raise typer.Exit(code=1)

version, fab_id = get_metadata_from_config(config)
fab_id, version = get_metadata_from_config(config)
publisher, project_name = fab_id.split("/")
config_metadata = (publisher, project_name, version, fab_hash)

Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/client/clientapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _load(fab_id: str, fab_version: str, fab_hash: str) -> ClientApp:
# `fab_hash` is not required since the app is loaded from `runtime_app_dir`.
elif app_path is not None:
config = get_project_config(runtime_app_dir)
this_fab_version, this_fab_id = get_metadata_from_config(config)
this_fab_id, this_fab_version = get_metadata_from_config(config)

if this_fab_version != fab_version or this_fab_id != fab_id:
raise LoadClientAppError(
Expand Down
4 changes: 2 additions & 2 deletions src/py/flwr/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ def parse_config_args(


def get_metadata_from_config(config: dict[str, Any]) -> tuple[str, str]:
"""Extract `fab_version` and `fab_id` from a project config."""
"""Extract `fab_id` and `fab_version` from a project config."""
return (
config["project"]["version"],
f"{config['tool']['flwr']['app']['publisher']}/{config['project']['name']}",
config["project"]["version"],
)


Expand Down

0 comments on commit 1c03c29

Please sign in to comment.