Skip to content
Snippets Groups Projects
Commit 7f07fe7f authored by Boman Romain's avatar Boman Romain
Browse files

fix path problems

parent ce4885e1
No related branches found
No related tags found
No related merge requests found
Pipeline #7088 passed
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Fossils:
# main script
from PyQt5.QtCore import *
from PyQt5.QtGui import *
......@@ -116,48 +118,66 @@ def view_results():
gmsh.fltk.run()
def rm_folder_from_pypath(folder):
sys.path = [ p for p in sys.path if not folder in p]
def add_folder2pypath(folder):
if os.path.isdir(folder):
print(f'{folder} added to pythonpath')
sys.path.append(folder)
def rm_folder_from_path(folder):
import platform
if 'Windows' in platform.uname():
path = [ p for p in os.environ['PATH'].split(';') if not folder in p]
os.environ['PATH'] = ';'.join(path)
# print(f'{folder} added to PATH')
# print(f"os.environ['PATH']={os.environ['PATH']}")
def add_folder2path(folder):
if not os.path.isdir(folder):
return
import platform
if 'Windows' in platform.uname():
path = os.environ['PATH'].split(';')
path.insert(0, folder)
# path.insert(0, folder)
path.append(folder)
os.environ['PATH'] = ';'.join(path)
print(f'{folder} added to PATH')
# print(f"os.environ['PATH']={os.environ['PATH']}")
def setup_pythonpath():
"""setup PYTHONPATH
"""
# adds script folder to the pythonpath
thisdir = os.path.split(os.path.abspath(__file__))[0]
thisdir = os.path.normcase(thisdir)
add_folder2pypath(thisdir)
this_script_dir = os.path.split(os.path.abspath(__file__))[0]
this_script_dir = os.path.normcase(this_script_dir)
# add_folder2pypath(this_script_dir) # already there as first entry
# add binary dir to PYTHONPATH
pyexe = os.path.basename(sys.executable)
print(f'pyexe = {pyexe}')
add_folder2pypath(os.path.join(thisdir, 'cxxfem',
add_folder2pypath(os.path.join(this_script_dir, 'cxxfem',
'build', 'bin')) # gcc/mingw
add_folder2pypath(os.path.join(thisdir, 'cxxfem',
add_folder2pypath(os.path.join(this_script_dir, 'cxxfem',
'build', 'bin', 'Release')) # msvc
# allows this script to be run without setting env
add_folder2pypath(os.path.join(thisdir, 'lib',
# allows this script to be run without setting env
rm_folder_from_path('gmsh')
rm_folder_from_pypath('gmsh')
add_folder2pypath(os.path.join(this_script_dir, 'lib',
'gmsh-sdk', 'lib')) # msvc
add_folder2path(os.path.join(thisdir, 'lib',
'gmsh-sdk', 'bin')) # gmsh
add_folder2path(os.path.join(this_script_dir, 'lib',
'gmsh-sdk', 'bin')) # gmsh
# print(f'sys.path={sys.path}')
def create_workspace(workspace, testname):
"""create workspace and chdir into it
"""create workspace folder and chdir into it
"""
if workspace:
# workspace is given:
# => workspace + testname
......@@ -168,14 +188,14 @@ def create_workspace(workspace, testname):
else:
# workspace is not given:
# => current_folder + 'workspace' + testname
thisdir = os.path.normcase(os.getcwd())
current_dir = os.path.normcase(os.getcwd())
# print(f'testname={testname}')
# print(f'thisdir={thisdir}')
common = os.path.commonprefix((testname, thisdir))
# print(f'current_dir={current_dir}')
common = os.path.commonprefix((testname, current_dir))
# print(f'common={common}')
resdir = testname[len(common)+1:].replace(os.sep, "_")
resdir, ext = os.path.splitext(resdir)
wdir = os.path.join('workspace', resdir)
wdir = os.path.abspath(os.path.join('workspace', resdir))
print('workspace =', wdir)
# sys.exit()
if not os.path.isdir(wdir):
......@@ -187,6 +207,10 @@ if __name__ == "__main__":
# add main program folder and binaries dir to the PYTHONPATH
setup_pythonpath()
# preload some modules (vtk before gmsh)
import vtk
import gmsh
# redirect C++ streams to Python
import cxxfem
redirect = cxxfem.StdOutErr2Py()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment