#!/usr/bin/env python # -*- coding: utf-8 -*- import os import shutil from os import environ as env from datasets import load_dataset def create_task_projects(): dataset = load_dataset(env['HF_DATASET'], split='test') base_dir = 'hardhat' for row in dataset: task_id = row['task_id'] test_content = row['test'] canonical_solution = row['canonical_solution'] task_dir = os.path.join('tasks', task_id.replace('/', '_')) if os.path.exists(task_dir): shutil.rmtree(task_dir) os.makedirs(task_dir) for item in os.listdir(base_dir): if item == 'hardhat.config.js': continue src = os.path.join(base_dir, item) dst = os.path.join(task_dir, item) os.symlink(os.path.abspath(src), dst) shutil.copy(os.path.join(base_dir, 'hardhat.config.js'), task_dir) os.makedirs(os.path.join(task_dir, 'contracts'), exist_ok=True) os.makedirs(os.path.join(task_dir, 'test'), exist_ok=True) with open(os.path.join(task_dir, 'contracts', 'Task.sol'), 'w') as f: f.write(canonical_solution) with open(os.path.join(task_dir, 'test', 'Task.js'), 'w') as f: f.write(test_content) if __name__ == '__main__': create_task_projects()