From 0e04ff788de4f6d40f94c06b73e43be7a28f3e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CEvgeny?= Date: Mon, 4 Sep 2023 13:10:54 +0400 Subject: [PATCH] update readme and rename iris_script.py --- Dockerfile | 2 +- README.md | 114 ++++++++++++++++--------------- iris-script.py => iris_script.py | 0 3 files changed, 60 insertions(+), 56 deletions(-) rename iris-script.py => iris_script.py (100%) diff --git a/Dockerfile b/Dockerfile index bf6ba1c..8f73e43 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,5 +22,5 @@ RUN --mount=type=bind,src=.,dst=. \ pip3 install -r requirements.txt && \ iris start IRIS && \ iris merge IRIS merge.cpf && \ - irispython iris-script.py && \ + irispython iris_script.py && \ iris stop IRIS quietly diff --git a/README.md b/README.md index 4806fda..a0a80ec 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ $ docker-compose up -d ### IRIS Initialization In this template two approaches are provided to initialize iris: merge and python. +merge.cpf is a convenient way to setup different IRIS configuration settings. [Learn more about merge.cpf](https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RACS_cpf#:~:text=Use%20the%20iris%20merge%20command,is%20the%20instance's%20current%20iris.). 1. Using merge to initialize IRIS and create IRIS Database and Namespace Notice [merge.cpf](https://github.com/intersystems-community/iris-embedded-python-template/blob/4c12d4b02770c7422c7553ee818a18c1871c3759/merge.cpf) file that is being implemented during docker image build in Dockerfile @@ -80,76 +81,26 @@ docker run --rm -it containers.intersystems.com/intersystems/passwordhash:1.1 -a ``` 2. Using python to initialize IRIS. -Often we used a special iris.script file to run ObjectScript commands during the initialization. -This template shows you how to use python for the same purpose with [iris-script.py](https://github.com/intersystems-community/iris-embedded-python-template/blob/4c12d4b02770c7422c7553ee818a18c1871c3759/iris-script.py)file. +Often we used a special [iris.script](https://github.com/intersystems-community/iris-embedded-python-template/blob/d7c817865b48681e3454997906e1374b3baeef74/iris.script) file to run ObjectScript commands during the initialization - it is here just for the information. +This template shows you how to use python for the same purpose with [iris_script.py](https://github.com/intersystems-community/iris-embedded-python-template/blob/4c12d4b02770c7422c7553ee818a18c1871c3759/iris_script.py)file. It is being executed via the line in Dockerfile: ``` -irispython iris-script.py && \ +irispython iris_script.py && \ ``` -the iris-script.py file contains examples how developer can initialize different services of iris via Python code. +the iris_script.py file contains examples how developer can initialize different services of iris via Python code. ## How to test it -### Working with Python libs from ObjectScript -Open IRIS terminal: - -```objectscript -$ docker-compose exec iris iris session iris -USER>zn "IRISAPP" -``` - -The first test demonstrates the call to a standard python library working with dates datetime -```objectscript -IRISAPP>d ##class(dc.python.test).Today() -2021-02-09 -``` - -Another example shows the work of a custom lib sample.py which is installed with repo or ZPM. It has function hello which returns string "world": -```objectscript -IRISAPP>d ##class(dc.python.test).Hello() -World -``` - -Another example shows how to work with files and use pandas and numpy libs. -It calculates the mean age of Titanic passengers: - -```objectscript -IRISAPP>d ##class(dc.python.test).TitanicMeanAge() -mean age=29.69911764705882 - -``` ### Working with IRIS from Embedded Python As mentioned Embedded Python works in the **same process as IRIS**. So you have 2 options to work with Embedded Python in IRIS: -1. Develop in VSCode locally and then run the code in IRIS container with a shared folder. +1. Run the code in IRIS container with a shared folder. 2. Bind VsCode to the running IRIS container. -### Develop python scripts locally and run the code in IRIS container - -By default, the template is configured to use the shared folder `./src` for python scripts to `/home/irisowner/dev/src` in IRIS container. - -You can change the folder according to your preferences. - -It's recommended to work with a virtual environment. - -Create a virtual environment in the project directory. Click New Terminal in the VS Code menu: -```bash -$ python3 -m venv .venv -``` -Activate the virtual environment: -``` -$ source .venv/bin/activate -``` - -Install the requirements: -``` -$ pip install -r requirements.txt -``` - #### Run the python script in iris container: ```bash @@ -207,6 +158,59 @@ $ irispython /python/irisapp.py ``` +### Working with Python libs from ObjectScript +Open IRIS terminal: + +```objectscript +$ docker-compose exec iris iris session iris +USER>zn "IRISAPP" +``` + +The first test demonstrates the call to a standard python library working with dates datetime +```objectscript +IRISAPP>d ##class(dc.python.test).Today() +2021-02-09 +``` + +Another example shows the work of a custom lib sample.py which is installed with repo or ZPM. It has function hello which returns string "world": +```objectscript +IRISAPP>d ##class(dc.python.test).Hello() +World +``` + +Another example shows how to work with files and use pandas and numpy libs. +It calculates the mean age of Titanic passengers: + +```objectscript +IRISAPP>d ##class(dc.python.test).TitanicMeanAge() +mean age=29.69911764705882 + +``` + +### Develop python scripts locally + +By default, the template is configured to use the shared folder `./python` for python scripts to `/home/irisowner/dev/python` in IRIS container. + +You can change the folder according to your preferences. Usually python developers name project at the root folder. + +It's recommended to work with a virtual environment. + +Create a virtual environment in the project directory. Click New Terminal in the VS Code menu: +```bash +$ python3 -m venv .venv +``` +Activate the virtual environment: +``` +$ source .venv/bin/activate +``` + +Install the requirements: +``` +$ pip install -r requirements.txt +``` + + + ### Working with flask The template also contains samples of working with flask. diff --git a/iris-script.py b/iris_script.py similarity index 100% rename from iris-script.py rename to iris_script.py