Skip to content
Draft
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions streamflow/core/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,13 @@ def __init__(
workdir
or self.deployment.workdir
or (
os.path.join(os.path.realpath(tempfile.gettempdir()), "streamflow")
os.path.join(
os.path.realpath(tempfile.gettempdir()),
utils.get_local_username(),
"streamflow",
)
if deployment.type == "local"
else posixpath.join("/tmp", "streamflow") # nosec
else posixpath.join("/tmp", "${USER}", "streamflow")
)
)

Expand Down
5 changes: 5 additions & 0 deletions streamflow/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import itertools
import os
import posixpath
import pwd
import shlex
import uuid
from collections.abc import Iterable, MutableMapping, MutableSequence
Expand Down Expand Up @@ -232,6 +233,10 @@ async def get_local_to_remote_destination(
return dst


def get_local_username() -> str:
return pwd.getpwuid(os.getuid()).pw_name


def get_option(
name: str,
value: Any,
Expand Down
6 changes: 5 additions & 1 deletion streamflow/deployment/connector/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ async def copy_remote_to_remote(

async def deploy(self, external: bool) -> None:
os.makedirs(
os.path.join(os.path.realpath(tempfile.gettempdir()), "streamflow"),
os.path.join(
os.path.realpath(tempfile.gettempdir()),
utils.get_local_username(),
"streamflow",
),
exist_ok=True,
)

Expand Down
4 changes: 2 additions & 2 deletions streamflow/recovery/checkpoint_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from streamflow.core.data import DataLocation
from streamflow.core.deployment import ExecutionLocation, LocalTarget
from streamflow.core.recovery import CheckpointManager
from streamflow.core.utils import random_name

if TYPE_CHECKING:
from streamflow.core.context import StreamFlowContext
Expand All @@ -22,14 +21,15 @@ def __init__(self, context: StreamFlowContext, checkpoint_dir: str | None = None
super().__init__(context)
self.checkpoint_dir = checkpoint_dir or os.path.join(
os.path.realpath(tempfile.gettempdir()),
utils.get_local_username(),
"streamflow",
"checkpoint",
utils.random_name(),
)
self.copy_tasks: MutableSequence[asyncio.Task[None]] = []

async def _async_local_copy(self, data_location: DataLocation) -> None:
parent_directory = os.path.join(self.checkpoint_dir, random_name())
parent_directory = os.path.join(self.checkpoint_dir, utils.random_name())
local_path = os.path.join(parent_directory, data_location.relpath)
await self.context.data_manager.transfer_data(
src_location=data_location.location,
Expand Down
11 changes: 7 additions & 4 deletions tests/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from streamflow.core.context import StreamFlowContext
from streamflow.core.deployment import Target
from streamflow.core.exception import WorkflowDefinitionException
from streamflow.core.utils import compare_tags
from streamflow.core.workflow import Token
from streamflow.cwl.runner import main
from streamflow.cwl.step import CWLTransferStep
Expand Down Expand Up @@ -418,7 +417,7 @@ async def test_gather_order(context: StreamFlowContext) -> None:
if prev_tag is None:
assert token.tag == "0.0"
else:
assert compare_tags(token.tag, prev_tag) > 0
assert utils.compare_tags(token.tag, prev_tag) > 0
prev_tag = token.tag


Expand Down Expand Up @@ -508,9 +507,13 @@ async def test_workdir_inheritance() -> None:
assert binding_config.targets[3].deployment.name == "wrapper_4"
assert binding_config.targets[3].deployment.workdir is None
assert binding_config.targets[3].workdir == (
os.path.join(os.path.realpath(tempfile.gettempdir()), "streamflow")
os.path.join(
os.path.realpath(tempfile.gettempdir()),
utils.get_local_username(),
"streamflow",
)
if binding_config.targets[3].deployment == "local"
else posixpath.join("/tmp", "streamflow")
else posixpath.join("/tmp", "${USER}", "streamflow")
)


Expand Down
18 changes: 12 additions & 6 deletions tests/utils/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
Target,
WrapsConfig,
)
from streamflow.core.utils import random_name
from streamflow.core.workflow import Job
from streamflow.deployment import DefaultDeploymentManager
from tests.utils.data import get_data_path
Expand Down Expand Up @@ -75,8 +74,9 @@ async def get_deployment_config(
name="local-fs-volatile",
workdir=os.path.join(
os.path.realpath(tempfile.gettempdir()),
utils.get_local_username(),
"streamflow-test",
random_name(),
utils.random_name(),
"test-fs-volatile",
),
)
Expand Down Expand Up @@ -108,7 +108,7 @@ def get_docker_compose_deployment_config():
"files": [
str(get_data_path("deployment", "docker-compose", "docker-compose.yml"))
],
"projectName": random_name(),
"projectName": utils.random_name(),
},
external=False,
lazy=False,
Expand Down Expand Up @@ -179,7 +179,10 @@ def get_local_deployment_config(
name: str | None = None, workdir: str | None = None
) -> DeploymentConfig:
workdir = workdir or os.path.join(
os.path.realpath(tempfile.gettempdir()), "streamflow-test", random_name()
os.path.realpath(tempfile.gettempdir()),
utils.get_local_username(),
"streamflow-test",
utils.random_name(),
)
os.makedirs(workdir, exist_ok=True)
return DeploymentConfig(
Expand All @@ -204,7 +207,10 @@ async def get_location(

def get_parameterizable_hardware_deployment_config():
workdir = os.path.join(
os.path.realpath(tempfile.gettempdir()), "streamflow-test", random_name()
os.path.realpath(tempfile.gettempdir()),
utils.get_local_username(),
"streamflow-test",
utils.random_name(),
)
os.makedirs(workdir, exist_ok=True)
return DeploymentConfig(
Expand Down Expand Up @@ -255,7 +261,7 @@ async def get_slurm_deployment_config(_context: StreamFlowContext):
type="docker-compose",
config={
"files": [str(get_data_path("deployment", "slurm", "docker-compose.yml"))],
"projectName": random_name(),
"projectName": utils.random_name(),
},
external=False,
)
Expand Down
Loading