Skip to content

Commit

Permalink
Merge branch 'main' into add-superexec-proto
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbvll committed Jun 13, 2024
2 parents 26e78ba + c16cd75 commit 8dcbc00
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/py/flwr/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def build(
Optional[Path],
typer.Option(help="The Flower project directory to bundle into a FAB"),
] = None,
) -> None:
) -> str:
"""Build a Flower project into a Flower App Bundle (FAB).
You can run `flwr build` without any argument to bundle the current directory:
Expand Down Expand Up @@ -125,6 +125,8 @@ def build(
f"🎊 Successfully built {fab_filename}.", fg=typer.colors.GREEN, bold=True
)

return fab_filename


def _load_gitignore(directory: Path) -> pathspec.PathSpec:
"""Load and parse .gitignore file, returning a pathspec."""
Expand Down
28 changes: 13 additions & 15 deletions src/py/flwr/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Flower command line interface `install` command."""


import os
import shutil
import tempfile
import zipfile
Expand All @@ -26,6 +25,8 @@
import typer
from typing_extensions import Annotated

from flwr.common.config import get_flwr_dir

from .config_utils import load_and_validate
from .utils import get_sha256_hash

Expand Down Expand Up @@ -84,7 +85,7 @@ def install_from_fab(
fab_file: Union[Path, bytes],
flwr_dir: Optional[Path],
skip_prompt: bool = False,
) -> None:
) -> Path:
"""Install from a FAB file after extracting and validating."""
fab_file_archive: Union[Path, IO[bytes]]
fab_name: Optional[str]
Expand Down Expand Up @@ -124,15 +125,19 @@ def install_from_fab(

shutil.rmtree(info_dir)

validate_and_install(tmpdir_path, fab_name, flwr_dir, skip_prompt)
installed_path = validate_and_install(
tmpdir_path, fab_name, flwr_dir, skip_prompt
)

return installed_path


def validate_and_install(
project_dir: Path,
fab_name: Optional[str],
flwr_dir: Optional[Path],
skip_prompt: bool = False,
) -> None:
) -> Path:
"""Validate TOML files and install the project to the desired directory."""
config, _, _ = load_and_validate(project_dir / "pyproject.toml", check_module=False)

Expand Down Expand Up @@ -161,16 +166,7 @@ def validate_and_install(
raise typer.Exit(code=1)

install_dir: Path = (
(
Path(
os.getenv(
"FLWR_HOME",
f"{os.getenv('XDG_DATA_HOME', os.getenv('HOME'))}/.flwr",
)
)
if not flwr_dir
else flwr_dir
)
(get_flwr_dir() if not flwr_dir else flwr_dir)
/ "apps"
/ publisher
/ project_name
Expand All @@ -185,7 +181,7 @@ def validate_and_install(
bold=True,
)
):
return
return install_dir

install_dir.mkdir(parents=True, exist_ok=True)

Expand All @@ -202,6 +198,8 @@ def validate_and_install(
bold=True,
)

return install_dir


def _verify_hashes(list_content: str, tmpdir: Path) -> bool:
"""Verify file hashes based on the LIST content."""
Expand Down
11 changes: 3 additions & 8 deletions src/py/flwr/client/supernode/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Flower SuperNode."""

import argparse
import os
import sys
from logging import DEBUG, INFO, WARN
from pathlib import Path
Expand All @@ -32,6 +31,7 @@
from flwr.cli.config_utils import validate_fields
from flwr.client.client_app import ClientApp, LoadClientAppError
from flwr.common import EventType, event
from flwr.common.config import get_flwr_dir
from flwr.common.exit_handlers import register_exit_handlers
from flwr.common.logger import log, warn_deprecated_feature
from flwr.common.object_ref import load_app, validate
Expand Down Expand Up @@ -170,12 +170,7 @@ def _get_load_client_app_fn(
flwr_dir = Path("")
if "flwr_dir" in args:
if args.flwr_dir is None:
flwr_dir = Path(
os.getenv(
"FLWR_HOME",
f"{os.getenv('XDG_DATA_HOME', os.getenv('HOME'))}/.flwr",
)
)
flwr_dir = get_flwr_dir()
else:
flwr_dir = Path(args.flwr_dir)

Expand Down Expand Up @@ -234,7 +229,7 @@ def _load(fab_id: str, fab_version: str) -> ClientApp:

# Load pyproject.toml file
toml_path = project_dir / "pyproject.toml"
if not os.path.isfile(toml_path):
if not toml_path.is_file():
raise LoadClientAppError(
f"Cannot find pyproject.toml in {project_dir}",
) from None
Expand Down
28 changes: 28 additions & 0 deletions src/py/flwr/common/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Provide functions for managing global Flower config."""

import os
from pathlib import Path


def get_flwr_dir() -> Path:
"""Return the Flower home directory based on env variables."""
return Path(
os.getenv(
"FLWR_HOME",
f"{os.getenv('XDG_DATA_HOME', os.getenv('HOME'))}/.flwr",
)
)

0 comments on commit 8dcbc00

Please sign in to comment.