Skip to content

Commit

Permalink
[runrms] add APS_TOOLBOX_PATH env
Browse files Browse the repository at this point in the history
In addition some fixed for test versions and options like
--nopy
  • Loading branch information
jcrivenaes committed Aug 22, 2023
1 parent 5d563f6 commit 90e4efc
Showing 1 changed file with 63 additions and 33 deletions.
96 changes: 63 additions & 33 deletions src/subscript/runrms/runrms.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def __init__(self):
self.runloggerfile = "/prog/roxar/site/log/runrms_usage.log"
self.userwarnings = [] # a list of user warnings to display e.g. upgrade ver.
self.warn_empty_version = False
self.aps_toolbox_path = None

self.detect_os()

Expand Down Expand Up @@ -421,26 +422,57 @@ def requested_rms_version(self):
if self.exe is None:
raise RuntimeError("Executable is not found, probably a config/setup error")

self._pythonpath_etc_extract(rmssection, proposed_version)

logger.debug("EXECUTABLE: %s", self.exe)
logger.debug("PYTHONPATH: %s", self.pythonpath)
logger.debug("PLUGINSPATH: %s", self.pluginspath)
logger.debug("TCLTK: %s", self.tcltkpath)
logger.debug("APS_TOOLBOX_PATH: %s", self.aps_toolbox_path)

def _pythonpath_etc_extract(self, rmssection, proposed_version):
"""Get the PYTHONPATH etc given various options.
Set state variables: pythonpath, pluginspath, aps_toolbox_path, tcltkpath
"""
pypath = self.setup[rmssection][proposed_version].get("pythonpath", None)
self.pythonpath = self._process_genericpath(pypath)
if self.args.testpylib:
pypath = self.setup[rmssection][proposed_version].get(
"pythonpathtest", None
)
if not pypath:
raise ValueError("Could not retrieve 'pythonpathtest'")

# test pythonpath
pypathtest = self.setup[rmssection][proposed_version].get(
"pythonpathtest", None
)
if pypathtest:
self.testpythonpath = self._process_genericpath(pypathtest)
if isinstance(pypath, str):
pypath = [pypath]

if self.args.incsyspy:
pypath.append(self.oldpythonpath)

if self.args.nopy and not self.args.testpylib:
pypath.pop(0)

if self.args.nopy and self.args.testpylib:
raise ValueError("Combing '--nopy' and '--testpylib' is not allowed")

pluginspath = self.setup[rmssection][proposed_version].get("pluginspath", None)
if pluginspath:
self.pluginspath = self._process_genericpath(pluginspath)
self.pythonpath = self._process_genericpath(pypath)

if self.args.testpylib:
pluginspath = self.setup[rmssection][proposed_version].get(
"pluginspathtest", None
)
else:
pluginspath = self.setup[rmssection][proposed_version].get(
"pluginspath", None
)
self.pluginspath = self._process_genericpath(pluginspath)

self.tcltkpath = self.setup[rmssection][proposed_version].get("tcltkpath", None)

logger.debug("EXECUTABLE: %s", self.exe)
logger.debug("PYTHONPATH: %s", self.pythonpath)
logger.debug("PLUGINSPATH: %s", self.pluginspath)
logger.debug("TCLTK: %s", self.tcltkpath)
if (pathlib.Path(pypath[0]) / "aps").exists():
self.aps_toolbox_path = f"{pypath[0]}/aps/toolbox"
else:
self.aps_toolbox_path = ""

def _process_genericpath(self, pypath):
"""Collect and validate input pythonpath/testpythonpath/pluginspath from setup.
Expand All @@ -456,24 +488,26 @@ def _process_genericpath(self, pypath):
"/some/main/python3.6/site-packages:/some/other/python3.6/site-packages"
"""
pypathlist = []

pypathlist = []
if not isinstance(pypath, list):
# Allow both string and list syntax in yml:
pypath = [pypath]

if isinstance(pypath, list):
for pyp in pypath:
pyp = pyp.replace("<PLATFORM>", self.osver)
for pyp in pypath:
if pyp is None:
continue

if self.args.dryrun:
pypathlist.append(pyp) # in dryrun mode accept non-existing dirs
continue
pyp = pyp.replace("<PLATFORM>", self.osver)

if pathlib.Path(pyp).is_dir():
pypathlist.append(pyp)
else:
xwarn(f"Proposed {pypath} does not exist!")
if self.args.dryrun:
pypathlist.append(pyp) # in dryrun mode accept non-existing dirs
continue

if pathlib.Path(pyp).is_dir():
pypathlist.append(pyp)
else:
xwarn(f"Proposed {pypath} does not exist!")

if not pypathlist:
xwarn("No valid in-house PYTHONPATHS are provided")
Expand Down Expand Up @@ -646,14 +680,6 @@ def _collect_env_settings(self):
pythonpathlist = []

if not self.args.nopy:
if self.args.testpylib:
if self.testpythonpath:
pythonpathlist.append(self.testpythonpath)
else:
logger.error(
"Test python path asked for, but pythonpathtest in yml is %s",
self.testpythonpath,
)
if self.pythonpath:
pythonpathlist.append(self.pythonpath)
if self.args.incsyspy:
Expand Down Expand Up @@ -683,6 +709,9 @@ def _collect_env_settings(self):
if self.setdpiscaling:
rms_exec_env["QT_SCALE_FACTOR"] = self.setdpiscaling

if self.aps_toolbox_path:
rms_exec_env["APS_TOOLBOX_PATH"] = self.aps_toolbox_path

for key, value in rms_exec_env.items():
logger.debug("rms_exec_env... %s: %s", key, value)

Expand Down Expand Up @@ -726,6 +755,7 @@ def showinfo(self):
print("{0:30s}: {1}".format(f"Pythonpath added as {order}**", self.pythonpath))
print("{0:30s}: {1}".format("RMS plugins path", self.pluginspath))
print("{0:30s}: {1}".format("TCL/TK path", self.tcltkpath))
print("{0:30s}: {1}".format("APS TOOLBOX PATH", self.aps_toolbox_path))
print("{0:30s}: {1}".format("RMS DPI scaling", self.setdpiscaling))
print("{0:30s}: {1}".format("RMS executable", self.exe))
print("=" * shutil.get_terminal_size((132, 20)).columns)
Expand Down

0 comments on commit 90e4efc

Please sign in to comment.