Skip to content

Commit 5a20fc7

Browse files
committed
Refactor SetPythonPath method to streamline path checking and insertion logic
1 parent 6107513 commit 5a20fc7

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

src/iop/cls/IOP/Common.cls

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,12 @@ ClassMethod SetPythonPath(pClasspaths)
147147

148148
// Add the classpaths to the Python sys.path only if they are not already present
149149
// Check if the path is already in sys.path
150-
set found = 0
151-
for j=1:1:sys.path."__len__"() {
152-
if sys.path."__getitem__"(j-1) = pClasspaths {
153-
set found = 1
154-
quit
155-
}
156-
}
157-
if found = 0 {
158-
// If not found, add to sys.path
159-
do sys.path."append"(pClasspaths)
150+
if (sys.path."__len__"() > 0) && (sys.path."__getitem__"(0) = pClasspaths) { Quit }
151+
152+
while (sys.path."__contains__"(pClasspaths)) {
153+
do sys.path.remove(pClasspaths)
160154
}
155+
do sys.path.insert(0, pClasspaths)
161156
}
162157

163158
Method Connect() As %Status

0 commit comments

Comments
 (0)