Skip to content

Commit

Permalink
Delete cached tests after contest type change
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 24, 2023
1 parent c87f551 commit 35880a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/sinol_make/commands/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,6 @@ def set_group_result(solution, group, result):
self.possible_score
)


if self.args.apply_suggestions:
for solution in diff.removed_solutions:
del config_expected_scores[solution]
Expand All @@ -951,7 +950,6 @@ def set_group_result(solution, group, result):
else:
config_expected_scores[solution] = diff.new_expected_scores[solution]


self.config["sinol_expected_scores"] = self.convert_status_to_string(config_expected_scores)
util.save_config(self.config)
print(util.info("Saved suggested expected scores description."))
Expand Down Expand Up @@ -1129,6 +1127,7 @@ def run(self, args):
print("Task: %s (tag: %s)" % (title, self.ID))
self.cpus = args.cpus or mp.cpu_count()
cache.save_to_cache_extra_compilation_files(self.config.get("extra_compilation_files", []), self.ID)
cache.check_if_contest_type_changed(self.config.get("contest_type", "default"))

checker = package_util.get_files_matching_pattern(self.ID, f'{self.ID}chk.*')
if len(checker) != 0:
Expand Down
20 changes: 20 additions & 0 deletions src/sinol_make/helpers/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,23 @@ def save_to_cache_extra_compilation_files(extra_compilation_files, task_id):

info.md5sum = md5sum
info.save(file_path)


def check_if_contest_type_changed(contest_type):
"""
Checks if contest type has changed and removes all cached test results if it has.
:param contest_type: Contest type
"""
try:
with open(paths.get_cache_path("contest_type"), 'r') as cache_file:
cache_contest_type = cache_file.read().strip()
if cache_contest_type != contest_type:
for solution in os.listdir(paths.get_cache_path('md5sums')):
info = get_cache_file(solution)
info.tests = {}
info.save(solution)
except FileNotFoundError:
pass
os.makedirs(paths.get_cache_path(), exist_ok=True)
with open(paths.get_cache_path("contest_type"), 'w') as cache_file:
cache_file.write(contest_type)

0 comments on commit 35880a4

Please sign in to comment.