diff --git a/OpenBench/pipeline_views.py b/OpenBench/pipeline_views.py index 4f39470..c89b925 100644 --- a/OpenBench/pipeline_views.py +++ b/OpenBench/pipeline_views.py @@ -30,6 +30,8 @@ # of, and takes no input from the request at all except which object it is for. # Every decision, allowed or refused, leaves an event behind. +import OpenBench.config +import OpenBench.pipeline_defaults as defaults import OpenBench.pipeline_graph as graphs import OpenBench.pipeline_layout as drawing import OpenBench.pipelines @@ -41,7 +43,7 @@ import json from django.http import JsonResponse from django.views.decorators.http import require_POST -from OpenBench.models import LogEvent, Pipeline, PipelineRun, Profile, StepRun, Test +from OpenBench.models import LogEvent, Network, Pipeline, PipelineRun, Profile, StepRun, Test STATUS_LABELS = { 'QUEUED' : 'Waiting', 'LAUNCHING' : 'Starting', 'RUNNING' : 'Running', @@ -624,3 +626,166 @@ def pipeline_test_fields(request, test_id): fields['test_max_games'] = test.max_games return JsonResponse({ 'payload' : { key : str(value) for key, value in fields.items() } }) + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# QUICK START # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +# What the New pipeline button opens. It asks for one thing, the dev branch, and +# fills in everything else the way that the Create Test page does ( the same +# presets, the same defaults, see pipeline_defaults.py ), so that a branch and an +# Enter are all that it takes, as they are for a single test. What comes out is a +# plain pipeline, which the editor can change like any other. + +def _quick_engine(profile, wanted): + + """ The engine to make tests for: the one asked for, else the default of this + person, else the first there is. '' when the server has none at all """ + + engines = OpenBench.config.OPENBENCH_CONFIG['engines'] + + for name in (wanted, profile.engine): + if name in engines: + return name + + return next(iter(engines), '') + +def _quick_choices(engine_config): + + """ ( the presets to choose from, the one that goes first, the one that follows ) """ + + names = defaults.preset_names(engine_config) + first = 'STC' if 'STC' in names else (names[0] if names else '') + then = 'LTC' if 'LTC' in names and first != 'LTC' else '' + + choices = [{ 'name' : name, 'time' : defaults.time_control(engine_config, name) } for name in names] + return choices, first, then + +def _quick_page(request, engine, choices, form, error=None): + + config = OpenBench.config.OPENBENCH_CONFIG + + # What the presets say about the base branch, to show where the box is left blank + base = defaults.test_payload(engine, config['engines'][engine], form['first'], 'dev')[0].get('base_branch', '') + + data = { + 'engine' : engine, + 'engines' : list(config['engines']), + 'choices' : choices, + 'form' : form, + 'base' : base, + 'more' : bool(form['base_branch'] or form['name'] or not base), + } + + return OpenBench.views.render(request, 'pipeline_quick.html', data, error=error) + +def pipeline_quick(request): + + profile = viewer(request) + if profile is None: + return _turn_away(request, profile) + + config = OpenBench.config.OPENBENCH_CONFIG + source = request.POST if request.method == 'POST' else request.GET + engine = _quick_engine(profile, source.get('engine')) + + if not engine: + return OpenBench.views.redirect(request, '/pipelines/', error='No engine is set up on this server') + + engine_config = config['engines'][engine] + choices, first, then = _quick_choices(engine_config) + names = [choice['name'] for choice in choices] + + if not names: + return OpenBench.views.redirect(request, '/pipelines/new/', error='%s has no test presets, so its pipelines are made here' % (engine)) + + asked = { + 'dev_branch' : (source.get('dev_branch' ) or '').strip(), + 'base_branch' : (source.get('base_branch') or '').strip(), + 'name' : (source.get('name' ) or '').strip(), + 'first' : source.get('first', first), + 'then' : source.get('then' , then ), + } + + form = dict(asked, + first = asked['first'] if asked['first'] in names else first, + then = asked['then' ] if asked['then' ] in names else '') + + if request.method != 'POST': + return _quick_page(request, engine, choices, form) + + errors = [] + + branch = defaults.clean_branch(asked['dev_branch']) + if not asked['dev_branch']: + errors.append('Type the name of the branch to test') + elif branch is None: + errors.append('"%s" cannot be a branch, which has no spaces or quotes' % (asked['dev_branch'][:40])) + + base = asked['base_branch'] + if base and defaults.clean_branch(base) is None: + errors.append('"%s" cannot be a branch, which has no spaces or quotes' % (base[:40])) + + if asked['first'] not in names: + errors.append('Pick the test to run first') + + if asked['then'] and asked['then'] not in names: + errors.append('Pick the test to run after it, or none') + + if errors: + return _quick_page(request, engine, choices, form, error='\n'.join(errors)) + + networks = list(Network.objects.all().values()) + books = list(config['books']) + plan = [asked['first']] + ([asked['then']] if asked['then'] else []) + + steps, lacking = [], [] + + for preset in plan: + payload, absent = defaults.test_payload(engine, engine_config, preset, branch, profile.repos, networks, books, base) + steps.append((preset, payload)) + lacking += [(preset, key) for key in absent] + + if any(key == 'base_branch' for _, key in lacking): + errors.append('Type the base branch, as the engine does not say which one to test against') + + others = ['%s (%s)' % (key.replace('_', ' '), preset) for preset, key in lacking if key != 'base_branch'] + if others: + errors.append('The presets of %s leave out: %s\nFill those in with the editor' % (engine, ', '.join(others))) + + if errors: + return _quick_page(request, engine, choices, form, error='\n'.join(errors)) + + graph = defaults.quick_graph(steps) + issues = _check(graph) + + if graphs.has_errors(issues): # Nothing for a person to fix: this page never builds anything that is wrong + problems = '\n'.join(i['message'] for i in issues if i['level'] == 'error') + return _quick_page(request, engine, choices, form, error='The pipeline could not be made:\n' + problems) + + author = profile.user.username + title = asked['name'][:128] or defaults.quick_name(branch, [label for label, _ in steps]) + + pipeline = Pipeline.objects.create(name=title, author=author, graph=_tidy(graph)) + pipeline_id = pipeline.id + + _audit(author, 'PIPELINE #%d CREATED' % (pipeline_id)) + + if request.POST.get('action') == 'save': + return OpenBench.views.redirect(request, '/pipelines/%d/' % (pipeline_id), status='Pipeline saved') + + run, issues = OpenBench.pipelines.start_pipeline(pipeline, starter=author) + first_step = StepRun.objects.filter(run=run).order_by('id').first() if run else None + + if run is None or (run.status == 'ERROR' and first_step): + + reason = first_step.message if first_step else '\n'.join(i['message'] for i in issues if i['level'] == 'error') + + # Nothing was made, and a pipeline that never made anything is of no use to anybody + pipeline.delete() + _audit(author, 'PIPELINE #%d DISCARDED' % (pipeline_id)) + + return _quick_page(request, engine, choices, form, error='The first test could not be created:\n' + reason) + + return OpenBench.views.redirect(request, '/pipelines/run/%d/' % (run.id), status='Pipeline started') diff --git a/OpenBench/urls.py b/OpenBench/urls.py index 34e6fcc..3414ac4 100644 --- a/OpenBench/urls.py +++ b/OpenBench/urls.py @@ -50,6 +50,7 @@ urlpatterns = [ django.urls.path(r'pipelines//delete/', OpenBench.pipeline_views.pipeline_delete), django.urls.path(r'pipelines//edit/', OpenBench.pipeline_views.pipeline_edit), django.urls.path(r'pipelines/new/', OpenBench.pipeline_views.pipeline_new), + django.urls.path(r'pipelines/quick/', OpenBench.pipeline_views.pipeline_quick), django.urls.path(r'pipelines/check/', OpenBench.pipeline_views.pipeline_check), django.urls.path(r'pipelines/preview/', OpenBench.pipeline_views.pipeline_preview), django.urls.path(r'pipelines/test-fields//', OpenBench.pipeline_views.pipeline_test_fields), diff --git a/Templates/OpenBench/pipeline_quick.html b/Templates/OpenBench/pipeline_quick.html new file mode 100644 index 0000000..2072633 --- /dev/null +++ b/Templates/OpenBench/pipeline_quick.html @@ -0,0 +1,92 @@ +{% extends "OpenBench/base.html" %} + +{% block page_head %} +
+ Pipelines +

New pipeline

+

Type a branch and press Enter. Everything else is filled in like Create Test, and the first test starts right away

+
+{% endblock %} + +{% block content %} + + + +
+ {% csrf_token %} + +
+
+ +

What to test

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ More options + + {% if engines|length > 1 %} +
+ + +
+ {% else %} + + {% endif %} + +
+ + +
+ +
+ + +
+
+ +
+
+ +
+
+ + +
+
+
+ +

Need to retry, branch on a failure, or tune? Draw the flow in the editor.

+ +{% endblock %} diff --git a/Templates/OpenBench/pipelines.html b/Templates/OpenBench/pipelines.html index ddecb16..f33b11d 100644 --- a/Templates/OpenBench/pipelines.html +++ b/Templates/OpenBench/pipelines.html @@ -7,7 +7,8 @@ {% endblock %}