Codegen: collect imports from function calls; fix Python resource names. Just what it says on the tin.