Skip to content

Commit 8560ba2

Browse files
committed
Refactor Python settings management in Utils and Common classes for improved clarity and functionality
1 parent 737d2a2 commit 8560ba2

File tree

3 files changed

+38
-50
lines changed

3 files changed

+38
-50
lines changed

src/iop/_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def get_python_settings() -> Tuple[str,str,str]:
8888
pythonpath = _Utils._get_python_path()
8989
pythonversion = sys.version[:4]
9090

91+
if not pythonlib:
92+
pythonlib = ""
93+
9194
return pythonlib, pythonpath, pythonversion
9295

9396
@staticmethod

src/iop/cls/IOP/Common.cls

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Method OnInit() As %Status
8686
set tSC = $$$OK
8787
try {
8888
LOCK +^PythonSettings:5
89-
do ..SetPythonSettings(..%PythonRuntimeLibrary, ..%PythonPath, ..%PythonRuntimeLibraryVersion)
89+
do ##class(IOP.Utils).SetPythonSettings(..%PythonRuntimeLibrary, ..%PythonPath, ..%PythonRuntimeLibraryVersion)
9090

9191
do ..DisplayPythonVersion()
9292

@@ -105,37 +105,6 @@ Method OnInit() As %Status
105105
quit tSC
106106
}
107107

108-
ClassMethod SetPythonSettings(
109-
pPythonLib,
110-
pPythonPath,
111-
pPythonVersion)
112-
{
113-
set currentNS = $namespace
114-
set $NAMESPACE = "%SYS"
115-
try {
116-
// Get Config
117-
$$$ThrowOnError(##Class(Config.config).Get(.Properties))
118-
// Set the Python interpreter path
119-
if ..%PythonInterpreterPath'="" {
120-
set Properties("PythonPath") = pPythonPath
121-
}
122-
123-
// Set the Python runtime library
124-
if ..%PythonRuntimeLibrary'="" {
125-
set Properties("PythonRuntimeLibrary") = pPythonLib
126-
}
127-
128-
// Set the Python runtime library version
129-
if ..%PythonRuntimeLibraryVersion'="" {
130-
set Properties("PythonRuntimeLibraryVersion") = pPythonVersion
131-
}
132-
$$$ThrowOnError(##Class(Config.config).Modify(.Properties))
133-
} catch ex {
134-
135-
}
136-
set $NAMESPACE = currentNS
137-
}
138-
139108
Method DisplayPythonVersion()
140109
{
141110
set sys = ##class(%SYS.Python).Import("sys")

src/iop/cls/IOP/Utils.cls

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,6 @@ ClassMethod dispatchRegisterComponent(
2323
return tSc
2424
}
2525

26-
ClassMethod SetPythonSettings(
27-
pPythonLib As %String = "",
28-
pPythonPath As %String = "",
29-
pPythonVersion As %String = "") As %Status
30-
{
31-
#dim tSC As %Status = $$$OK
32-
#dim ex As %Exception.AbstractException
33-
34-
Try {
35-
Do ##class(IOP.Common).SetPythonSettings(pPythonLib, pPythonPath, pPythonVersion)
36-
} Catch ex {
37-
Set tSC = ex.AsStatus()
38-
}
39-
40-
Quit tSC
41-
}
42-
4326
/// "bo","Duplex","/irisdev/app/src/python/demo/duplex/",1,"Duplex.Duplex"
4427
ClassMethod RegisterComponent(
4528
pModule As %String,
@@ -64,7 +47,7 @@ ClassMethod RegisterComponent(
6447
Try {
6548
LOCK +^PythonSettings:10
6649
// Set the Python settings
67-
$$$ThrowOnError(##class(IOP.Utils).SetPythonSettings(pPythonLib, pPythonPath, pPythonVersion))
50+
do ..SetPythonSettings(pPythonLib, pPythonPath, pPythonVersion)
6851

6952
$$$ThrowOnError(..GetRemoteClassInfo(pRemoteClassname,pModule,pCLASSPATHS,pFullpath,.tClassDetails,.tRemoteSettings))
7053

@@ -478,4 +461,37 @@ ClassMethod dispatchTestComponent(
478461
Quit tOutput
479462
}
480463

464+
ClassMethod SetPythonSettings(
465+
pPythonLib,
466+
pPythonPath,
467+
pPythonVersion)
468+
{
469+
set currentNS = $namespace
470+
set $NAMESPACE = "%SYS"
471+
try {
472+
// Get Config
473+
$$$ThrowOnError(##Class(Config.config).Get(.Properties))
474+
// Set the Python interpreter path
475+
if pPythonPath'="" {
476+
set Properties("PythonPath") = pPythonPath
477+
}
478+
479+
// Set the Python runtime library
480+
if pPythonLib'="" {
481+
set Properties("PythonRuntimeLibrary") = pPythonLib
482+
}
483+
484+
// Set the Python runtime library version
485+
if pPythonVersion'="" {
486+
set Properties("PythonRuntimeLibraryVersion") = pPythonVersion
487+
}
488+
$$$ThrowOnError(##Class(Config.config).Modify(.Properties))
489+
} catch ex {
490+
set msg = $System.Status.GetOneStatusText(ex.AsStatus(),1)
491+
set ^PLOG=msg
492+
}
493+
494+
set $NAMESPACE = currentNS
495+
}
496+
481497
}

0 commit comments

Comments
 (0)