From 8adb2dbbbaa45cce24f81d5b9596fcdc24b001eb Mon Sep 17 00:00:00 2001 From: Charles Beauville Date: Tue, 16 Jul 2024 12:13:37 +0200 Subject: [PATCH 1/5] feat(framework) Install Python package on `flwr install` --- src/py/flwr/cli/install.py | 16 ++++++++++++++++ src/py/flwr/superexec/deployment.py | 9 +-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/py/flwr/cli/install.py b/src/py/flwr/cli/install.py index a1a66e42fd65..79156bb4d0c6 100644 --- a/src/py/flwr/cli/install.py +++ b/src/py/flwr/cli/install.py @@ -16,6 +16,7 @@ import shutil +import subprocess import tempfile import zipfile from io import BytesIO @@ -192,6 +193,21 @@ def validate_and_install( else: shutil.copy2(item, install_dir / item.name) + try: + subprocess.run( + ["pip", "install", "-e", install_dir, "--no-deps"], + capture_output=True, + text=True, + check=True, + ) + except subprocess.CalledProcessError as e: + typer.secho( + f"❌ Failed to install the package from {project_dir}:\n{e.stderr}", + fg=typer.colors.RED, + bold=True, + ) + raise typer.Exit(code=1) from e + typer.secho( f"🎊 Successfully installed {project_name} to {install_dir}.", fg=typer.colors.GREEN, diff --git a/src/py/flwr/superexec/deployment.py b/src/py/flwr/superexec/deployment.py index bbe7882692f0..f2180285a317 100644 --- a/src/py/flwr/superexec/deployment.py +++ b/src/py/flwr/superexec/deployment.py @@ -131,14 +131,7 @@ def start_run( try: # Install FAB to flwr dir fab_version, fab_id = get_fab_metadata(fab_file) - fab_path = install_from_fab(fab_file, None, True) - - # Install FAB Python package - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "--no-deps", str(fab_path)], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ) + install_from_fab(fab_file, None, True) # Call SuperLink to create run run_id: int = self._create_run(fab_id, fab_version, override_config) From 5c930127f764ca0e6c7e4244293b75c8e3f13e71 Mon Sep 17 00:00:00 2001 From: Charles Beauville Date: Tue, 16 Jul 2024 12:16:54 +0200 Subject: [PATCH 2/5] Remove unused import --- src/py/flwr/superexec/deployment.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/py/flwr/superexec/deployment.py b/src/py/flwr/superexec/deployment.py index f2180285a317..d012d408a9ff 100644 --- a/src/py/flwr/superexec/deployment.py +++ b/src/py/flwr/superexec/deployment.py @@ -15,7 +15,6 @@ """Deployment engine executor.""" import subprocess -import sys from logging import ERROR, INFO from pathlib import Path from typing import Dict, Optional From 49b0757023a10ab50a8b4beb9a7a878fca71cb1e Mon Sep 17 00:00:00 2001 From: Charles Beauville Date: Tue, 16 Jul 2024 12:55:20 +0200 Subject: [PATCH 3/5] Fix error message --- 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 79156bb4d0c6..322e04472085 100644 --- a/src/py/flwr/cli/install.py +++ b/src/py/flwr/cli/install.py @@ -202,7 +202,7 @@ def validate_and_install( ) except subprocess.CalledProcessError as e: typer.secho( - f"❌ Failed to install the package from {project_dir}:\n{e.stderr}", + f"❌ Failed to install the package from {install_dir}:\n{e.stderr}", fg=typer.colors.RED, bold=True, ) From 05e8b60fb10388d4911f79aaf5897ff1478f8d5d Mon Sep 17 00:00:00 2001 From: "Daniel J. Beutel" Date: Wed, 17 Jul 2024 11:32:33 +0200 Subject: [PATCH 4/5] Update src/py/flwr/cli/install.py --- 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 322e04472085..8c58eb5d7929 100644 --- a/src/py/flwr/cli/install.py +++ b/src/py/flwr/cli/install.py @@ -202,7 +202,7 @@ def validate_and_install( ) except subprocess.CalledProcessError as e: typer.secho( - f"❌ Failed to install the package from {install_dir}:\n{e.stderr}", + f"❌ Failed to `pip install` the package(s) from {install_dir}:\n{e.stderr}", fg=typer.colors.RED, bold=True, ) From 566ed8cb221bf75c5543de016975f56b7b11070c Mon Sep 17 00:00:00 2001 From: "Daniel J. Beutel" Date: Wed, 17 Jul 2024 11:33:08 +0200 Subject: [PATCH 5/5] Update src/py/flwr/cli/install.py --- 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 8c58eb5d7929..749a4516f65c 100644 --- a/src/py/flwr/cli/install.py +++ b/src/py/flwr/cli/install.py @@ -202,7 +202,7 @@ def validate_and_install( ) except subprocess.CalledProcessError as e: typer.secho( - f"❌ Failed to `pip install` the package(s) from {install_dir}:\n{e.stderr}", + f"❌ Failed to `pip install` package(s) from {install_dir}:\n{e.stderr}", fg=typer.colors.RED, bold=True, )