Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(framework) Remove pip install in flwr install and the wheel file #4571

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions src/py/flwr/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@
import shutil
import tempfile
import zipfile
from logging import DEBUG, ERROR
from pathlib import Path
from typing import Annotated, Any, Optional, Union

import pathspec
import tomli_w
import typer
from hatchling.builders.wheel import WheelBuilder
from hatchling.metadata.core import ProjectMetadata

from flwr.common.constant import FAB_ALLOWED_EXTENSIONS, FAB_DATE, FAB_HASH_TRUNCATION
from flwr.common.logger import log

from .config_utils import load_and_validate
from .utils import is_valid_project_name
Expand All @@ -55,27 +51,6 @@ def get_fab_filename(conf: dict[str, Any], fab_hash: str) -> str:
return f"{publisher}.{name}.{version}.{fab_hash_truncated}.fab"


def _build_app_wheel(app: Path) -> Path:
"""Build app as a wheel and return its path."""
# Path to your project directory
app_dir = str(app.resolve())
try:

# Initialize the WheelBuilder
builder = WheelBuilder(
app_dir, metadata=ProjectMetadata(root=app_dir, plugin_manager=None)
)

# Build
whl_path = Path(next(builder.build(directory=app_dir)))
log(DEBUG, "Wheel succesfully built: %s", str(whl_path))
except Exception as ex:
log(ERROR, "Exception encountered when building wheel.", exc_info=ex)
raise typer.Exit(code=1) from ex

return whl_path


# pylint: disable=too-many-locals, too-many-statements
def build(
app: Annotated[
Expand Down Expand Up @@ -131,12 +106,6 @@ def build(
bold=True,
)

# Build wheel
whl_path = _build_app_wheel(app)

# Add path to .whl to `[tool.flwr.app]`
conf["tool"]["flwr"]["app"]["whl"] = str(whl_path.name)

# Load .gitignore rules if present
ignore_spec = _load_gitignore(app)

Expand Down Expand Up @@ -168,9 +137,6 @@ def build(
and f.name != "pyproject.toml" # Exclude the original pyproject.toml
]

# Include FAB .whl
all_files.append(whl_path)

for file_path in all_files:
# Read the file content manually
with open(file_path, "rb") as f:
Expand All @@ -187,9 +153,6 @@ def build(
# Add CONTENT and CONTENT.jwt to the zip file
write_to_zip(fab_file, ".info/CONTENT", list_file_content)

# Erase FAB .whl in app directory
whl_path.unlink()

# Get hash of FAB file
content = Path(temp_filename).read_bytes()
fab_hash = hashlib.sha256(content).hexdigest()
Expand Down
20 changes: 1 addition & 19 deletions src/py/flwr/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import hashlib
import shutil
import subprocess
import tempfile
import zipfile
from io import BytesIO
Expand Down Expand Up @@ -188,25 +187,8 @@ def validate_and_install(
else:
shutil.copy2(item, install_dir / item.name)

whl_file = config["tool"]["flwr"]["app"]["whl"]
install_whl = install_dir / whl_file
try:
subprocess.run(
["pip", "install", "--no-deps", install_whl],
capture_output=True,
text=True,
check=True,
)
except subprocess.CalledProcessError as e:
typer.secho(
f"❌ Failed to install {project_name}:\n{e.stderr}",
fg=typer.colors.RED,
bold=True,
)
raise typer.Exit(code=1) from e

typer.secho(
f"🎊 Successfully installed {project_name}.",
f"🎊 Successfully installed {project_name} to {install_dir}.",
fg=typer.colors.GREEN,
bold=True,
)
Expand Down