I'm proud to announce the new release of iris-pex-embedded-python (v2.3.1) with a new command line interface.
This command line is called iop
for Interoperability On Python
.
First I would like to present in few words the project the main changes since the version 1.
A breif history of the project
Version 1.0 was a proof of concept to show how the interoperability framework of IRIS can be used with a python first approach while remaining compatible with any existing ObjectScript code.
What does it mean? It means that any python developer can use the IRIS interoperability framework without any knowledge of ObjectScript.
Example :
from grongier.pex import BusinessOperation
class MyBusinessOperation(BusinessOperation):
def on_message(self, request):
self.log.info("Received request")
Great, isn't it?
With version 1.1, I added the possibilty to register those python classes to IRIS with an helper function.
from grongier.pex import Utils
Utils.register_file("/src/MyBusinessOperation.py")
Version 2.0 was a major release because now you can install this project with pip.
pip install iris-pex-embedded-python
What's new in version 2.3.1
Version 2.3.1 is a major release because it introduces a new command line interface.
This command line interface can be used with this python project based on this module or maybe with projects that doesn't use this module.
Let me introduce it and explain why it can be used in non python projects.
The command line interface
The command line is part of this project, to install it you just have to install this project with pip.
pip install iris-pex-embedded-python
Then you can use the command line iop
to start the interoperability framework.
iop
output :
usage: iop [-h] [-d DEFAULT] [-l] [-s START] [-k] [-S] [-r] [-M MIGRATE] [-e EXPORT] [-x] [-v] [-L]
optional arguments:
-h, --help display help and default production name
-d DEFAULT, --default DEFAULT
set the default production
-l, --lists list productions
-s START, --start START
start a production
-k, --kill kill a production (force stop)
-S, --stop stop a production
-r, --restart restart a production
-M MIGRATE, --migrate MIGRATE
migrate production and classes with settings file
-e EXPORT, --export EXPORT
export a production
-x, --status status a production
-v, --version display version
-L, --log display log
default production: UnitTest.Production
Let's go in few examples.
help
The help command display the help and the default production name.
iop -h
output :
usage: python3 -m grongier.pex [-h] [-d DEFAULT] [-l] [-s START] [-k] [-S] [-r] [-M MIGRATE] [-e EXPORT] [-x] [-v] [-L]
...
default production: PEX.Production
default
The default command set the default production.
With no argument, it display the default production.
iop -d
output :
default production: PEX.Production
With an argument, it set the default production.
iop -d PEX.Production
lists
The lists command list productions.
iop -l
output :
{
"PEX.Production": {
"Status": "Stopped",
"LastStartTime": "2023-05-31 11:13:51.000",
"LastStopTime": "2023-05-31 11:13:54.153",
"AutoStart": 0
}
}
start
The start command start a production.
To exit the command, you have to press CTRL+C.
iop -s PEX.Production
If no argument is given, the start command start the default production.
iop -s
output :
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting production
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.FileOperation
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.EmailOperation
...
kill
The kill command kill a production (force stop).
Kill command is the same as stop command but with a force stop.
Kill command doesn't take an argument because only one production can be running.
iop -k
stop
The stop command stop a production.
Stop command doesn't take an argument because only one production can be running.
iop -S
restart
The restart command restart a production.
Restart command doesn't take an argument because only one production can be running.
iop -r
migrate
The migrate command migrate a production and classes with settings file.
Migrate command must take the absolute path of the settings file.
Settings file must be in the same folder as the python code.
iop -M /tmp/settings.py
export
The export command export a production.
If no argument is given, the export command export the default production.
iop -e
If an argument is given, the export command export the production given in argument.
iop -e PEX.Production
output :
{
"Production": {
"@Name": "PEX.Production",
"@TestingEnabled": "true",
"@LogGeneralTraceEvents": "false",
"Description": "",
"ActorPoolSize": "2",
"Item": [
{
"@Name": "Python.FileOperation",
"@Category": "",
"@ClassName": "Python.FileOperation",
"@PoolSize": "1",
"@Enabled": "true",
"@Foreground": "false",
"@Comment": "",
"@LogTraceEvents": "true",
"@Schedule": "",
"Setting": [
{
"@Target": "Adapter",
"@Name": "Charset",
"#text": "utf-8"
},
{
"@Target": "Adapter",
"@Name": "FilePath",
"#text": "/irisdev/app/output/"
},
{
"@Target": "Host",
"@Name": "%settings",
"#text": "path=/irisdev/app/output/"
}
]
}
]
}
}
status
The status command status a production.
Status command doesn't take an argument because only one production can be running.
iop -x
output :
{
"Production": "PEX.Production",
"Status": "stopped"
}
Status can be :
- stopped
- running
- suspended
- troubled
version
The version command display the version.
iop -v
output :
2.3.0
log
The log command display the log.
To exit the command, you have to press CTRL+C.
iop -L
output :
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting production
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.FileOperation
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.EmailOperation
...
Can it be used outside of iris-pex-embedded-python project ?
That's your choice.
But, before you leave, let me tell why I think it can be used outside of iris-pex-embedded-python project.
First, because it can interact with production without the need to use an iris shell. That means it's easier to use in a script.
Secoud, because settings.py can be used to import production and classes with environment variables.
Here is an example of settings.py :
import os
PRODUCTIONS = [
{
'UnitTest.Production': {
"Item": [
{
"@Name": "Python.FileOperation",
"@ClassName": "Python.FileOperation",
"Setting": {
"@Target": "Host",
"@Name": "%settings",
"#text": os.environ['SETTINGS']
}
}
]
}
}
]
Pay attention to #text value. It's an environment variable. Neat, isn't it ?
Do you see yourself using this command line tool, worth it to keep developing it ?
Thanks for reading and your feedbacks are welcome.
Great stuff, @Guillaume Rongier !
A few questions:
iop -x
-x is for status? Why not -s?
Also,
iop -e PEX.Production
is for export? Can then this export be imported?
Hi Evgeny,
Thanks for your feedback.
The
-x
option is forstatus
, because-s
is already used tostart
a production.The
-e
option is forexport
, and the export can be imported with the-m
option.-m
option stand formigrate
, because I took the inspiration from the migrate command form django.I hope it's more clear now.
But if you think,
-i
forimport
and-e
forexport
is more clear, I can change it.Same for
-s
and-x
. What do you think can be short forstatus
?Hi @Guillaume Rongier !
Well explained. I just hope the UI be more intuitive - this pays a lot in the future for the better adoption of the tool.
I understand that there are not many letters in the alphabet and it can go to the end quickly. In this case I'd keep with what you think on one-letters and also introduce synonyms of fulltext with double --.e.g.
--import for import,
--export for export and
--status for status.
This could help with readability in long scripts with cli or with documentation.
Hi @Guillaume Rongier
I am getting the following error while calling
iop
on WindowsD:\temp\iop>iop -start
WARNING:root:Error importing pythonint312: irisinit failed
WARNING:root:Embedded Python not available
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "D:\temp\iop\.venv\Scripts\iop.exe\__main__.py", line 4, in <module>
File "d:\temp\iop\.venv\Lib\site-packages\iop\__init__.py", line 1, in <module>
from iop._business_operation import _BusinessOperation
File "d:\temp\iop\.venv\Lib\site-packages\iop\_business_operation.py", line 3, in <module>
from iop._business_host import _BusinessHost
File "d:\temp\iop\.venv\Lib\site-packages\iop\_business_host.py", line 8, in <module>
from iop._decorators import input_serializer_param, output_deserializer
File "d:\temp\iop\.venv\Lib\site-packages\iop\_decorators.py", line 3, in <module>
from iop._dispatch import dispatch_deserializer, dispatch_serializer
File "d:\temp\iop\.venv\Lib\site-packages\iop\_dispatch.py", line 15, in <module>
def serialize_pickle_message(message: Any) -> iris.cls:
^^^^^^^^
AttributeError: module 'iris' has no attribute 'cls'
Which version of IRIS do you use? Try on the latest preview?
IRIS for Windows (x86-64) 2024.2 (Build 247U) Tue Jul 16 2024 09:57:03 EDT [Health:7.2.0-3.m2024.1.2]
hi @Muhammad Waseem
I bet the issue is due to a conflict with iris official driver.
Embedded python and iris official driver share the same module name iris.
But the official driver obviously doesn't include the cls attribute.
To solve this issue please for install this module :
This module is an helper to play with embedded python with a native python interpreter not only irispython.
Hi @Guillaume Rongier
.png)
Still same issue
in your case you have to. force-reinstall it :
I found that the issue was actually related to the Python installation itself. After resolving the installation problem, the application is now working fine.
Thank you all for your help and support
if you happened to install the official python driver, it could mess here.