diff --git a/streamflow/core/deployment.py b/streamflow/core/deployment.py index 5d420f4b2..cb5751f43 100644 --- a/streamflow/core/deployment.py +++ b/streamflow/core/deployment.py @@ -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") ) ) diff --git a/streamflow/core/utils.py b/streamflow/core/utils.py index e16765894..28aefb06b 100644 --- a/streamflow/core/utils.py +++ b/streamflow/core/utils.py @@ -7,6 +7,7 @@ import itertools import os import posixpath +import pwd import shlex import uuid from collections.abc import Iterable, MutableMapping, MutableSequence @@ -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, diff --git a/streamflow/deployment/connector/local.py b/streamflow/deployment/connector/local.py index 3c89c564c..49dcb2b4f 100644 --- a/streamflow/deployment/connector/local.py +++ b/streamflow/deployment/connector/local.py @@ -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, ) diff --git a/streamflow/recovery/checkpoint_manager.py b/streamflow/recovery/checkpoint_manager.py index b16b9088d..5c53aa832 100644 --- a/streamflow/recovery/checkpoint_manager.py +++ b/streamflow/recovery/checkpoint_manager.py @@ -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 @@ -22,6 +21,7 @@ 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(), @@ -29,7 +29,7 @@ def __init__(self, context: StreamFlowContext, checkpoint_dir: str | None = None 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, diff --git a/tests/test_translator.py b/tests/test_translator.py index c128913a8..17745203f 100644 --- a/tests/test_translator.py +++ b/tests/test_translator.py @@ -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 @@ -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 @@ -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") ) diff --git a/tests/utils/deployment.py b/tests/utils/deployment.py index a9bfebf62..84212088b 100644 --- a/tests/utils/deployment.py +++ b/tests/utils/deployment.py @@ -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 @@ -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", ), ) @@ -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, @@ -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( @@ -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( @@ -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, )