diff --git a/fedn/cli/config_cmd.py b/fedn/cli/config_cmd.py index 74634aed7..b10f05d81 100644 --- a/fedn/cli/config_cmd.py +++ b/fedn/cli/config_cmd.py @@ -12,7 +12,7 @@ "FEDN_TOKEN", "FEDN_AUTH_SCHEME", "FEDN_CONTROLLER_URL", - "FEDN_PACKAGE_PATH" + "FEDN_PACKAGE_DIR" ] diff --git a/fedn/cli/run_cmd.py b/fedn/cli/run_cmd.py index f9c93f57a..566e3f89f 100644 --- a/fedn/cli/run_cmd.py +++ b/fedn/cli/run_cmd.py @@ -1,16 +1,15 @@ import threading import uuid - +import os import click import yaml - from fedn.common.exceptions import InvalidClientConfig from fedn.common.log_config import logger from fedn.network.clients.client import Client from fedn.network.combiner.combiner import Combiner from .main import main -from .shared import CLIENT_DEFAULTS, COMBINER_DEFAULTS, CONTROLLER_DEFAULTS, get_client_package_path +from .shared import CLIENT_DEFAULTS, COMBINER_DEFAULTS, CONTROLLER_DEFAULTS, get_client_package_dir def get_statestore_config_from_file(init): @@ -118,7 +117,7 @@ def run_cmd(ctx): @click.option('-n', '--name', required=False, default="client" + str(uuid.uuid4())[:8]) @click.option('-i', '--client_id', required=False) @click.option('--local-package', is_flag=True, help='Enable local compute package') -@click.option('-pp', '--package-path', required=False, help='Path to local package') +@click.option('-pd', '--package-dir', required=False, help='Path to local package') @click.option('--force-ssl', is_flag=True, help='Force SSL/TLS for REST service') @click.option('-u', '--dry-run', required=False, default=False) @click.option('-s', '--secure', required=False, default=False) @@ -135,7 +134,7 @@ def run_cmd(ctx): @click.option('--reconnect-after-missed-heartbeat', required=False, default=30) @click.option('--verbosity', required=False, default='INFO', type=click.Choice(['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'], case_sensitive=False)) @click.pass_context -def client_cmd(ctx, discoverhost, discoverport, token, name, client_id, local_package, package_path, force_ssl, dry_run, secure, preshared_cert, +def client_cmd(ctx, discoverhost, discoverport, token, name, client_id, local_package, package_dir, force_ssl, dry_run, secure, preshared_cert, verify, preferred_combiner, validator, trainer, init, logfile, heartbeat_interval, reconnect_after_missed_heartbeat, verbosity): """ @@ -161,13 +160,20 @@ def client_cmd(ctx, discoverhost, discoverport, token, name, client_id, local_pa """ remote = False if local_package else True - package_path = get_client_package_path(package_path) + package_dir = get_client_package_dir(package_dir) + + working_dir = package_dir or f"{os.getcwd()}/client" + + if not remote and not os.path.exists(working_dir): + click.echo("fedn.yaml not found. Either set --package-dir or FEDN_PACKAGE_DIR.") + click.echo(f"If neither of these are set, the current working directory will be used. Package dir set to: {working_dir}") + exit(-1) config = {'discover_host': discoverhost, 'discover_port': discoverport, 'token': token, 'name': name, 'client_id': client_id, 'remote_compute_context': remote, 'force_ssl': force_ssl, 'dry_run': dry_run, 'secure': secure, 'preshared_cert': preshared_cert, 'verify': verify, 'preferred_combiner': preferred_combiner, 'validator': validator, 'trainer': trainer, 'init': init, 'logfile': logfile, 'heartbeat_interval': heartbeat_interval, - 'reconnect_after_missed_heartbeat': reconnect_after_missed_heartbeat, 'verbosity': verbosity, 'package_path': package_path} + 'reconnect_after_missed_heartbeat': reconnect_after_missed_heartbeat, 'verbosity': verbosity, 'package_dir': package_dir} if init: apply_config(config) diff --git a/fedn/cli/shared.py b/fedn/cli/shared.py index f4bbb5bd9..81364bf13 100644 --- a/fedn/cli/shared.py +++ b/fedn/cli/shared.py @@ -48,5 +48,5 @@ def get_token(token: str) -> str: return f"{scheme} {_token}" -def get_client_package_path(path: str) -> str: - return path or os.environ.get('FEDN_PACKAGE_PATH', None) +def get_client_package_dir(path: str) -> str: + return path or os.environ.get('FEDN_PACKAGE_DIR', None) diff --git a/fedn/fedn/network/clients/client.py b/fedn/fedn/network/clients/client.py index d80ceb4d3..896f071c1 100644 --- a/fedn/fedn/network/clients/client.py +++ b/fedn/fedn/network/clients/client.py @@ -346,15 +346,17 @@ def _initialize_dispatcher(self, config): except Exception as e: logger.error(f"Caught exception: {type(e).__name__}") else: - run_path: str + from_path: str = None + run_path: str = None - if "package_path" in config and config["package_path"]: - run_path = f"{config['package_path']}/client" + if "package_dir" in config and config["package_dir"]: + path = f"{config['package_dir']}" + run_path = f"{config['package_dir']}" + from_path = path else: run_path = os.path.join(os.getcwd(), 'client') - - self.dispatcher = pr.dispatcher(run_path) + self.dispatcher = pr.dispatcher(run_path, from_path=from_path) def get_model_from_combiner(self, id, timeout=20): """Fetch a model from the assigned combiner. diff --git a/fedn/fedn/network/clients/package.py b/fedn/fedn/network/clients/package.py index d56296de8..4d47bb4df 100644 --- a/fedn/fedn/network/clients/package.py +++ b/fedn/fedn/network/clients/package.py @@ -144,18 +144,20 @@ def unpack(self): logger.error("Error extracting files.") return False - def dispatcher(self, run_path): + def dispatcher(self, run_path: str, from_path: str = None): """ Dispatch the compute package :param run_path: path to dispatch the compute package :type run_path: str + :param from_path: path to the compute package + :type from_path: str :return: Dispatcher object :rtype: :class:`fedn.utils.dispatcher.Dispatcher` """ - from_path = os.path.join(os.getcwd(), 'client') + _from_path = from_path or os.path.join(os.getcwd(), 'client') # preserve_times=False ensures compatibility with Gramine LibOS - copy_tree(from_path, run_path, preserve_times=False) + copy_tree(_from_path, run_path, preserve_times=False) try: cfg = None