Skip to content

Commit 3b694a8

Browse files
committed
Refactor WrapperDemo method to improve module import path and capture function result; update documentation with usage remarks and example
1 parent 6d79858 commit 3b694a8

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

demo/iris/PEX/NonProduction.cls

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ ClassMethod WrapperDemo() As %Status
55
{
66

77
// Import the module
8-
set tModule = ##class(IOP.Wrapper).Import("my_script", "/Users/grongier/git/interoperability-embedded-python/demo/python/non_production/", 54132)
8+
set tModule = ##class(IOP.Wrapper).Import("my_script", "/irisdev/app/demo/python/non_production/", 54132)
99

1010
// Call the function
11-
do tModule.main()
11+
set result = tModule.main()
12+
13+
// Print the result
14+
write result
1215
}
1316

1417
}

demo/python/non_production/my_script.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ def main():
77
# Print the value of the environment variable
88
print(f'MY_ENV_VAR: {my_env_var}')
99

10+
return "Script executed successfully!"
11+
1012

1113
if __name__ == "__main__":
1214
main()

docs/wrapper.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def main():
2323
# Print the value of the environment variable
2424
print(f'MY_ENV_VAR: {my_env_var}')
2525

26+
return "Hello from my_script!"
27+
2628

2729
if __name__ == "__main__":
2830
main()
@@ -40,3 +42,34 @@ Set myModule = ##class(IoP.Wrapper).Import(pythonModule, pythonPath, debugPort)
4042
do myModule.main()
4143
```
4244

45+
## Remarks
46+
47+
By the nature of python, to test it effectively, you must start a new job in IRIS each time you modify the Python code. This is because the Python interpreter does not automatically reload modules when they are changed, unlike some other languages (eg: objectscript).
48+
49+
For example, given the above code
50+
51+
```objectscript
52+
Class Demo.PEX.NonProduction Extends %RegisteredObject
53+
{
54+
55+
ClassMethod WrapperDemo() As %Status
56+
{
57+
58+
// Import the module
59+
set tModule = ##class(IOP.Wrapper).Import("my_script", "/path/to/your/python/scripts", 54132)
60+
61+
// Call the function
62+
set result = tModule.main()
63+
64+
// Print the result
65+
write result
66+
}
67+
68+
}
69+
```
70+
71+
You can run this objectscript code as :
72+
73+
```bash
74+
iris session iris -U%IRISAPP '##class(Demo.PEX.NonProduction).WrapperDemo()'
75+
```

0 commit comments

Comments
 (0)