Load modular configs for Books + Engines

Produce some verification of correctness for those configs
Begin future client auto-updating things, with new config fields

client_repo_url, and client_repo_ref specifically.
This commit is contained in:
andrew authored and Andrew Grant committed 2023-11-16 20:25:11 -05:00
1 parent 5d8704d896
commit 37cc4a5b96
9 files changed
+157 -53

No files matched your search

+72 -38
View File
@@ -18,53 +18,87 @@
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import json, os.path, sys
import json
import os
from OpenSite.settings import PROJECT_PATH
def load_json_config(*path):
try:
with open(os.path.join(PROJECT_PATH, *path)) as fin:
return json.load(fin)
except:
print ('Error reading ', path)
sys.exit()
OPENBENCH_CONFIG = None # Initialized by OpenBench/apps.py
def load_folder_of_configs(*path):
return {
fname.removesuffix('.json') : load_json_config(*path, fname)
for fname in os.listdir(os.path.join(PROJECT_PATH, *path)) if fname.endswith('.json')
def create_openbench_config():
with open(os.path.join(PROJECT_PATH, 'Config', 'config.json')) as fin:
config_dict = json.load(fin)
config_dict['books'] = {
book : load_book_config(book) for book in config_dict['books']
}
USE_CROSS_APPROVAL = False # Require a second user to approve patches
REQUIRE_LOGIN_TO_VIEW = True # Block all content but Login and Regiser by default
REQUIRE_MANUAL_REGISTRATION = False # Disable the public facing registration page
config_dict['engines'] = {
engine : load_engine_config(engine) for engine in config_dict['engines']
}
OPENBENCH_CONFIG = {
return config_dict
# Server Client version control
'client_version' : 18,
def load_book_config(book_name):
# Generic Error Messages useful to those setting up their own instance
'error' : {
'disabled' : 'Account has not been enabled. Contact an Administrator',
'fakeuser' : 'This is not a real OpenBench User. Create an OpenBench account',
'requires_login' : 'All pages require a user login to access',
'manual_registration' : 'Registration can only be done via an Administrator',
},
with open(os.path.join(PROJECT_PATH, 'Books', '%s.json' % (book_name))) as fin:
conf = json.load(fin)
# Link to the repo on the sidebar, as well as the core files
'framework' : 'http://github.com/AndyGrant/OpenBench/',
'corefiles' : 'https://raw.githubusercontent.com/AndyGrant/OpenBench/master/CoreFiles',
assert type(conf.get('sha')) == str
assert type(conf.get('source')) == str
# Test Configuration. For both SPRT and Fixed Games Tests
'tests' : {
'max_games' : '40000', # Default for Fixed Games
'confidence' : '[0.10, 0.05]', # SPRT Type I/II Confidence
},
return conf
# Take a look at Books/books.json
'books' : load_folder_of_configs('Books'),
def load_engine_config(engine_name):
# Take a look at json file in Engines/
'engines' : load_folder_of_configs('Engines'),
}
with open(os.path.join(PROJECT_PATH, 'Engines', '%s.json' % (engine_name))) as fin:
conf = json.load(fin)
verify_engine_basics(engine_name, conf)
verify_engine_build(engine_name, conf)
# for test_mode in conf['test_modes']:
# verify_engine_test_mode(test_mode)
#
# for tune_mode in conf['tune_modes']:
# verify_engine_test_mode(test_mode)
return conf
def verify_engine_basics(engine_name, conf):
assert type(conf.get('private')) == bool
assert type(conf.get('nps')) == int and conf['nps'] > 0
assert type(conf.get('base')) == str
assert type(conf.get('source')) == str
assert type(conf.get('bounds')) == str
assert type(conf.get('book')) == str
assert type(conf.get('win_adj')) == str
assert type(conf.get('draw_adj')) == str
assert type(conf.get('build')) == dict
assert type(conf.get('test_modes')) == dict
assert type(conf['test_modes'].get('STC')) == dict
assert type(conf.get('tune_modes')) == dict
assert type(conf['tune_modes'].get('STC')) == dict
def verify_engine_build(engine_name, conf):
assert type(conf['build'].get('cpuflags')) == list
assert all(type(x) == str for x in conf['build']['cpuflags'])
assert type(conf['build'].get('systems')) == list
assert all(type(x) == str for x in conf['build']['systems'])
if conf['private']: # Private engines require a PAT
fname = 'credentials.%s' % (engine_name.replace(' ', '').lower())
assert os.path.exists(os.path.join(PROJECT_PATH, 'Config', fname))
else: # Public engines require a Makefile path and valid compilers
assert type(conf['build'].get('path')) == str
assert type(conf['build'].get('compilers')) == list
assert all(type(x) == str for x in conf['build']['compilers'])