Skip to content

Commit d33af76

Browse files
Merge pull request #478 from linsword13/logger-fix
Fix anonymous workspace setup with no log dir
2 parents 4088551 + 21a08b8 commit d33af76

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/ramble/ramble/test/cmd/workspace.py

+18
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,24 @@ def test_setup_command():
621621
assert os.path.exists(ws.root + '/all_experiments')
622622

623623

624+
def test_setup_command_with_missing_log_dir():
625+
ws_name = "test"
626+
workspace("create", ws_name)
627+
628+
with ramble.workspace.read("test") as ws:
629+
add_basic(ws)
630+
check_basic(ws)
631+
# Missing log directory shouldn't prevent workspace
632+
# setup, as long as the workspace is considered valid
633+
# by the `is_workspace_dir` check.
634+
os.rmdir(ws.log_dir)
635+
636+
workspace("concretize")
637+
638+
workspace("setup")
639+
assert os.path.exists(ws.root + "/all_experiments")
640+
641+
624642
def test_setup_nothing():
625643
ws_name = 'test'
626644
workspace('create', ws_name)

lib/ramble/ramble/util/logger.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import llnl.util.tty.color
1212

1313
from contextlib import contextmanager
14+
from pathlib import Path
1415

1516

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

0 commit comments

Comments
 (0)