Skip to content

Commit

Permalink
#2285 Adjusted the path for python scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Apr 7, 2023
1 parent a14085d commit 0c1aaad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
50 changes: 39 additions & 11 deletions src/basic/vx_util/python_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ using namespace std;
////////////////////////////////////////////////////////////////////////


static const char set_python_env_wrapper [] = "set_python_env";
static const char env_PYTHONPATH [] = "PYTHONPATH";

static const char write_tmp_mpr_wrapper [] = "MET_BASE/wrappers/write_tmp_mpr.py";
static const char met_python_path [] = "MET_BASE/python";

static const char set_python_env_wrapper [] = "pyembed.set_python_env";

static const char write_tmp_mpr_wrapper [] = "MET_BASE/python/pyembed/write_tmp_mpr.py";

static const char list_name [] = "mpr_data";

Expand Down Expand Up @@ -301,9 +305,7 @@ void PyLineDataFile::do_straight()

{

ConcatString command, path, user_base;

path = set_python_env_wrapper;
ConcatString command, user_base;

mlog << Debug(3)
<< "PyLineDataFile::do_straight() -> "
Expand All @@ -318,7 +320,7 @@ user_base.chomp(".py");
// start up the python interpreter
//

script = new Python3_Script (path.text());
script = get_python3_script();

//
// set up a "new" sys.argv list
Expand Down Expand Up @@ -434,11 +436,7 @@ if ( status ) {

}

ConcatString wrapper;

wrapper = set_python_env_wrapper;

script = new Python3_Script (wrapper.text());
script = get_python3_script();

mlog << Debug(4) << "Reading temporary Python line data file: "
<< tmp_ascii_path << "\n";
Expand Down Expand Up @@ -574,6 +572,36 @@ return;
}


////////////////////////////////////////////////////////////////////////

Python3_Script *get_python3_script()

{

const char *method_name = "get_python3_script()";
ConcatString path = set_python_env_wrapper;
ConcatString python_path = met_python_path;

const char *env_pythonpath = getenv(env_PYTHONPATH);

if (env_pythonpath) {
python_path = env_pythonpath;
python_path.add(':');
}
python_path.add(replace_path(met_python_path));
mlog << Debug(0) << method_name << " -> added python path "
<< replace_path(met_python_path) << ") to " << env_PYTHONPATH << "\n";

setenv(env_PYTHONPATH, python_path.c_str(),1);

//
// start up the python interpreter
//

return new Python3_Script (path.text());

}

////////////////////////////////////////////////////////////////////////


Expand Down
3 changes: 3 additions & 0 deletions src/basic/vx_util/python_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class PyLineDataFile : public LineDataFile {

////////////////////////////////////////////////////////////////////////

extern Python3_Script *get_python3_script();

////////////////////////////////////////////////////////////////////////

#endif /* __PYTHON_LINE_H__ */

Expand Down

0 comments on commit 0c1aaad

Please sign in to comment.