Skip to content

Commit

Permalink
Merge pull request #478 from linsword13/logger-fix
Browse files Browse the repository at this point in the history
Fix anonymous workspace setup with no log dir
  • Loading branch information
douglasjacobsen authored May 4, 2024
2 parents 4088551 + 21a08b8 commit d33af76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/ramble/ramble/test/cmd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,24 @@ def test_setup_command():
assert os.path.exists(ws.root + '/all_experiments')


def test_setup_command_with_missing_log_dir():
ws_name = "test"
workspace("create", ws_name)

with ramble.workspace.read("test") as ws:
add_basic(ws)
check_basic(ws)
# Missing log directory shouldn't prevent workspace
# setup, as long as the workspace is considered valid
# by the `is_workspace_dir` check.
os.rmdir(ws.log_dir)

workspace("concretize")

workspace("setup")
assert os.path.exists(ws.root + "/all_experiments")


def test_setup_nothing():
ws_name = 'test'
workspace('create', ws_name)
Expand Down
3 changes: 2 additions & 1 deletion lib/ramble/ramble/util/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import llnl.util.tty.color

from contextlib import contextmanager
from pathlib import Path


class Logger(object):
Expand Down Expand Up @@ -43,7 +44,7 @@ def add_log(self, path):
path: File path for the new log file
"""
if isinstance(path, str) and self.enabled:
stream = None
Path(path).parent.mkdir(parents=True, exist_ok=True)
stream = llnl.util.tty.log.Unbuffered(open(path, 'a+'))
self.log_stack.append((path, stream))

Expand Down

0 comments on commit d33af76

Please sign in to comment.