|
22 | 22 | from ..feature import Features |
23 | 23 | from .accuracy import Accuracy |
24 | 24 | from ..util.entrypoint import base_entry_point |
| 25 | +from ..util.os import MODE_BITS_SECURE |
25 | 26 |
|
26 | 27 |
|
27 | 28 | class ModelNotTrained(Exception): |
@@ -79,13 +80,20 @@ class Model(BaseDataFlowFacilitatorObject): |
79 | 80 | CONFIG = ModelConfig |
80 | 81 |
|
81 | 82 | 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() |
87 | 84 | return self.CONTEXT(self) |
88 | 85 |
|
| 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 | + |
89 | 97 |
|
90 | 98 | class SimpleModelNoContext: |
91 | 99 | """ |
@@ -113,6 +121,7 @@ async def __aenter__(self) -> Model: |
113 | 121 | # If we've already entered the model's context once, don't reload |
114 | 122 | if self._in_context > 1: |
115 | 123 | return self |
| 124 | + self._make_config_directory() |
116 | 125 | self.open() |
117 | 126 | return self |
118 | 127 |
|
|
0 commit comments