From ba7b43812d998f897a06ab2828a08e86d4fcf6ea Mon Sep 17 00:00:00 2001 From: Shireen Elhabian Date: Wed, 2 Dec 2020 11:39:38 -0700 Subject: [PATCH] adding a setupenv module to examples based on the setting shapeworks environment notebook --- .gitattributes | 3 +++ Examples/Python/setupenv.py | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Examples/Python/setupenv.py diff --git a/.gitattributes b/.gitattributes index 898377a2bc..256a206c0c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,6 @@ *.vtk filter=lfs diff=lfs merge=lfs -text *.dcm filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text + +*.ipynb filter=nbstripout +*.ipynb diff=ipynb diff --git a/Examples/Python/setupenv.py b/Examples/Python/setupenv.py new file mode 100644 index 0000000000..d595f84054 --- /dev/null +++ b/Examples/Python/setupenv.py @@ -0,0 +1,40 @@ +import os +import sys +import platform + +# helper function to print out python path +def print_python_path(): + syspath = sys.path.copy() + print("\nPython path:") + for curpath in syspath: + if curpath != "": + print(curpath) + +# helper function to print out system path +def print_env_path(): + syspath = os.environ["PATH"].split(os.pathsep) + print("\nSystem path:") + for curpath in syspath: + if curpath != "": + print(curpath) + +# helper function to add shapeworks bin directory to the path +def setup_shapeworks_env(shapeworks_bin_dir, # path to the binary directory of shapeworks + dependencies_bin_dir, # path to the binary directory of shapeworks dependencies used when running build_dependencies.sh + verbose = True): + + # add shapeworks (and studio on mac) directory to python path + sys.path.append(shapeworks_bin_dir) + if platform.system() == "Darwin": # MacOS + sys.path.append(shapeworks_bin_dir + "/ShapeWorksStudio.app/Contents/MacOS") + + # add shapeworks and studio to the system path + os.environ["PATH"] = shapeworks_bin_dir + os.pathsep + os.environ["PATH"] + os.environ["PATH"] = dependencies_bin_dir + os.pathsep + os.environ["PATH"] + if platform.system() == "Darwin": # MacOS + os.environ["PATH"] = shapeworks_bin_dir + "/ShapeWorksStudio.app/Contents/MacOS" + os.pathsep + os.environ["PATH"] + + if verbose: + print_python_path() + print_env_path() + \ No newline at end of file