Skip to content

Commit 72e7f4f

Browse files
committed
add python support for the init script
1 parent 3353a02 commit 72e7f4f

File tree

6 files changed

+57
-14
lines changed

6 files changed

+57
-14
lines changed

.vscode/settings.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
"iris.script": "objectscript"
66
},
77
"objectscript.conn" :{
8-
"ns": "USER",
9-
"username": "_SYSTEM",
8+
"ns": "IRISAPP",
9+
"username": "SUPERUSER",
1010
"password": "SYS",
1111
"docker-compose": {
1212
"service": "iris",
1313
"internalPort": 52773
1414
},
15-
"active": true
15+
"active": false
1616
},
1717
"sqltools.connections": [
1818
{
19-
"namespace": "USER",
19+
"namespace": "IRISAPP",
2020
"connectionMethod": "Server and Port",
2121
"showSystem": false,
2222
"previewLimit": 50,
@@ -25,7 +25,7 @@
2525
"askForPassword": false,
2626
"driver": "InterSystems IRIS",
2727
"name": "objectscript-docker",
28-
"username": "_SYSTEM",
28+
"username": "SUPERUSER",
2929
"password": "SYS"
3030
}
3131
],

Dockerfile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG IMAGE=intersystemsdc/irishealth-community
2-
ARG IMAGE=intersystemsdc/iris-community
32
ARG IMAGE=intersystemsdc/iris-community:preview
3+
ARG IMAGE=intersystemsdc/iris-community
44
FROM $IMAGE
55

66
WORKDIR /home/irisowner/dev
@@ -9,19 +9,18 @@ ARG TESTS=0
99
ARG MODULE="iris-python-template"
1010
ARG NAMESPACE="USER"
1111

12+
1213
# create Python env
1314
## Embedded Python environment
14-
ENV IRISUSERNAME "SuperUser"
15-
ENV IRISPASSWORD "SYS"
16-
ENV IRISNAMESPACE "USER"
15+
ENV IRISNAMESPACE "IRISAPP"
1716
ENV PYTHON_PATH=/usr/irissys/bin/
18-
ENV PATH "/usr/irissys/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/irisowner/bin"
19-
17+
ENV PATH "/usr/irissys/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/irisowner/bin:/home/irisowner/.local/bin"
18+
ENV LIBRARY_PATH=${ISC_PACKAGE_INSTALLDIR}/bin:${LIBRARY_PATH}
2019
## Start IRIS
2120

2221
RUN --mount=type=bind,src=.,dst=. \
2322
pip3 install -r requirements.txt && \
2423
iris start IRIS && \
25-
iris session IRIS < iris.script && \
26-
([ $TESTS -eq 0 ] || iris session iris -U $NAMESPACE "##class(%ZPM.PackageManager).Shell(\"test $MODULE -v -only\",1,1)") && \
24+
iris merge IRIS /home/irisowner/dev/merge.cpf && \
25+
python3 /home/irisowner/dev/iris-script.py && \
2726
iris stop IRIS quietly

dev.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,7 @@ IRISAPP:zpm>test package-name
9191

9292

9393
do ##class(%SYS.Python).Shell()
94+
95+
96+
iris session IRIS < iris.script && \
97+
([ $TESTS -eq 0 ] || iris session iris -U $NAMESPACE "##class(%ZPM.PackageManager).Shell(\"test $MODULE -v -only\",1,1)") && \

iris-script.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import glob
2+
import os
3+
import iris
4+
import pandas as pd
5+
from sqlalchemy import create_engine
6+
from grongier.pex import Utils
7+
8+
# switch namespace to the %SYS namespace
9+
iris.system.Process.SetNamespace("%SYS")
10+
11+
# set credentials to not expire
12+
iris.cls('Security.Users').UnExpireUserPasswords("*")
13+
14+
# switch namespace to IRISAPP built by merge.cpf
15+
iris.system.Process.SetNamespace("IRISAPP")
16+
17+
# load zpm packages
18+
iris.cls('%ZPM.PackageManager').Shell("load /home/irisowner/dev -v")
19+
20+
# load demo data
21+
engine = create_engine('iris+emb:///')
22+
# list all csv files in the demo data folder
23+
for files in glob.glob('/home/irisowner/dev/data/*.csv'):
24+
# get the file name without the extension
25+
table_name = os.path.splitext(os.path.basename(files))[0]
26+
# load the csv file into a pandas dataframe
27+
df = pd.read_csv(files)
28+
# write the dataframe to IRIS
29+
df.to_sql(table_name, engine, if_exists='replace', index=False, schema='Demo')
30+

merge.cpf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Actions]
2+
CreateResource:Name=%DB_IRISAPP_DATA,Description="IRISAPP_DATA database"
3+
CreateDatabase:Name=IRISAPP_DATA,Directory=/usr/irissys/mgr/IRISAPP_DATA
4+
CreateResource:Name=%DB_IRISAPP_CODE,Description="IRISAPP_CODE database"
5+
CreateDatabase:Name=IRISAPP_CODE,Directory=/usr/irissys/mgr/IRISAPP_CODE
6+
CreateNamespace:Name=IRISAPP,Globals=IRISAPP_DATA,Routines=IRISAPP_CODE,Interop=1
7+
ModifyService:Name=%Service_CallIn,Enabled=1,AutheEnabled=48
8+
ModifyUser:Name=SuperUser,PasswordHash=a31d24aecc0bfe560a7e45bd913ad27c667dc25a75cbfd358c451bb595b6bd52bd25c82cafaa23ca1dd30b3b4947d12d3bb0ffb2a717df29912b743a281f97c1,0a4c463a2fa1e7542b61aa48800091ab688eb0a14bebf536638f411f5454c9343b9aa6402b4694f0a89b624407a5f43f0a38fc35216bb18aab7dc41ef9f056b1,10000,SHA512

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
numpy==1.23.4
2-
pandas==1.5.0
2+
pandas==1.5.0
3+
dataclasses-json==0.5.7
4+
sqlalchemy-iris==0.10.5

0 commit comments

Comments
 (0)