Skip to content

Commit

Permalink
Merge pull request #240 from KernelTuner/reduce_complexity_read_cache
Browse files Browse the repository at this point in the history
improve code quality of cache file related functions
  • Loading branch information
benvanwerkhoven authored Jan 27, 2024
2 parents 5465a09 + cf5866c commit 4b74402
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions kernel_tuner/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,8 +1167,9 @@ def process_cache(cache, kernel_options, tuning_options, runner):
tuning_options.cache = cached_data["cache"]


def read_cache(cache, open_cache=True):
"""Read the cachefile into a dictionary, if open_cache=True prepare the cachefile for appending."""
def correct_open_cache(cache, open_cache=True):
""" if cache file was not properly closed, pretend it was properly closed """

with open(cache, "r") as cachefile:
filestr = cachefile.read().strip()

Expand All @@ -1185,6 +1186,13 @@ def read_cache(cache, open_cache=True):
with open(cache, "w") as cachefile:
cachefile.write(filestr[:-3] + ",")

return filestr

def read_cache(cache, open_cache=True):
"""Read the cachefile into a dictionary, if open_cache=True prepare the cachefile for appending."""

filestr = correct_open_cache(cache, open_cache)

error_configs = {
"InvalidConfig": InvalidConfig(),
"CompilationFailedConfig": CompilationFailedConfig(),
Expand Down

0 comments on commit 4b74402

Please sign in to comment.