Skip to content

Commit 0e71f56

Browse files
committed
Added Embedded python changes
1 parent 7293a7a commit 0e71f56

File tree

14 files changed

+334
-13
lines changed

14 files changed

+334
-13
lines changed

.devcontainer/devcontainer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.224.2/containers/docker-existing-docker-compose
3+
{
4+
"name": "iris-embedded-python-template devcontainer",
5+
6+
// Use the same recipe as creates the container we use when working locally.
7+
"dockerComposeFile": [
8+
"../docker-compose.yml"
9+
],
10+
11+
"service": "iris",
12+
13+
"workspaceFolder": "/irisrun/repo",
14+
15+
// This provides the elements of the connection object which require different values when connecting to the workspace within the container,
16+
// versus those in .vscode/settings.json which apply when operating locally on the workspace files.
17+
// We define and use a `server` so that (a) a user-level `objectscript.conn.server` properly doesn't override us, and (b) so InterSystems
18+
// Server Manager can also be used.
19+
"settings": {
20+
"objectscript.conn" :{
21+
"server": "devcontainer",
22+
"active": true,
23+
},
24+
"intersystems.servers": {
25+
"devcontainer": {
26+
"username": "SuperUser",
27+
"password": "SYS",
28+
"webServer": {
29+
"scheme": "http",
30+
"host": "127.0.0.1",
31+
"port": 52773
32+
},
33+
},
34+
},
35+
"python.defaultInterpreterPath":"/usr/irissys/bin/irispython"
36+
},
37+
38+
// Add the IDs of extensions we want installed when the container is created.
39+
// Currently (March 2022) `intersystems.language-server` fails to run within the container (alpine platform).
40+
// Issue is probably https://github.com/intersystems/language-server/issues/185 and/or https://github.com/intersystems/language-server/issues/32
41+
// Crash gets reported to the user, after which `intersystems-community.vscode-objectscript` falls back to
42+
// using its TextMate grammar for code coloring.
43+
"extensions": [
44+
"ms-python.python",
45+
"ms-python.vscode-pylance",
46+
"intersystems-community.vscode-objectscript",
47+
"intersystems.language-server",
48+
"intersystems-community.servermanager",
49+
"ms-vscode.docker"
50+
],
51+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: versionbump
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
pull_request:
9+
branches:
10+
- master
11+
- main
12+
release:
13+
types:
14+
- released
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Bump version
22+
run: |
23+
git config --global user.name 'ProjectBot'
24+
git config --global user.email '[email protected]'
25+
VERSION=$(sed -n '0,/.*<Version>\(.*\)<\/Version>.*/s//\1/p' module.xml)
26+
VERSION=`echo $VERSION | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.`
27+
sed -i "0,/<Version>\(.*\)<\/Version>/s//<Version>$VERSION<\/Version>/" module.xml
28+
git add module.xml
29+
git commit -m 'auto bump version'
30+
git push

.github/workflows/github-registry.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build and publish a Docker image to ghcr.io
2+
on:
3+
4+
# publish on pushes to the main branch (image tagged as "latest")
5+
# image name: will be: ghcr.io/${{ github.repository }}:latest
6+
# e.g.: ghcr.io/intersystems-community/intersystems-iris-dev-template:latest
7+
push:
8+
branches:
9+
- master
10+
11+
jobs:
12+
docker_publish:
13+
runs-on: "ubuntu-20.04"
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
# https://github.com/marketplace/actions/push-to-ghcr
19+
- name: Build and publish a Docker image for ${{ github.repository }}
20+
uses: macbre/push-to-ghcr@master
21+
with:
22+
image_name: ${{ github.repository }}
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
# optionally push to the Docker Hub (docker.io)
25+
# docker_io_token: ${{ secrets.DOCKER_IO_ACCESS_TOKEN }} # see https://hub.docker.com/settings/security

.github/workflows/runtests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: unittest
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
pull_request:
9+
branches:
10+
- master
11+
- main
12+
release:
13+
types:
14+
- released
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Build and Test
22+
uses: docker/build-push-action@v2
23+
with:
24+
context: .
25+
push: false
26+
load: true
27+
tags: ${{ github.repository }}:${{ github.sha }}
28+
build-args: TESTS=1

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## iris-embedded-python-template
22
This is a template to work with Embedded Python in InterSystems IRIS
3+
It demonstrates how to call python libs from ObjectScript in dc.python.test class.
4+
And it demonstrates how to deal with IRIS from python scripts - python/irisapp.py
35

46
## Prerequisites
57
Make sure you have [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and [Docker desktop](https://www.docker.com/products/docker-desktop) installed.
@@ -33,6 +35,7 @@ $ docker-compose up -d
3335

3436
## How to work with it
3537

38+
### Working with Python libs from ObjectScript
3639
Open IRIS terminal:
3740

3841
```
@@ -60,4 +63,16 @@ USER>d ##class(dc.python.test).TitanicMeanAge()
6063
mean age=29.69911764705882
6164
6265
```
66+
### Working with IRIS from Embedded Python
67+
Open VSCode in Devcontainer - this is the bell(notifications) button in the left bottom corner, where you will see the suggestion to open VSCOde in DevContainer mode.
68+
Follow it - it will let to execute Embedded Python scripts vs IRIS and develop it at the same time.
69+
70+
Once devcontainer is opened go to /python/irisapp.py and run it, either with Run button in the top right corner, or in terminal via:
71+
```
72+
irispython /python/irisapp.py
73+
```
74+
The script contains different samples of working with IRIS from python and goes through it.
75+
76+
Feel free to use the template for your own development just by adding new py files.
77+
6378

dev.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# useful commands
22
## clean up docker
3+
use it when docker says "There is no space left on device". It will remove built but not used images and other temporary files.
34
```
45
docker system prune -f
56
```
67

8+
```
9+
docker rm -f $(docker ps -qa)
10+
```
11+
712
## build container with no cache
813
```
9-
docker-compose build --no-cache
14+
docker-compose build --no-cache --progress=plain
1015
```
1116
## start iris container
1217
```
@@ -18,6 +23,17 @@ docker-compose up -d
1823
docker-compose exec iris iris session iris -U IRISAPP
1924
```
2025

26+
## map iris key from Mac home directory to IRIS in container
27+
- ~/iris.key:/usr/irissys/mgr/iris.key
28+
29+
## install git in the docker image
30+
## add git in dockerfile
31+
USER root
32+
RUN apt update && apt-get -y install git
33+
34+
USER ${ISC_PACKAGE_MGRUSER}
35+
36+
2137
## install docker-compose
2238
```
2339
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
@@ -56,6 +72,22 @@ zn "%SYS" \
5672
write "Web application "_webName_" has been created!",!
5773
```
5874

59-
zw ##class(community.csvgen).GenerateFromURL("https://github.com/h2oai/h2o-tutorials/raw/master/h2o-world-2017/automl/data/product_backorders.csv")
6075

61-
d ##class(dc.python.test).TitanicMeanAge()
76+
77+
```
78+
do $SYSTEM.OBJ.ImportDir("/opt/irisbuild/src",, "ck")
79+
```
80+
81+
82+
### run tests described in the module
83+
84+
IRISAPP>zpm
85+
IRISAPP:zpm>load /irisrun/repo
86+
IRISAPP:zpm>test package-name
87+
88+
### install ZPM with one line
89+
// Install ZPM
90+
set $namespace="%SYS", name="DefaultSSL" do:'##class(Security.SSLConfigs).Exists(name) ##class(Security.SSLConfigs).Create(name) set url="https://pm.community.intersystems.com/packages/zpm/latest/installer" Do ##class(%Net.URLParser).Parse(url,.comp) set ht = ##class(%Net.HttpRequest).%New(), ht.Server = comp("host"), ht.Port = 443, ht.Https=1, ht.SSLConfiguration=name, st=ht.Get(comp("path")) quit:'st $System.Status.GetErrorText(st) set xml=##class(%File).TempFilename("xml"), tFile = ##class(%Stream.FileBinary).%New(), tFile.Filename = xml do tFile.CopyFromAndSave(ht.HttpResponse.Data) do ht.%Close(), $system.OBJ.Load(xml,"ck") do ##class(%File).Delete(xml)
91+
92+
93+
do ##class(%SYS.Python).Shell()

iris.script

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
;do $System.OBJ.LoadDir("/opt/irisbuild/src","ck",,1)
1+
;do $System.OBJ.LoadDir("/opt/irisbuild/src","ck",,1)
22

3-
zn "%SYS"
4-
Do ##class(Security.Users).UnExpireUserPasswords("*")
3+
zn "%SYS"
4+
Do ##class(Security.Users).UnExpireUserPasswords("*")
55

6-
zn "USER"
7-
zpm "load /opt/irisbuild/ -v":1:1
8-
halt
6+
; enabling callin for Embedded Python
7+
do ##class(Security.Services).Get("%Service_CallIn",.prop)
8+
set prop("Enabled")=1
9+
set prop("AutheEnabled")=48
10+
do ##class(Security.Services).Modify("%Service_CallIn",.prop)
11+
12+
zn "USER"
13+
zpm "load /home/irisowner/irisbuild/ -v":1:1
14+
halt

module.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<Packaging>module</Packaging>
99
<SourcesRoot>src</SourcesRoot>
1010
<Resource Name="dc.python.PKG"/>
11-
<FileCopy Name="python/" Target="${mgrdir}python/"/>
12-
<FileCopy Name="data/" Target="${mgrdir}data/"/>
11+
<FileCopy Name="python/" Target="${libdir}python/"/>
12+
<FileCopy Name="data/" Target="${libdir}data/"/>
1313
</Module>
1414
</Document>
1515
</Export>

python/irisapp.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Script to test IRIS Embedded Python calls.
2+
# Embedded python works in a shared memory with IRIS.
3+
# Thus direct calls to IRIS classmethods, globals and tables are available via iris lib.
4+
5+
print('Hello World')
6+
7+
# Run IRIS Class Method
8+
import iris
9+
10+
print("Method call:")
11+
print(iris.cls('dc.python.ObjectScript').Test())
12+
13+
# function to return IRIS version
14+
def iris_version():
15+
return iris.system.Version.GetVersion()
16+
17+
# testing the function
18+
print("Iris Version:")
19+
print(iris_version())
20+
21+
# function to create record in IRIS
22+
def create_rec(var):
23+
obj=iris.cls('dc.python.PersistentClass')._New()
24+
obj.Test=var
25+
obj._Save()
26+
id=obj._Id()
27+
return id
28+
29+
# test record creation
30+
from datetime import datetime
31+
now=str(datetime.now())
32+
print("Creating new record in dc.python.PersistentClass")
33+
print(create_rec(now))
34+
35+
def print_rec(cls_name,id):
36+
obj=iris.cls(cls_name)._OpenId(id)
37+
print(iris.cls("%SYSTEM.OBJ").Dump(obj))
38+
39+
print("Printing one IRIS Object Dump:")
40+
print_rec('dc.python.PersistentClass',1)
41+
42+
## run SQL and print data
43+
def run_sql(query):
44+
rs=iris.sql.exec(query)
45+
for idx, row in enumerate(rs):
46+
print(f"[{idx}]: {row}")
47+
48+
query="Select * from dc_python.PersistentClass"
49+
print("Running SQL query "+query)
50+
run_sql(query)
51+
52+
def print_global(glname):
53+
gl=iris.gref(glname)
54+
for (key,value) in gl.query([]):
55+
print(f"key={key}: {value}")
56+
57+
58+
glname=iris.cls("%Dictionary.CompiledStorage")._OpenId("dc.python.PersistentClass||Default").DataLocation
59+
print("Printing the whole global of the persistence storage for the class dc.python.PersistentClass:"+glname)
60+
print_global(glname)
61+
62+
def global_order_demo():
63+
gl=iris.gref("^EPython.Order")
64+
# set three indexes in unsorted order
65+
list=["John","Jim","James"]
66+
for key in list:
67+
gl.set([key],"")
68+
# print global indexes traversing via order function. Notice that indexes are sorted automatically
69+
key=""
70+
while True:
71+
key=gl.order([key])
72+
if key==None:
73+
break
74+
print(key)
75+
76+
# demoing persistent key-value global setting and traversing
77+
global_order_demo()

python/sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def meanage(filename="titanic.csv"):
1919

2020
return str(mean_age)
2121

22-
#print(meanage())
22+
print(meanage())

0 commit comments

Comments
 (0)