diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 89e92217fd584f5b4897e288639f6b52b0cce93a..dd6a776a1a21cad6296d92aa09fa406b59bdac51 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,7 +15,6 @@ Run tests: - apt-get install -y build-essential gcc tk openjdk-17-jdk - export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 - export PATH=$JAVA_HOME/bin:$PATH - - export THERMOGIS_JAR=$CI_PROJECT_DIR/resources/thermogis_jar/thermogis-1.7.0-shaded.jar - pixi install - pixi run pytest -rx tests/ - rm -rf /var/lib/apt/lists/* diff --git a/README.md b/README.md index 62c4f1bb437f1be098d10e5c689197113ad8ddd4..f771aa804542c809f0fa6c384a4245879099015d 100644 --- a/README.md +++ b/README.md @@ -16,29 +16,28 @@ pixi run mkdocs serve pythermogis has been designed to be used as a python package you import into your own python projects. It works by creating a python API access to the ThermoGIS techno-economic application, which is written in Java. -Because of this dependency you need to Install a Java 17 VM and store the ThermoGIS Jar (a Java executable file) on your computer: +Because of this dependency you need to Install a Java 17 VM. -### 1. Install Java 17 and Download the ThermoGIS JAR +### 1. Install Java 17 -This package requires a Java 17 VM (we recommend using [Amazon Corretto 17](https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/downloads-list.html)) and a [ThermoGIS Jar file](https://ci.tno.nl/gitlab/ags_public/pythermogis/-/blob/main/resources/thermogis_jar/thermogis-1.7.0-shaded.jar?ref_type=heads) (Version >=1.7). +This package requires a Java 17 VM (we recommend using [Amazon Corretto 17](https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/downloads-list.html)). *(You can find the JAR in this repository's resources folder: /resources/thermogis_jar)* -### 2. Create Required Environment Variables +### 2. Ensure JAVA_HOME is set -Create a file called ``.env`` in your project root folder. -This file should contain the following variables: +When installing the Java 17 Virtual Machine (JVM), a global environment variable _should_ have been set: `JAVA_HOME`. This stores the path to the JVM that was installed in step 1 and enables pythermogis to read the core Java code. + +If, for some reason, this was not done during installation you can either set it yourself or create a ``.env`` file in your project root folder. + +This `.env` file should contain the following variable: - `JAVA_HOME`: Path to the Java 17 installation *(e.g., on Windows: `C:\Program Files\Amazon Corretto\jdk17.0.0_0`)* -- `THERMOGIS_JAR`: Path to the ThermoGIS `.jar` file; __including__ the name of the jar file - *(e.g. `/path/to/the/thermogis-1.7.0-shaded.jar`)* - -Example .env contents: +Example `.env` contents (The specific path could be different depending on your OS, or file architecture): ``` -THERMOGIS_JAR = /path/to/the/thermogis-1.7.0-shaded.jar JAVA_HOME = C:\Program Files \Amazon Corretto\jdk17.0.0_0 ``` @@ -68,7 +67,7 @@ git clone git@ci.tno.nl:ags_public/pythermogis.git cd pythermogis pixi install ``` -(Make sure you have followed the step installing a Java17 VM and saving the ThermoGIS Jar) +(Make sure you have followed step 1 and 2: installing a Java 17 VM) --- diff --git a/docs/changelog.md b/docs/changelog.md index aab65ea5a216ae7a50d7233e884dd7321775d63c..56cfc0846e9dc349135a6a6b0646f00b9bda8ec5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # Change log +## v1.2.4 (23-1-2026) +The ThermoGIS Jar is now packaged within pythermogis, this reduces the number of installation steps from users (no longer having to set a THERMOGIS_JAR environment variable) and means that multiple installations of pythermogis on the same +system won't break each-other (previously two or more pythermogis installations would use the same Jar, which could cause version conflicts). + ## v1.2.3 (6-1-2026) Added the calculation of `heat in place` and `potential recoverable heat`. These are part of the potential calculation of the original java code. diff --git a/docs/install/install.md b/docs/install/install.md index 311cc563b3b138de22c57a65239489c22c91f1dd..128cefcb41caf091136ef1545eaec6c9b638f1bb 100644 --- a/docs/install/install.md +++ b/docs/install/install.md @@ -2,33 +2,31 @@ pythermogis has been designed to be used as a python package you import into your own python projects. It works by creating a python API access to the ThermoGIS techno-economic application, which is written in Java. -Because of this dependency you need to Install a Java 17 VM and store the ThermoGIS Jar (a Java executable file) on your computer: +Because of this dependency you need to Install a Java 17 VM. -### 1. Install Java 17 and Download the ThermoGIS JAR +### 1. Install Java 17 -This package requires a Java 17 VM (we recommend using [Amazon Corretto 17](https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/downloads-list.html)) and a [ThermoGIS Jar file](https://ci.tno.nl/gitlab/ags_public/pythermogis/-/blob/main/resources/thermogis_jar/thermogis-1.7.0-shaded.jar?ref_type=heads) (Version >=1.7). +This package requires a Java 17 VM (we recommend using [Amazon Corretto 17](https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/downloads-list.html)). -*(You can find the JAR in this repository's resources folder: /resources/thermogis_jar.)* +*(You can find the JAR in this repository's resources folder: /resources/thermogis_jar)* -### 2. Create Required Environment Variables +### 2. Ensure JAVA_HOME is set -Create a file called ``.env`` in your project root folder. -This file should contain the following variables: +When installing the Java 17 Virtual Machine (JVM), a global environment variable _should_ have been set: `JAVA_HOME`. This stores the path to the JVM that was installed in step 1 and enables pythermogis to read the core Java code. + +If, for some reason, this was not done during installation you can either set it yourself or create a ``.env`` file in your project root folder. + +This `.env` file should contain the following variable: - `JAVA_HOME`: Path to the Java 17 installation *(e.g., on Windows: `C:\Program Files\Amazon Corretto\jdk17.0.0_0`)* -- `THERMOGIS_JAR`: Path to the ThermoGIS `.jar` file; __including__ the name of the jar file - *(e.g. `/path/to/the/thermogis-1.7.0-shaded.jar`)* - -Example .env contents: +Example `.env` contents (The specific path could be different depending on your OS, or file architecture): ``` -THERMOGIS_JAR = /path/to/the/thermogis-1.7.0-shaded.jar JAVA_HOME = C:\Program Files \Amazon Corretto\jdk17.0.0_0 ``` - ### 3. Import pythermogis into your own python projects You can use pip to install the package directly from the gitlab project: @@ -55,6 +53,6 @@ git clone git@ci.tno.nl:ags_public/pythermogis.git cd pythermogis pixi install ``` -(Make sure you have followed the step installing a Java17 VM and saving the ThermoGIS Jar) +(Make sure you have followed step 1 and 2: installing a Java 17 VM) --- diff --git a/pixi.lock b/pixi.lock index 0d84993bba41405a3d2f7707684329dcd92dbc8e..61f5e03e1937f6ac8801da8c3ff9c4d1509bbdfb 100644 --- a/pixi.lock +++ b/pixi.lock @@ -4920,8 +4920,8 @@ packages: timestamp: 1740946648058 - pypi: ./ name: pythermogis - version: 1.2.3 - sha256: 6c8828289c71f3180f90af7d940428d8362b440e147bf8a6e533c4d28a8232d2 + version: 1.2.4 + sha256: 41970125f848a057eda9f00cac0c2046df6c0b149f67081432922484a4320b9d requires_dist: - jpype1>=1.5.2,<2 - xarray==2024.9.0.* diff --git a/pyproject.toml b/pyproject.toml index 9b5f1e744fa11d434e3e0bcbe9a0accab7a85be8..4054d06a1d0c7f8f5028c9e81d382c27c34498ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pythermogis" -version = "1.2.3" +version = "1.2.4" description = "This repository is used as a python API for the ThermoGIS Doublet simulations" authors = [ { name = "Hen Brett", email = "hen.brett@tno.nl" }, @@ -37,6 +37,9 @@ markers = [ [tool.setuptools] package-dir = {"" = "src"} +[tool.setuptools.package-data] +"pythermogis" = ["thermogis_jar/*.jar"] # Ensure all files inside 'lib/' are included + [tool.pixi.workspace] channels = ["conda-forge"] platforms = ["win-64", "linux-64"] diff --git a/src/pythermogis/constants.py b/src/pythermogis/constants.py new file mode 100644 index 0000000000000000000000000000000000000000..1b0c72f2fea07cad131dd067793fb88d834c481c --- /dev/null +++ b/src/pythermogis/constants.py @@ -0,0 +1,5 @@ +from pathlib import Path + +THERMOGIS_JAR_PATH = ( + Path(__file__).parent / "thermogis_jar" / "thermogis-1.7.0-shaded.jar" +) diff --git a/src/pythermogis/thermogis_classes/jvm_start.py b/src/pythermogis/thermogis_classes/jvm_start.py index 2bff18505c33780cf828b982eacb37da39145b40..cabbdb7d3e1f89b77c5b48cb9eda1ba35416b851 100644 --- a/src/pythermogis/thermogis_classes/jvm_start.py +++ b/src/pythermogis/thermogis_classes/jvm_start.py @@ -1,25 +1,18 @@ import os -from pathlib import Path import jpype import faulthandler from dotenv import load_dotenv - +from pythermogis.constants import THERMOGIS_JAR_PATH load_dotenv() def get_thermogis_jar_path() -> str: """ - From the resources directory, return the path to the ThermoGIS Jar + From within thermogis, find the thermogis-jar, return the path to the ThermoGIS Jar """ - tg_jar = os.getenv("THERMOGIS_JAR") - - if tg_jar is None: - raise ValueError("THERMOGIS_JAR environment variable is not set in the .env file.") - - thermogis_jar_path = Path(tg_jar) - if not thermogis_jar_path.exists(): - raise FileNotFoundError(f"Jar file not found at {thermogis_jar_path}, check that you have downloaded the ThermoGIS Jar and set the THERMOGIS_JAR environment variable.") - return str(thermogis_jar_path) + if not THERMOGIS_JAR_PATH.exists(): + raise FileNotFoundError(f"Jar file not found at {THERMOGIS_JAR_PATH}.") + return str(THERMOGIS_JAR_PATH) def start_jvm(): @@ -28,16 +21,12 @@ def start_jvm(): This method ensures a clean startup of the jvm packaged with this repo :return: """ - java_home = os.getenv("JAVA_HOME") - - if java_home is None: - raise ValueError("JAVA_HOME environment variable is not set in the .env file.") - if not jpype.isJVMStarted(): # when running pytest with jpype a "Windows fatal exception" is thrown which in reality has no affect on the outcome or performance. # the current workaround from the jpype package is to disable the pytest faulthandler. (This will not prevent python or java errors in the test). faulthandler.disable() + # automatically looks up the java version in JAVA_HOME jpype.startJVM(classpath=[get_thermogis_jar_path()]) def close_jvm(): diff --git a/resources/thermogis_jar/thermogis-1.7.0-shaded.jar b/src/pythermogis/thermogis_jar/thermogis-1.7.0-shaded.jar similarity index 100% rename from resources/thermogis_jar/thermogis-1.7.0-shaded.jar rename to src/pythermogis/thermogis_jar/thermogis-1.7.0-shaded.jar