Skip to content

Commit

Permalink
Merge pull request #58 from venaturum/GH26_no_logfiles_found
Browse files Browse the repository at this point in the history
FileNotFoundError raised
  • Loading branch information
mattmilten authored Aug 1, 2024
2 parents 4975f8e + 726c6af commit d3f0db9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Unreleased
### Fixed
### Changed
- If logfiles are not found when parsing then a FileNotFoundError is raised
### Removed

## 3.1.0 - 2024-07-25
Expand Down
10 changes: 8 additions & 2 deletions src/gurobi_logtools/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ def parse(patterns: Union[str, List[str]], write_to_dir=None) -> ParseResult:
result = ParseResult(write_to_dir=write_to_dir)
if type(patterns) is str:
patterns = [patterns]
logfiles = itertools.chain(*(glob.glob(pattern) for pattern in patterns))
for logfile in sorted(set(logfiles)):
logfiles = sorted(
set(itertools.chain(*(glob.glob(pattern) for pattern in patterns)))
)
if not len(logfiles):
raise FileNotFoundError(f"No logfiles found in patterns: {patterns}")
for logfile in logfiles:
result.parse(logfile)
return result

Expand All @@ -190,8 +194,10 @@ def get_dataframe(logfiles: List[str], timelines=False, prettyparams=False):
"""
result = parse(logfiles)
summary = result.summary(prettyparams=prettyparams)

if not timelines:
return summary

return summary, dict(
norel=result.progress("norel"),
rootlp=result.progress("rootlp"),
Expand Down
5 changes: 5 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,8 @@ def test_rewrite_filenames():
assert log_file.stem == expected_name
assert len(start_lines) == 1
assert len(end_lines) == 1


def test_no_logfile_error():
with pytest.raises(FileNotFoundError):
glt.parse("/file/with/a/tyop")

0 comments on commit d3f0db9

Please sign in to comment.