diff --git a/setup.py b/setup.py index 9a9dd2b4..e41ee68d 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ """Packaging settings.""" + import os from codecs import open diff --git a/substra/sdk/backends/local/compute/spawner/subprocess.py b/substra/sdk/backends/local/compute/spawner/subprocess.py index 8bda7668..a474694d 100644 --- a/substra/sdk/backends/local/compute/spawner/subprocess.py +++ b/substra/sdk/backends/local/compute/spawner/subprocess.py @@ -92,26 +92,25 @@ def spawn( envs, ): """Spawn a python process (blocking).""" - with tempfile.TemporaryDirectory(dir=self._local_worker_dir) as function_dir, tempfile.TemporaryDirectory( - dir=function_dir - ) as args_dir: - function_dir = pathlib.Path(function_dir) - args_dir = pathlib.Path(args_dir) - uncompress(archive_path, function_dir) - script_name, function_name = _get_entrypoint_from_dockerfile(function_dir) - - args_file = args_dir / "arguments.txt" - - py_command = [sys.executable, str(function_dir / script_name), f"@{args_file}"] - py_command_args = _get_command_args(function_name, command_args_tpl, local_volumes) - write_command_args_file(args_file, py_command_args) - - if data_sample_paths is not None and len(data_sample_paths) > 0: - _symlink_data_samples(data_sample_paths, local_volumes[VOLUME_INPUTS]) - - # Catching error and raising to be ISO to the docker local backend - # Don't capture the output to be able to use pdb - try: - subprocess.run(py_command, capture_output=False, check=True, cwd=function_dir, env=envs) - except subprocess.CalledProcessError as e: - raise ExecutionError(e) + with tempfile.TemporaryDirectory(dir=self._local_worker_dir) as function_dir: + with tempfile.TemporaryDirectory(dir=function_dir) as args_dir: + function_dir = pathlib.Path(function_dir) + args_dir = pathlib.Path(args_dir) + uncompress(archive_path, function_dir) + script_name, function_name = _get_entrypoint_from_dockerfile(function_dir) + + args_file = args_dir / "arguments.txt" + + py_command = [sys.executable, str(function_dir / script_name), f"@{args_file}"] + py_command_args = _get_command_args(function_name, command_args_tpl, local_volumes) + write_command_args_file(args_file, py_command_args) + + if data_sample_paths is not None and len(data_sample_paths) > 0: + _symlink_data_samples(data_sample_paths, local_volumes[VOLUME_INPUTS]) + + # Catching error and raising to be ISO to the docker local backend + # Don't capture the output to be able to use pdb + try: + subprocess.run(py_command, capture_output=False, check=True, cwd=function_dir, env=envs) + except subprocess.CalledProcessError as e: + raise ExecutionError(e) diff --git a/tests/data_factory.py b/tests/data_factory.py index 32bdd767..9f72594a 100644 --- a/tests/data_factory.py +++ b/tests/data_factory.py @@ -400,11 +400,17 @@ def create_function( ( BAD_ENTRYPOINT_DOCKERFILE if dockerfile_type == "BAD_ENTRYPOINT" - else NO_ENTRYPOINT_DOCKERFILE - if dockerfile_type == "NO_ENTRYPOINT" - else NO_FUNCTION_NAME_DOCKERFILE - if dockerfile_type == "NO_FUNCTION_NAME" - else DEFAULT_FUNCTION_DOCKERFILE.format(function_name=DEFAULT_FUNCTION_FUNCTION_NAME[category]) + else ( + NO_ENTRYPOINT_DOCKERFILE + if dockerfile_type == "NO_ENTRYPOINT" + else ( + NO_FUNCTION_NAME_DOCKERFILE + if dockerfile_type == "NO_FUNCTION_NAME" + else DEFAULT_FUNCTION_DOCKERFILE.format( + function_name=DEFAULT_FUNCTION_FUNCTION_NAME[category] + ) + ) + ) ), ), )