"""Fresh round8 tasks; inherit sealed round7 strictK, latest UI and review budget."""
import types

from .cluster_targets import digest
from .mask_model_training_data import PROJECT,write,require

path=PROJECT/'pallet/pallet_description_round7_release.py'
SOURCE=path.read_text().replace('round7','round8').replace('第七轮','第八轮')
for old,new in (("('new',3422),('existing',3423)","('new',3424),('existing',3425)"),
                ("=='latest_saved_human_correct_round6'","=='latest_saved_human_correct_round7'")):
    require(SOURCE.count(old)==1,'Round8 release adapter anchor changed: '+old);SOURCE=SOURCE.replace(old,new)
implementation=types.ModuleType('pallet._round8_release');implementation.__file__=__file__
exec(compile(SOURCE,str(path),'exec'),implementation.__dict__)
ROOT=implementation.ROOT;PREVIOUS=implementation.PREVIOUS;RELEASE=implementation.RELEASE;REVIEW_SETS=implementation.REVIEW_SETS
bind_review_sets=implementation.bind_review_sets;ui_assets=implementation.ui_assets;builder=implementation.builder
description_draft=implementation.description_draft


def run(phase):
    implementation.run(phase)
    if phase=='infer-masks':
        folder=ROOT/'release_implementation';(folder/'release_adapter_round8.py').write_text(SOURCE)
        write(folder/'round8_adapter.json',dict(adapter_sha256=digest(__file__),source_sha256=digest(path),adapted_sha256=digest(folder/'release_adapter_round8.py'),
            new_ports=[3424,3425],prior_tasks_services_models_unchanged=True,same_priority_rules_and_fixed_50_audit=True))


if __name__=='__main__':
    import argparse
    p=argparse.ArgumentParser();p.add_argument('phase',choices=('infer-masks','select-semantic','build-new','build-existing'));a=p.parse_args();run(a.phase)
