Coverage for sparkle/CLI/help/global_variables.py: 78%

27 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-27 09:10 +0000

1#!/usr/bin/env python3 

2"""Definitions of constants broadly used in Sparkle.""" 

3import ast 

4from pathlib import Path 

5 

6from sparkle.CLI.help.reporting_scenario import ReportingScenario 

7from sparkle.platform.settings_objects import Settings 

8 

9 

10# TODO: Handle different seed requirements; for the moment this is a dummy function 

11def get_seed() -> int: 

12 """Return a seed.""" 

13 return 1 

14 

15 

16__latest_scenario: ReportingScenario = None 

17 

18 

19def latest_scenario() -> ReportingScenario: 

20 """Function to get the global latest scenario object.""" 

21 global __latest_scenario 

22 if __latest_scenario is None: 

23 __latest_scenario = ReportingScenario() 

24 return __latest_scenario 

25 

26 

27__settings: Settings = None 

28 

29 

30def settings() -> Settings: 

31 """Function to get the global settings object.""" 

32 global __settings 

33 if __settings is None: 

34 __settings = Settings() 

35 return __settings 

36 

37 

38reference_list_dir = Path("Reference_Lists") 

39reference_list_dir.mkdir(exist_ok=True) 

40extractor_nickname_list_path = reference_list_dir / "sparkle_extractor_nickname_list.txt" 

41solver_nickname_list_path = reference_list_dir / "sparkle_solver_nickname_list.txt" 

42instances_nickname_path = reference_list_dir / "sparkle_instance_nickname_list.txt" 

43 

44file_storage_data_mapping = {solver_nickname_list_path: {}, 

45 instances_nickname_path: {}, 

46 extractor_nickname_list_path: {}} 

47 

48for data_path in file_storage_data_mapping.keys(): 

49 if data_path.exists(): 

50 with data_path.open("r+") as fo: 

51 file_storage_data_mapping[data_path] = ast.literal_eval(fo.read()) 

52 

53solver_nickname_mapping = file_storage_data_mapping[solver_nickname_list_path]