infor.com
concierge
infor u
developer portal
documentation central
customer center
Posts
Categories
Groups
ERPs
CSD
FSM/HRT
LN
M3
Syteline/ CSI
Hubs
Developer
Healthcare
Hospitality
Public Sector
Onboarding
Release Center
CloudSuites
Aerospace & Defense (LN)
Automotive (LN)
Chemicals (M3)
Corporate (FSM/HRT)
Distribution (Sx.e/CSD)
Distribution Enterprise (M3)
Engineering & Construction (LN)
Fashion (M3)
Food & Beverage (M3)
Healthcare (FSM/HRT)
Industrial (Syteline/CSI)
Industrial Enterprise (LN)
Manufacturing (M3)
Public Sector (FSM/HRT)
Solutions
Supply Chain Management (SCM)
Human Capital Management (HCM)
Events
Groups
User Groups
Your Groups
About
Email Community Support
Infor News
Migrated Forums
Home
Clovertech
Clovertech Archive
Cloverleaf
Python Libraries
Jon Souders
Curious if anyone knows...
I'm currently tinkering with the contrib Python box on CL 6.2.3 and am wondering if it's possible to install libraries to function with hcipython. I installed jip from pip, but that didn't seem to help.
Anyone else experiment with this at all?
Find more posts tagged with
Clovertech
Comments
lonnie-davis
This is an old question, but I have been playing with Python support in Cloverleaf 19.1.
Here is what I did to get a 3rd party Python library called 'python-hl7' to work from hcipython. I will create a new thread for an issue I am having running Python scripts as a UPoC. More on that later.
According to the 19.1 documentation, the Python scripts need to be put in the $HCISITEDIR/scripts directory as Cloverleaf searches this directory and subdirectories for Python and Javascript files. This is different from how the site in the JavascriptAndPython.box file works where Python scripts are put in the $HCISITEDIR/pythonmodules directory.
I downloaded the python-hl7 library from the developer's GitHub page at
https://github.com/johnpaulett/python-hl7
then copied the directory containing the Python scripts, called 'hl7', to the $HCISITEDIR/scripts/ directory.
From there, I could load up the hcipython interpreter, import the python-hl7 library, and start using all of the classes according to the developer's instructions. I couldn't get any Python package manager to work such as pip or easy_install. The generic Jython documentation doesn't seem to work with the Cloverleaf implementation so it looks like the only way to use a Python library is to download the Python source code and copy it to the $HCISITEDIR/scripts/directory.
It all breaks down for me when I use the Cloverleaf 19.1 documentation to run a Python script as a TPS UPoC though. At least it works from hcipython so that is the first step.
If there have been any new developments on using Python libraries in Cloverleaf since the original question was asked, please let me know.
Jon Souders
Clever!
I never followed up on this since there didn't seem to be any interest, but I eventually did find a way to install libraries from pip.
It required downloading an updated version of the Jython Standalone .jar file that is in $HCIROOT/lib/java - the version that already exists in that directory wouldn't allow the ensurepip command to work for whatever reason, but installing the libraries in the updated version is backwards compatible for the older version - and running the following commands:
$ java -jar jython-standalone-2.7.1.jar -m ensurepip
$ java -jar jython-standalone-2.7.1.jar -m pip install --upgrade pip
$ java -jar jython-standalone-2.7.1.jar -m pip install hl7
$ java -jar jython-standalone-2.7.1.jar -m pip install zxJDBC
After doing this, I could write my scripts with any libraries I had installed from pip and set the threads to run with the Script TPS module.
Rob Abbott
Great input guys!
Jonathan - will investigate upgrading Jython for the next release.
Lonnie - if you're having trouble running python UPoC and the documentation is incorrect please open a support case so we can help you and get anything fixed that needs fixing.
lonnie-davis
Jonathan,
Thanks for your input. After following your instructions, I was able to use easy_install but I can't get pip to work. I think I just need to read more about pip to get it to work though. I'm new to the whole Python world and the Jython piece is raising the learning curve since I know nothing about Java.
Using easy_install though, I was able to reinstall the python-hl7 package...
java -jar jython-standalone-2.7.1.jar -m easy_install hl7
Then I deleted that 'hl7' directory from my 'pythonmodules' directory from the JavaScript/Python BOX and my test script still worked. I switched back to using the BOXed site for testing because using the 'scripts' directory just didn't work right for me.
I see that Python packages are installed to $HCIROOT/lib/java/Lib/site-packages
It is worth mentioning I'm doing this testing on a Windows machine running Cloverleaf 19.1. All of my real work is done on AIX boxes running Cloverleaf 6.2.2.
Can you elaborate on how you are getting your script TPS modules to work? Are you able to use user arguments in the TPS Properties 'args' box?
I can't seem to get the Cloverleaf documentation method of using the ScriptTPS Java class plus the {LANG python}{FILE <file_name>} {FUNC <func_name>} args to work properly. Why does it ask me for a func name?
But I can use the method used in the BOX example of using the JythonTPSBeta Java class with the args {MODULE <file_name>}
Jon Souders
This is how I have my TPS set up with my .py files in$HCIROOT/scripts - which I'm currently just running against some sample files with success (still need to get the team on board with using Python since no one else is familiar):
Java Class: ScriptTPS
Args: {LANG python} {FILE Tps_py_template.py} {FUNC __MODULE_NAME__}
ScriptTPS being the Java class Infor allows these to run through, {LANG python} being the language I want to use (as opposed to JavaScript), {FILE Tps_py_template.py} being the file containing my relevant functions, and {FUNC __MODULE_NAME__} being the Python function I am calling from my .py file. Think of this like your Tcl procs, where you have a file that can contain many procs, and your Tcl_index contains a list of your procs which you can then select from the TPS properties window - with Tcl it's inherently in the application, but for Python/JavaScript you have to specify the arguments for those parameters since they are not built in like the Tcl components.
TL;DR - LANG tells Cloverleaf what language to use, FILE specifies the file in which to look for functions, FUNC specifies which function in the FILE to use.
lonnie-davis
Success! I got a test Python script to work correctly in a site other than the BOXed JavaScript/Python site using the 'scripts' directory and your instructions. I'm not sure what I was doing before to get the errors.
One more question for you. How do you supply the userArgs to the Java class 'ScriptTPS'?
Jon Souders
Awesome! There are some template outlines in $HCIROOT/scripts/templates that give you some general starting places on the different types of functions you might use. The one for TPS includes some function parameters, one of which is 'userArgs' which you can then call print(userArgs), or however you plan to use them, within your function. Below is my general understanding of ways to use (most of) the parameters:
def __MODULE_NAME__(cloverEnv, context, mode, msg, userArgs, dl):
if mode == 'run':
# Obtain thread name
hciConnName = cloverEnv.getThreadName()
# Print user arguments
uargs = userArgs
# Obtain content of message handle
data = msg.getContent())
# Commit any changes you've made to your message content
msg.setContent(str(data))
# Add message to disposition list
dl.add(CONTINUE, msg)
lonnie-davis
Yeah, I don't know what I was doing before, but it works great now. What I mean with the userArgs was how to populate userArgs from the Java args in the TPS properties where you set...
Java Class: ScriptTPS
Args: {LANG python} {FILE Tps_py_template.py} {FUNC __MODULE_NAME__}
There has got to be an ARGS parameter or something that tells the ScriptTPS Java class to populate the userArgs object/ parameter so it can be used from within the Python script.
Jon Souders
You can do that like so (just an example):
NetConfig
Java Class: ScriptTPS
Args: {LANG python} {FILE Tps_py_template.py} {FUNC __MODULE_NAME__} {userArgs TESTING}
Python Script
def __MODULE_NAME__(cloverEnv, context, mode, msg, userArgs, dl):
# mode can be "run", "start", "shutdown", or "time"
#hciConnName = cloverEnv.getThreadName()
import hl7
lang = userArgs.get('LANG')
file = userArgs.get('FILE')
func - userArgs.get('FUNC')
uargs = userArgs.get('userArgs')
print(lang)
print(uargs)
Log Output
[prod:prod:INFO/0: python_in:05/08/2020 13:34:22] Applying EO config: ''
python
Tps_py_template.py
__MODULE_NAME__
TESTING
[cmd :cmd :INFO/0: python_cmd:05/08/2020 13:34:26] Receiving a command
[cmd :cmd :INFO/0: python_cmd:05/08/2020 13:34:26] Received command: 'python_xlate xrel_post'
[cmd :cmd :INFO/0: python_xlate:05/08/2020 13:34:26] Doing 'xrel_post' command with args '<none>'
Jon Souders
Appreciate that, Rob!
Rob Abbott
We are actually investigating moving to JEP (Java Embedded Python) which supports Python 3 (yay), if there are no major issues we might be able to squeeze that into 20.1.
We will also plan to upgrade Jython in any future patches to 19.1 or 6.2.
Jon Souders
Rob:
Should I open a case on the following issues?
For Javascript, I'm not sure how to debug - I've tried console.log(<variable>), but it errors out my scripts in testing so I can't read any of my variables from the log file.
For testing tool, I try to pass arguments (JS and PY) the same way I do in the NetConfig, but I never get any output to the screen.
I'll open a case if necessary, but thought I'd ask if that was worth my time first.
Thanks.