#!/usr/bin/env python3

import os

with open('build/CP_instances') as cp_instances:
    with open('build/top.i', 'w') as top:
        path = os.path.abspath(os.getcwd())
        instances = ''.join(cp_instances.readlines())
        top.write(
          '%module top\n'
          '\n'
          '%{\n'
          '#include "../S_source.hh"\n'
          '\n' +
          instances + '\n'
          '%}\n'
          '\n'
          '%import "build' + path + '/S_source_py.i"\n'
          '\n' +
          instances)
