From 65fe3a189410939f7e6702d4173504b82af75bb4 Mon Sep 17 00:00:00 2001 From: William Patton Date: Thu, 12 Sep 2024 09:57:20 -0700 Subject: [PATCH] trying to avoid `daisy_logs` artifact after running tests --- daisy/client.py | 2 ++ daisy/context.py | 3 ++- daisy/logging.py | 8 +++++++- daisy/server.py | 1 + daisy/task_worker_pools.py | 1 + tests/conf.py | 8 ++++++++ 6 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/conf.py diff --git a/daisy/client.py b/daisy/client.py index bfc9f2ca..3fa6fa06 100644 --- a/daisy/client.py +++ b/daisy/client.py @@ -1,5 +1,6 @@ from .block import BlockStatus from .context import Context +from .logging import set_log_basedir from .messages import ( AcquireBlock, BlockFailed, @@ -56,6 +57,7 @@ def __init__(self, context=None): self.context = Context.from_env() logger.debug("Client context: %s", self.context) + set_log_basedir(self.context["logdir"]) self.host = self.context["hostname"] self.port = int(self.context["port"]) self.worker_id = int(self.context["worker_id"]) diff --git a/daisy/context.py b/daisy/context.py index 82a52a1f..f3c7480c 100644 --- a/daisy/context.py +++ b/daisy/context.py @@ -1,6 +1,7 @@ import copy import logging import os +from .logging import get_log_basedir logger = logging.getLogger(__name__) @@ -11,7 +12,7 @@ class Context: def __init__(self, **kwargs): - self.__dict = dict(**kwargs) + self.__dict = dict(logdir=get_log_basedir(), **kwargs) def copy(self): diff --git a/daisy/logging.py b/daisy/logging.py index 504c6792..9a5e644b 100644 --- a/daisy/logging.py +++ b/daisy/logging.py @@ -22,10 +22,16 @@ def set_log_basedir(path): else: LOG_BASEDIR = None +def get_log_basedir(): + """Get the base directory for logging.""" + global LOG_BASEDIR + return LOG_BASEDIR + def get_worker_log_basename(worker_id, task_id=None): """Get the basename of log files for individual workers.""" - + global LOG_BASEDIR + if LOG_BASEDIR is None: return None diff --git a/daisy/server.py b/daisy/server.py index 0d3e1e65..e7469d26 100644 --- a/daisy/server.py +++ b/daisy/server.py @@ -2,6 +2,7 @@ from .block import BlockStatus from .block_bookkeeper import BlockBookkeeper from .context import Context +from .logging import get_log_basedir from .messages import ( AcquireBlock, BlockFailed, diff --git a/daisy/task_worker_pools.py b/daisy/task_worker_pools.py index e4eb7ed6..eb14f482 100644 --- a/daisy/task_worker_pools.py +++ b/daisy/task_worker_pools.py @@ -1,4 +1,5 @@ from .context import Context +from .logging import get_log_basedir from .server_observer import ServerObserver from .worker_pool import WorkerPool import logging diff --git a/tests/conf.py b/tests/conf.py new file mode 100644 index 00000000..b6a70be2 --- /dev/null +++ b/tests/conf.py @@ -0,0 +1,8 @@ +import pytest + +from daisy.logging import set_log_basedir, get_log_basedir + + +@pytest.fixture(autouse=True) +def logdir(tmp_path): + set_log_basedir(tmp_path / "daisy_logs") \ No newline at end of file