Initial steps for build_all.py

This commit is contained in:
andrew committed 2023-12-06 13:32:46 -05:00
1 parent 8e14f1c0b2
commit 2a461ecfaa
6 files changed
+271 -76

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
#!/bin/python3
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# OpenBench is a chess engine testing framework by Andrew Grant. #
# <https://github.com/AndyGrant/OpenBench> <andrew@grantnet.us> #
# #
# OpenBench is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# OpenBench is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import argparse
import os
import requests
import sys
# Needed to include from ../Client/*.py
PARENT = os.path.join(os.path.dirname(__file__), os.path.pardir)
sys.path.append(os.path.abspath(PARENT))
from Client.utils import url_join
from Client.utils import credentialed_cmdline_args
from Client.utils import credentialed_request
from Client.utils import download_network
from Client.utils import download_public_engine
def get_default_network_if_any(args, networks):
# Not all engines use Networks
if 'default' not in networks:
return None
# Download the default Network
net_name = networks['default']['name']
net_sha = networks['default']['sha']
net_path = os.path.join('Networks', net_sha)
download_network(args.server, args.username, args.password, engine, net_name, net_sha, net_path)
return net_path
if __name__ == '__main__':
# Use bench_all.py's path as the base pathway
os.chdir(os.path.dirname(os.path.abspath(__file__)))
# Ensure the folder structure for ease of coding
for folder in ['Engines', 'Networks']:
if not os.path.isdir(folder):
os.mkdir(folder)
# Get the list of engines on the Server
args = credentialed_cmdline_args()
request = credentialed_request(args.server, args.username, args.password, 'api/config')
for engine in request.json()['engines']:
if engine == 'Torch':
continue
# Get the configuration file for the engine
endpoint = 'api/config/%s' % (engine)
request = credentialed_request(args.server, args.username, args.password, endpoint)
config = request.json()
# Get the list of all Networks for the engine
endpoint = 'api/networks/%s' % (engine)
request = credentialed_request(args.server, args.username, args.password, endpoint)
net_path = get_default_network_if_any(args, request.json())
# Download, build, and move the engine to Engines/<engine>
make_path = config['build']['path']
branch = config['test_presets']['default']['base_branch']
out_path = os.path.join('Engines', engine)
target = url_join(config['source'], 'archive', '%s.zip' % (branch))
download_public_engine(engine, net_path, branch, target, make_path, out_path)
-71
View File
@@ -1,71 +0,0 @@
#!/bin/python3
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# OpenBench is a chess engine testing framework by Andrew Grant. #
# <https://github.com/AndyGrant/OpenBench> <andrew@grantnet.us> #
# #
# OpenBench is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# OpenBench is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import argparse
import hashlib
import os
import requests
def url_join(*args):
# Join a set of URL paths while maintaining the correct format
return '/'.join([f.lstrip('/').rstrip('/') for f in args]) + '/'
def download_network(username, password, server, engine, name):
print ('Downloading %s for %s...' % (name, engine))
target = url_join(server, 'clientGetNetwork', engine, name)
payload = { 'username' : username, 'password' : password }
request = requests.post(data=payload, url=target)
with open(name, 'wb') as fout:
for chunk in request.iter_content(chunk_size=1024):
if chunk: fout.write(chunk)
fout.flush()
if __name__ == '__main__':
# We can use ENV variables for Username, Password, and Server
req_user = required=('OPENBENCH_USERNAME' not in os.environ)
req_pass = required=('OPENBENCH_PASSWORD' not in os.environ)
req_server = required=('OPENBENCH_SERVER' not in os.environ)
# For clarity, seperate out this help text
help_user = 'Username. May also be passed as OPENBENCH_USERNAME environment variable'
help_pass = 'Password. May also be passed as OPENBENCH_PASSWORD environment variable'
help_server = ' Server. May also be passed as OPENBENCH_SERVER environment variable'
# Parse all arguments, all of which must exist in some form
p = argparse.ArgumentParser()
p.add_argument('-U', '--username', help=help_user , required=req_user )
p.add_argument('-P', '--password', help=help_pass , required=req_pass )
p.add_argument('-S', '--server' , help=help_server , required=req_server)
p.add_argument('-E', '--engine' , help='Engine' , required=True )
p.add_argument('-N', '--network' , help='Name or Sha', required=True )
args = p.parse_args()
# Fallback on ENV variables for Username, Password, and Server
args.username = args.username if args.username else os.environ['OPENBENCH_USERNAME']
args.password = args.password if args.password else os.environ['OPENBENCH_PASSWORD']
args.server = args.server if args.server else os.environ['OPENBENCH_SERVER' ]
download_network(args.username, args.password, args.server, args.engine, args.network)