21 lines
654 B
Python

def generate_source(target, source, env):
import os
import sys
from importlib.util import module_from_spec, spec_from_file_location
# allow the module to import from its current folder
sys.path.append(os.path.dirname(source[0].abspath))
python_spec = spec_from_file_location('source', source[0].abspath)
python_mod = module_from_spec(python_spec)
python_spec.loader.exec_module(python_mod)
python_mod.generate(targets = [t.abspath for t in target])
# restore path
sys.path = sys.path[:-1]
return None
pygen_builder = Builder(action = generate_source)
# env.Append(BUILDERS = {'PyGen': pygen_builder})