File size: 1,326 Bytes
5fe2042
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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()