Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit feb1eed

Browse files
committed
model: SimpleModel create directory if not exists
Signed-off-by: John Andersen <[email protected]>
1 parent 2120dd5 commit feb1eed

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

dffml/model/model.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ..feature import Features
2323
from .accuracy import Accuracy
2424
from ..util.entrypoint import base_entry_point
25+
from ..util.os import MODE_BITS_SECURE
2526

2627

2728
class ModelNotTrained(Exception):
@@ -79,13 +80,20 @@ class Model(BaseDataFlowFacilitatorObject):
7980
CONFIG = ModelConfig
8081

8182
def __call__(self) -> ModelContext:
82-
# If the config object for this model contains the directory property
83-
# then create it if it does not exist
84-
directory = getattr(self.config, "directory", None)
85-
if directory is not None and not os.path.isdir(directory):
86-
os.makedirs(directory)
83+
self._make_config_directory()
8784
return self.CONTEXT(self)
8885

86+
def _make_config_directory(self):
87+
"""
88+
If the config object for this model contains the directory property
89+
then create it if it does not exist.
90+
"""
91+
directory = getattr(self.config, "directory", None)
92+
if directory is not None:
93+
directory = pathlib.Path(directory)
94+
if not directory.is_dir():
95+
directory.mkdir(mode=MODE_BITS_SECURE, parents=True)
96+
8997

9098
class SimpleModelNoContext:
9199
"""
@@ -113,6 +121,7 @@ async def __aenter__(self) -> Model:
113121
# If we've already entered the model's context once, don't reload
114122
if self._in_context > 1:
115123
return self
124+
self._make_config_directory()
116125
self.open()
117126
return self
118127

0 commit comments

Comments
 (0)