Skip to content

Commit

Permalink
chore:black
Browse files Browse the repository at this point in the history
Signed-off-by: ThibaultFy <thibault.fouqueray@gmail.com>
  • Loading branch information
ThibaultFy committed Feb 1, 2024
1 parent b641741 commit 238e116
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Packaging settings."""

import os
from codecs import open

Expand Down
45 changes: 22 additions & 23 deletions substra/sdk/backends/local/compute/spawner/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 11 additions & 5 deletions tests/data_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
)
)
),
),
)
Expand Down

0 comments on commit 238e116

Please sign in to comment.