Skip to content

Commit

Permalink
enable carve out for initializing pipestat with "{record_identifier"
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Jun 3, 2024
1 parent b86e112 commit 743b26e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
23 changes: 14 additions & 9 deletions pipestat/backends/file_backend/filebackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,26 @@ def __init__(
self.result_formatter = result_formatter
self.multi_pipelines = multi_pipelines

self.determine_results_file(self.results_file_path)
self.determine_results_file()

def determine_results_file(self, results_file_path: str) -> None:
def determine_results_file(self) -> None:
"""Initialize or load results_file from given path
:param str results_file_path: YAML file to report into, if file is
used as the object back-end
"""
if not os.path.exists(self.results_file_path):
_LOGGER.debug(
f"Results file doesn't yet exist. Initializing: {self.results_file_path}"
)
self._init_results_file()

if "{record_identifier}" in self.results_file_path:
# In the special case where the user wants to use {record_identifier} in file path
pass
else:
_LOGGER.debug(f"Loading results file: {self.results_file_path}")
self._load_results_file()
if not os.path.exists(self.results_file_path):
_LOGGER.debug(
f"Results file doesn't yet exist. Initializing: {self.results_file_path}"
)
self._init_results_file()
else:
_LOGGER.debug(f"Loading results file: {self.results_file_path}")
self._load_results_file()

def check_record_exists(
self,
Expand Down
26 changes: 19 additions & 7 deletions pipestat/pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ def __init__(
),
self.cfg["config_path"],
)
make_subdirectories(self.cfg[FILE_KEY])

if "{record_identifier}" in str(self.cfg[FILE_KEY]):
# In the special case where the user wants to use {record_identifier} in file path
pass
else:
make_subdirectories(self.cfg[FILE_KEY])

self.cfg[RESULT_FORMATTER] = result_formatter

Expand Down Expand Up @@ -330,12 +335,19 @@ def resolve_results_file_path(self, results_file_path):
# Save for later when assessing if there may be multiple result files
if results_file_path:
assert isinstance(results_file_path, str), TypeError("Path is expected to be a str")
if not self.record_identifier and "{record_identifier}" in results_file_path:
raise NotImplementedError(
f"Must provide record identifier during PipestatManager creation for this results_file_path: {results_file_path}"
)
self.cfg["unresolved_result_path"] = results_file_path
return results_file_path.format(record_identifier=self.record_identifier)
if self.record_identifier:
try:
self.cfg["unresolved_result_path"] = results_file_path
results_file_path = results_file_path.format(
record_identifier=self.record_identifier
)
return results_file_path
except AttributeError:
self.cfg["unresolved_result_path"] = results_file_path
return results_file_path
else:
self.cfg["unresolved_result_path"] = results_file_path
return results_file_path
return results_file_path

def initialize_filebackend(self, record_identifier, results_file_path, flag_file_dir):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2245,8 +2245,8 @@ def test_multi_results_not_implemented(
backend_data = {"results_file_path": results_file_path}
args.update(backend_data)

with pytest.raises(NotImplementedError):
psm = SamplePipestatManager(**args)
# with pytest.raises(NotImplementedError):
psm = SamplePipestatManager(**args)

@pytest.mark.parametrize("backend", ["file"])
def test_multi_results_basic(
Expand Down

0 comments on commit 743b26e

Please sign in to comment.