Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix imports generated by python generator to correctly find the root …

…of the generated code so that thrift includes work correctly
  • Loading branch information...
commit 8155862578f7fc4c55f1f3dd833975e05ce381fb 1 parent 856844d
@nathanmarz nathanmarz authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 compiler/cpp/src/generate/t_py_generator.cc
View
13 compiler/cpp/src/generate/t_py_generator.cc
@@ -297,6 +297,17 @@ void t_py_generator::init_generator() {
string t_py_generator::render_includes() {
const vector<t_program*>& includes = program_->get_includes();
string result = "";
+ string relative = "\"/\".join(__file__.split(\"/\")[:-1]) + \"/..\"";
+ string mymodule = program_->get_namespace("py");
+ if(!mymodule.empty()) {
+ //for every ., add another /.. to the relative path
+ for(unsigned int i=0; i<mymodule.size(); i++) {
+ if(mymodule[i] == '.') {
+ relative += " + \"/..\"";
+ }
+ }
+ }
+ result += "sys.path = [" + relative + "] + sys.path\n";
for (size_t i = 0; i < includes.size(); ++i) {
result += "import " + get_real_py_module(includes[i]) + ".ttypes\n";
}
@@ -336,7 +347,7 @@ string t_py_generator::py_autogen_comment() {
*/
string t_py_generator::py_imports() {
return
- string("from thrift.Thrift import *");
+ string("from thrift.Thrift import *\nimport sys");
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.