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

Eliminate package install during fx workspace import #1109

Merged
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
44 changes: 9 additions & 35 deletions openfl/interface/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import sys
import tempfile
from hashlib import sha256
from os import chdir
from os.path import basename, isfile
from pathlib import Path
from shutil import copyfile, copytree, ignore_patterns, unpack_archive
from subprocess import check_call # nosec
from sys import executable
from typing import Tuple, Union
Expand Down Expand Up @@ -71,7 +68,7 @@ def create_dirs(prefix):
(prefix / "save").mkdir(parents=True, exist_ok=True) # model weight saves / initialization
(prefix / "src").mkdir(parents=True, exist_ok=True) # model code

copyfile(WORKSPACE / "workspace" / ".workspace", prefix / ".workspace")
shutil.copyfile(WORKSPACE / "workspace" / ".workspace", prefix / ".workspace")


def create_temp(prefix, template):
Expand All @@ -84,11 +81,11 @@ def create_temp(prefix, template):

echo("Creating Workspace Templates")

copytree(
shutil.copytree(
src=WORKSPACE / template,
dst=prefix,
dirs_exist_ok=True,
ignore=ignore_patterns("__pycache__"),
ignore=shutil.ignore_patterns("__pycache__"),
) # from template workspace


Expand Down Expand Up @@ -140,7 +137,7 @@ def create(prefix, template):

requirements_filename = "requirements.txt"

if isfile(f"{str(prefix)}/{requirements_filename}"):
if os.path.isfile(f"{str(prefix)}/{requirements_filename}"):
check_call(
[
executable,
Expand Down Expand Up @@ -172,37 +169,14 @@ def create(prefix, template):
@option(
"--archive",
required=True,
help="Zip file containing workspace to import",
help="Path to workspace archive.",
type=ClickPath(exists=True),
)
def import_(archive):
"""Import federated learning workspace.
Args:
archive: The archive file containing the workspace to import.
"""

archive = Path(archive).absolute()

dir_path = basename(archive).split(".")[0]
unpack_archive(archive, extract_dir=dir_path)
chdir(dir_path)

requirements_filename = "requirements.txt"

if isfile(requirements_filename):
check_call(
[executable, "-m", "pip", "install", "--upgrade", "pip"],
shell=False,
)
check_call(
[executable, "-m", "pip", "install", "-r", "requirements.txt"],
shell=False,
)
else:
echo("No " + requirements_filename + " file found.")

echo(f"Workspace {archive} has been imported.")
"""Import a federated learning workspace generated by `fx workspace export`."""
dir_path = os.path.basename(os.path.abspath(archive)).split(".")[0]
shutil.unpack_archive(archive, extract_dir=dir_path)
echo(f"Imported workspace `{archive}`.")
echo("You may need to copy your PKI certificates to join the federation.")


Expand Down
Loading