Skip to content

Commit d7c25e8

Browse files
Remove implicit package installs (#1413)
* Remove implicit package installs Signed-off-by: Shah, Karan <[email protected]> * Update CI Signed-off-by: Shah, Karan <[email protected]> * Install pkg cmd for tests Signed-off-by: Shah, Karan <[email protected]> * Patch gandlf test Signed-off-by: Shah, Karan <[email protected]> --------- Signed-off-by: Shah, Karan <[email protected]>
1 parent 4d65ddc commit d7c25e8

File tree

8 files changed

+15
-87
lines changed

8 files changed

+15
-87
lines changed

.github/workflows/tr_docker_gramine_direct.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
run: |
3434
fx workspace create --prefix example_workspace --template keras/mnist
3535
cd example_workspace
36+
pip install -r requirements.txt
3637
fx plan initialize -a localhost
3738
3839
# Disable tensorboard logging as multiprocessing is not supported in Gramine

.github/workflows/tr_docker_native.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
run: |
3434
fx workspace create --prefix example_workspace --template keras/mnist
3535
cd example_workspace
36+
pip install -r requirements.txt
3637
fx plan initialize -a localhost
3738
fx workspace dockerize --base-image openfl --save
3839

docs/tutorials/taskrunner.ipynb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@
3131
{
3232
"cell_type": "code",
3333
"execution_count": null,
34-
"metadata": {
35-
"tags": [
36-
"hide-output"
37-
]
38-
},
34+
"metadata": {},
3935
"outputs": [],
4036
"source": [
4137
"!fx workspace create --prefix ./mnist_example --template keras/mnist\n",
42-
"%cd ./mnist_example"
38+
"%cd ./mnist_example\n",
39+
"!pip install -r requirements.txt > /dev/null"
4340
]
4441
},
4542
{
@@ -62,9 +59,6 @@
6259
"cell_type": "code",
6360
"execution_count": null,
6461
"metadata": {
65-
"tags": [
66-
"hide-output"
67-
],
6862
"vscode": {
6963
"languageId": "shellscript"
7064
}

openfl/interface/plan.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
"""Plan module."""
66

7-
import os
87
import sys
98
from logging import getLogger
109
from os import makedirs
1110
from os.path import isfile
1211
from pathlib import Path
1312
from shutil import copyfile, rmtree
14-
from subprocess import check_call # nosec
1513

1614
from click import Path as ClickPath
1715
from click import echo, group, option, pass_context
@@ -92,14 +90,6 @@ def plan(context):
9290
required=False,
9391
help="GaNDLF Configuration File Path",
9492
)
95-
@option(
96-
"-r",
97-
"--install_reqs",
98-
required=False,
99-
help="If set, installs packages listed under 'requirements.txt'.",
100-
default=True,
101-
show_default=True,
102-
)
10393
@option(
10494
"-i",
10595
"--init_model_path",
@@ -115,7 +105,6 @@ def initialize(
115105
aggregator_address,
116106
input_shape,
117107
gandlf_config,
118-
install_reqs,
119108
init_model_path,
120109
):
121110
"""
@@ -134,10 +123,6 @@ def initialize(
134123
if gandlf_config is not None:
135124
gandlf_config = Path(gandlf_config).absolute()
136125

137-
if install_reqs:
138-
requirements_path = Path("requirements.txt").absolute()
139-
_handle_requirements_install(requirements_path)
140-
141126
plan = Plan.parse(
142127
plan_config_path=plan_config,
143128
cols_config_path=cols_config,
@@ -205,37 +190,6 @@ def initialize(
205190
logger.info(f"{context.obj['plans']}")
206191

207192

208-
def _handle_requirements_install(requirements_path):
209-
"""Handle the installation of requirements and process restart if needed.
210-
211-
This method checks if a requirements.txt file exists at the provided path.
212-
If found, it installs the packages listed in the file using pip. After
213-
successful installation, it restarts the current process with the same
214-
arguments, but with the --install_reqs flag set to False to avoid
215-
re-installing requirements.
216-
217-
If no requirements.txt file is found, it prints a message indicating that
218-
no additional requirements are defined for the workspace and skips the
219-
installation.
220-
221-
Args:
222-
requirements_path (str or Path): The path to the requirements.txt file.
223-
"""
224-
if isfile(str(requirements_path)):
225-
check_call(
226-
[sys.executable, "-m", "pip", "install", "-r", str(requirements_path)],
227-
shell=False,
228-
)
229-
echo(f"Successfully installed packages from {requirements_path}.")
230-
231-
# Required to restart the process for newly installed packages to be recognized
232-
args_restart = [arg for arg in sys.argv if not arg.startswith("--install_reqs")]
233-
args_restart.append("--install_reqs=False")
234-
os.execv(args_restart[0], args_restart)
235-
else:
236-
echo("No additional requirements for workspace defined. Skipping...")
237-
238-
239193
def _initialize_tensor_dict(plan, input_shape, init_model_path):
240194
"""Initialize and return the tensor dictionary.
241195

openfl/interface/workspace.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import tempfile
1313
from hashlib import sha256
1414
from pathlib import Path
15-
from subprocess import check_call # nosec
16-
from sys import executable
1715
from typing import Union
1816

1917
from click import Choice, echo, group, option, pass_context
@@ -23,7 +21,7 @@
2321
from openfl.cryptography.ca import generate_root_cert, generate_signing_csr, sign_certificate
2422
from openfl.federated.plan import Plan
2523
from openfl.interface import plan
26-
from openfl.interface.cli_helper import CERT_DIR, OPENFL_USERDIR, SITEPACKS, WORKSPACE, print_tree
24+
from openfl.interface.cli_helper import CERT_DIR, SITEPACKS, WORKSPACE, print_tree
2725

2826

2927
@group()
@@ -129,40 +127,11 @@ def create(prefix, template):
129127
prefix: The prefix for the directories to be created.
130128
template: The template to use for creating the workspace.
131129
"""
132-
133-
if not OPENFL_USERDIR.exists():
134-
OPENFL_USERDIR.mkdir()
135-
136130
prefix = Path(prefix).absolute()
137131

138132
create_dirs(prefix)
139133
create_temp(prefix, template)
140134

141-
requirements_filename = "requirements.txt"
142-
143-
if os.path.isfile(f"{str(prefix)}/{requirements_filename}"):
144-
check_call(
145-
[
146-
executable,
147-
"-m",
148-
"pip",
149-
"install",
150-
"-r",
151-
f"{prefix}/requirements.txt",
152-
],
153-
shell=False,
154-
)
155-
echo(f"Successfully installed packages from {prefix}/requirements.txt.")
156-
else:
157-
echo("No additional requirements for workspace defined. Skipping...")
158-
prefix_hash = _get_dir_hash(str(prefix.absolute()))
159-
with open(
160-
OPENFL_USERDIR / f"requirements.{prefix_hash}.txt",
161-
"w",
162-
encoding="utf-8",
163-
) as f:
164-
check_call([executable, "-m", "pip", "freeze"], shell=False, stdout=f)
165-
166135
apply_template_plan(prefix, template)
167136

168137
print_tree(prefix, level=3)

tests/end_to_end/models/model_owner.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ def create_workspace(self):
6868
raise_exception=True
6969
)
7070

71+
return_code, output, error = fh.run_command(
72+
"pip install -r requirements.txt",
73+
workspace_path=ws_path,
74+
error_msg="Failed to install the requirements",
75+
container_id=self.container_id,
76+
)
77+
7178
except Exception as e:
7279
log.error(f"{error_msg}: {e}")
7380
raise e

tests/github/test_gandlf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def main():
4949
shutil.rmtree(fed_workspace, ignore_errors=True)
5050
check_call(['fx', 'workspace', 'create', '--prefix', fed_workspace, '--template', template])
5151
os.chdir(fed_workspace)
52+
check_call(['pip', 'install', '-r', 'requirements.txt'])
5253
Path(Path.cwd().resolve() / 'data' / col1).mkdir(exist_ok=True)
5354
with os.scandir(origin_dir) as iterator:
5455
for entry in iterator:

tests/github/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def create_certified_workspace(path, template, fqdn, rounds_to_train):
5050
shutil.rmtree(path, ignore_errors=True)
5151
check_call(['fx', 'workspace', 'create', '--prefix', path, '--template', template])
5252
os.chdir(path)
53+
check_call(['pip', 'install', '-r', 'requirements.txt'])
5354

5455
# Initialize FL plan
5556
check_call(['fx', 'plan', 'initialize', '-a', fqdn])

0 commit comments

Comments
 (0)