Skip to content

Commit

Permalink
Merge pull request #1070 from kta-intel/kta-intel/fx_plan_initialize_…
Browse files Browse the repository at this point in the history
…pip_install_requirements

enable installation of requirements through `fx plan initialize`
  • Loading branch information
kta-intel authored Oct 4, 2024
2 parents d33d199 + 33125f6 commit f554e83
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions openfl/interface/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@


"""Plan module."""
import os
import sys
from logging import getLogger
from os import makedirs
from os.path import isfile
from pathlib import Path
from shutil import copyfile, rmtree
from subprocess import check_call # nosec

from click import Path as ClickPath
from click import echo, group, option, pass_context
Expand Down Expand Up @@ -85,6 +87,13 @@ def plan(context):
required=False,
help="GaNDLF Configuration File Path",
)
@option(
"-r",
"--install_reqs",
required=False,
help="Install packages listed under 'requirements.txt'. True/False [Default: True]",
default=True,
)
def initialize(
context,
plan_config,
Expand All @@ -93,6 +102,7 @@ def initialize(
aggregator_address,
input_shape,
gandlf_config,
install_reqs,
):
"""Initialize Data Science plan.
Expand All @@ -107,6 +117,7 @@ def initialize(
aggregator_address (str): The FQDN of the federation aggregator.
feature_shape (str): The input shape to the model.
gandlf_config (str): GaNDLF Configuration File Path.
install_reqs (bool): Whether to install packages listed under 'requirements.txt'.
"""

for p in [plan_config, cols_config, data_config]:
Expand All @@ -120,6 +131,31 @@ def initialize(
if gandlf_config is not None:
gandlf_config = Path(gandlf_config).absolute()

if install_reqs:
requirements_filename = "requirements.txt"
requirements_path = Path(requirements_filename).absolute()

if isfile(f"{str(requirements_path)}"):
check_call(
[
sys.executable,
"-m",
"pip",
"install",
"-r",
f"{str(requirements_path)}",
],
shell=False,
)
echo(f"Successfully installed packages from {requirements_path}.")

# Required to restart the process for newly installed packages to be recognized
args_restart = [arg for arg in sys.argv if not arg.startswith("--install_reqs")]
args_restart.append("--install_reqs=False")
os.execv(args_restart[0], args_restart)
else:
echo("No additional requirements for workspace defined. Skipping...")

plan = Plan.parse(
plan_config_path=plan_config,
cols_config_path=cols_config,
Expand Down

0 comments on commit f554e83

Please sign in to comment.