Skip to content

Commit

Permalink
Resolve SCIInstitute#1827 by adding version tag to all studio python …
Browse files Browse the repository at this point in the history
…api stuff
  • Loading branch information
akenmorris committed Oct 17, 2022
1 parent 4696426 commit 46d7131
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Python/shapeworks/shapeworks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def compute_line_indices(n, is_closed=True):
return lines

def get_api_version():
return "6.3"
return "6.4"

def set_sw_logger(log_object):
"""Set the shapeworks logger object"""
Expand Down
15 changes: 8 additions & 7 deletions Studio/src/Python/PythonWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ bool PythonWorker::init() {
#endif

// read pythonhome generated by:
// python -c "import sys; print(sys.prefix)" > $HOME/.shapeworks/python_home.txt
QString python_home_file = home + "/.shapeworks/python_home.txt";
// python -c "import sys; print(sys.prefix)" > $HOME/.shapeworks/python_home_<version>.txt
QString python_home_file = home + "/.shapeworks/python_home_" + PythonWorker::python_api_version + ".txt";
std::cerr << "Reading python home from " << python_home_file.toStdString() << "\n";

QFile qfile(python_home_file);
Expand All @@ -139,11 +139,12 @@ bool PythonWorker::init() {
}

// read list generated by something like this:
// python -c "import sys; print('\n'.join(sys.path))" > $HOME/.shapeworks/python_path.txt
// python -c "import sys; print('\n'.join(sys.path))" > $HOME/.shapeworks/python_path_<version>.txt
std::vector<std::string> python_path;
std::fstream file;

std::string python_path_file = home.toStdString() + "/.shapeworks/python_path.txt";
std::string
python_path_file = home.toStdString() + "/.shapeworks/python_path_" + PythonWorker::python_api_version + ".txt";
file.open(python_path_file, std::ios::in);
std::cerr << "Reading python path from " << python_path_file << "\n";
if (file.is_open()) {
Expand All @@ -170,7 +171,7 @@ bool PythonWorker::init() {
} else {
std::fstream file;
QString path;
file.open(home.toStdString() + "/.shapeworks/path.txt", std::ios::in);
file.open(home.toStdString() + "/.shapeworks/path_"+PythonWorker::python_api_version+".txt", std::ios::in);
if (file.is_open()) {
std::string line;
while (getline(file, line)) {
Expand Down Expand Up @@ -210,8 +211,8 @@ bool PythonWorker::init() {
std::string version = get_version().cast<std::string>();
if (version != PythonWorker::python_api_version) {
SW_ERROR("Unable to initialize Python. Expected API version " +
std::string(PythonWorker::python_api_version) +
" but found API version " + version + ". Please run " + script);
std::string(PythonWorker::python_api_version) +
" but found API version " + version + ". Please run " + script);
this->initialized_success_ = false;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Studio/src/Python/PythonWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PythonWorker : public QObject {
Q_OBJECT

public:
constexpr static const char* python_api_version = "6.3";
constexpr static const char* python_api_version = "6.4";

PythonWorker();
~PythonWorker();
Expand Down
6 changes: 5 additions & 1 deletion devenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# compiled portion of the Python bindings).
#

SW_MAJOR_VERSION=6.4

(return 0 2>/dev/null) && sourced=1 || sourced=0

if [[ "$sourced" == "0" ]]; then
Expand Down Expand Up @@ -39,7 +41,9 @@ done
echo "set PYTHONPATH to $PYTHONPATH"

# Set the python path for studio
mkdir -p $HOME/.shapeworks ; python -c "import sys; print('\n'.join(sys.path))" > $HOME/.shapeworks/python_path.txt
mkdir -p $HOME/.shapeworks
python -c "import sys; print('\n'.join(sys.path))" > $HOME/.shapeworks/python_path_${SW_MAJOR_VERSION}.txt
python -c "import sys; print(sys.prefix)" > $HOME/.shapeworks/python_home_${SW_MAJOR_VERSION}.txt

if [ -f ${BUILD}/shapeworks ] ; then
echo "shapeworks executable found ${BUILD}"
Expand Down
6 changes: 3 additions & 3 deletions install_shapeworks.bat
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ call .\Installation\install_python_module.bat
call .\Installation\conda_env_setup.bat

md %USERPROFILE%\.shapeworks
python -c "import sys; print('\n'.join(sys.path))" > %USERPROFILE%\.shapeworks\python_path.txt
python -c "import sys; print(sys.prefix)" > %USERPROFILE%\.shapeworks\python_home.txt
echo %PATH% > %USERPROFILE%\.shapeworks\path.txt
python -c "import sys; print('\n'.join(sys.path))" > %USERPROFILE%\.shapeworks\python_path_6.4.txt
python -c "import sys; print(sys.prefix)" > %USERPROFILE%\.shapeworks\python_home_6.4.txt
echo %PATH% > %USERPROFILE%\.shapeworks\path_6.4.txt
call conda info
8 changes: 6 additions & 2 deletions install_shapeworks.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# Installs conda environment for building ShapeWorks
#

SW_MAJOR_VERSION=6.4

echo ""
echo "Note: this script only supports bash and zsh shells "
echo " It must be called using \"source ./install_shapeworks.sh [--developer] [--user] [optional_env_name]\""
Expand Down Expand Up @@ -231,8 +234,9 @@ function install_conda() {

# Set the python path for studio
conda activate $CONDAENV
mkdir -p $HOME/.shapeworks ; python -c "import sys; print('\n'.join(sys.path))" > $HOME/.shapeworks/python_path.txt
python -c "import sys; print(sys.prefix)" > $HOME/.shapeworks/python_home.txt
mkdir -p $HOME/.shapeworks
python -c "import sys; print('\n'.join(sys.path))" > $HOME/.shapeworks/python_path_${SW_MAJOR_VERSION}.txt
python -c "import sys; print(sys.prefix)" > $HOME/.shapeworks/python_home_${SW_MAJOR_VERSION}.txt

return 0
}
Expand Down

0 comments on commit 46d7131

Please sign in to comment.