-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fishtest Coding Style Guide [RFC] #634
Comments
I'd leave the choice to those that actually write the code. I've used black https://github.com/psf/black in some hobby projects after a recommendation. |
following a style guide would be great. +1 to use a code formatter to set a good example in the codebase. i've used black at work before and it's not bad. worth checking out YAPF to see how they compare. |
This would be a quick preview on a blackened version of fishtest https://github.com/vondele/fishtest/tree/fishtestBlack |
Autoformat test on this snippet from
def make_player(arg):
return run['args'][arg].split(' ')[0]
while games_remaining > 0:
# Run cutechess-cli binary
cmd = [ cutechess, '-repeat', '-rounds', str(int(games_to_play/2)), '-games', ' 2', '-tournament', 'gauntlet'] + pgnout + \
['-site', 'https://tests.stockfishchess.org/tests/view/' + run['_id']] + \
['-event', 'Batch %d: %s vs %s' % (task_id, make_player('new_tag'), make_player('base_tag'))] + \
['-srand', "%d" % struct.unpack("<L", os.urandom(struct.calcsize("<L")))] + \
['-resign', 'movecount=3', 'score=400', '-draw', 'movenumber=34',
'movecount=8', 'score=20', '-concurrency', str(int(games_concurrency))] + pgn_cmd + \
['-engine', 'name=New-'+run['args']['resolved_new'][:7], 'cmd=%s' % (new_engine_name)] + new_options + ['_spsa_'] + \
['-engine', 'name=Base-'+run['args']['resolved_base'][:7], 'cmd=%s' % (base_engine_name)] + base_options + ['_spsa_'] + \
['-each', 'proto=uci', 'tc=%s' % (scaled_tc)] + nodestime_cmd + threads_cmd + book_cmd
task_status = launch_cutechess(cmd, remote, result, spsa_tuning, games_to_play,
tc_limit * games_to_play / min(games_to_play, games_concurrency))
if not task_status.get('task_alive', False):
break
def make_player(arg):
return run['args'][arg].split(' ')[0]
while games_remaining > 0:
# Run cutechess-cli binary
cmd = [ cutechess, '-repeat', '-rounds', str(int(games_to_play/2)), '-games', ' 2', '-tournament', 'gauntlet'] + pgnout + \
['-site', 'https://tests.stockfishchess.org/tests/view/' + run['_id']] + \
['-event', 'Batch %d: %s vs %s' % (task_id, make_player('new_tag'), make_player('base_tag'))] + \
['-srand', "%d" % struct.unpack("<L", os.urandom(struct.calcsize("<L")))] + \
['-resign', 'movecount=3', 'score=400', '-draw', 'movenumber=34',
'movecount=8', 'score=20', '-concurrency', str(int(games_concurrency))] + pgn_cmd + \
['-engine', 'name=New-'+run['args']['resolved_new'][:7], 'cmd=%s' % (new_engine_name)] + new_options + ['_spsa_'] + \
['-engine', 'name=Base-'+run['args']['resolved_base'][:7], 'cmd=%s' % (base_engine_name)] + base_options + ['_spsa_'] + \
['-each', 'proto=uci', 'tc=%s' % (scaled_tc)] + nodestime_cmd + threads_cmd + book_cmd
task_status = launch_cutechess(
cmd, remote, result, spsa_tuning, games_to_play,
tc_limit * games_to_play / min(games_to_play, games_concurrency))
if not task_status.get('task_alive', False):
break def make_player(arg):
return run["args"][arg].split(" ")[0]
while games_remaining > 0:
# Run cutechess-cli binary
cmd = (
[
cutechess,
"-repeat",
"-rounds",
str(int(games_to_play / 2)),
"-games",
" 2",
"-tournament",
"gauntlet",
]
+ pgnout
+ ["-site", "https://tests.stockfishchess.org/tests/view/" + run["_id"]]
+ [
"-event",
"Batch %d: %s vs %s"
% (task_id, make_player("new_tag"), make_player("base_tag")),
]
+ ["-srand", "%d" % struct.unpack("<L", os.urandom(struct.calcsize("<L")))]
+ [
"-resign",
"movecount=3",
"score=400",
"-draw",
"movenumber=34",
"movecount=8",
"score=20",
"-concurrency",
str(int(games_concurrency)),
]
+ pgn_cmd
+ [
"-engine",
"name=New-" + run["args"]["resolved_new"][:7],
"cmd=%s" % (new_engine_name),
]
+ new_options
+ ["_spsa_"]
+ [
"-engine",
"name=Base-" + run["args"]["resolved_base"][:7],
"cmd=%s" % (base_engine_name),
]
+ base_options
+ ["_spsa_"]
+ ["-each", "proto=uci", "tc=%s" % (scaled_tc)]
+ nodestime_cmd
+ threads_cmd
+ book_cmd
)
task_status = launch_cutechess(
cmd,
remote,
result,
spsa_tuning,
games_to_play,
tc_limit * games_to_play / min(games_to_play, games_concurrency),
)
if not task_status.get("task_alive", False):
break YAPF is a bit slower than Black on fishtest code base. YAPF takes the same time to process already formatted code, instead Black exit immediately.
I'm not able to replicate these YAPF anomalies pointed out in some (old) comparisons:
|
this reformats the code using `black --exclude=worker/requests .` fixes official-stockfish#634 as with any tool, not all is perfect, but things are pretty consistent. I propose to apply this patch (or execute the above black command) as part of the next worker change.
Not sure why but this command will ignore some of the files
|
also, I don't see a .mak in the formatting command, which formatting there should be done also :/ |
I don't think prettier supports mako templates, either format the scripts individually (copy and paste them here https://prettier.io/playground/) or move them to js files so they can be formatted with the command automatically |
I formatted the mako templates by hand, leaving unformatted the <script> tags. BTW the mako documentation uses different code formatting, so I randomly picked one type. |
Python
Python Official Style Guide
Google Python Style Guide
Tools list:
Command line:
Python version
CSS, HTML, Javascript
Google HTML/CSS Style Guide
Google Javasript Style Guide
Tools list:
Command line:
npx prettier --write 'server/fishtest/static/{css/*.css,html/*.html,js/*.js}'
Shell
Google Shell Style Guide
The text was updated successfully, but these errors were encountered: