From 77ad285caec6a63a53704a9fdabd30eed23f22ef Mon Sep 17 00:00:00 2001 From: Heng Pan Date: Fri, 22 Nov 2024 14:23:43 +0000 Subject: [PATCH 1/3] remove pip install & whl file --- src/py/flwr/cli/build.py | 37 ------------------------------------- src/py/flwr/cli/install.py | 18 ------------------ 2 files changed, 55 deletions(-) diff --git a/src/py/flwr/cli/build.py b/src/py/flwr/cli/build.py index 5a8ac2d1fd9b..e86f4bb762b3 100644 --- a/src/py/flwr/cli/build.py +++ b/src/py/flwr/cli/build.py @@ -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 @@ -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[ @@ -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) @@ -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: @@ -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() diff --git a/src/py/flwr/cli/install.py b/src/py/flwr/cli/install.py index 00f97b7ed708..d4d49f09cc6c 100644 --- a/src/py/flwr/cli/install.py +++ b/src/py/flwr/cli/install.py @@ -16,7 +16,6 @@ import hashlib import shutil -import subprocess import tempfile import zipfile from io import BytesIO @@ -188,23 +187,6 @@ 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}.", fg=typer.colors.GREEN, From c45a3322dfb7d2a2bcf72f00fad170ac20d248d4 Mon Sep 17 00:00:00 2001 From: Heng Pan Date: Fri, 22 Nov 2024 15:50:06 +0000 Subject: [PATCH 2/3] Update src/py/flwr/cli/install.py Co-authored-by: Chong Shen Ng --- src/py/flwr/cli/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/py/flwr/cli/install.py b/src/py/flwr/cli/install.py index d4d49f09cc6c..c2dd7b1585fd 100644 --- a/src/py/flwr/cli/install.py +++ b/src/py/flwr/cli/install.py @@ -188,7 +188,7 @@ def validate_and_install( shutil.copy2(item, install_dir / item.name) typer.secho( - f"🎊 Successfully installed {project_name}.", + f"🎊 Successfully installed {project_name} to {install_dir}.", fg=typer.colors.GREEN, bold=True, ) From 3675f83446f401d6dc9b3156a9e29d3d251cb494 Mon Sep 17 00:00:00 2001 From: Heng Pan Date: Mon, 25 Nov 2024 10:31:04 +0000 Subject: [PATCH 3/3] remove hatchling dependency --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f8e3914d277c..f1207a94c448 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,7 +77,6 @@ typer = "^0.12.5" tomli = "^2.0.1" tomli-w = "^1.0.0" pathspec = "^0.12.1" -hatchling = "^1.25.0" rich = "^13.5.0" # Optional dependencies (Simulation Engine) ray = { version = "==2.10.0", optional = true, python = ">=3.9,<3.12" }