diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5898be5f..d7505c48 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,8 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] python-version: ["3.9", "3.13"] + java-version: ["8", "21"] + steps: - uses: actions/checkout@v2 @@ -28,7 +30,7 @@ jobs: - uses: actions/setup-java@v3 with: - java-version: '8' + java-version: ${{matrix.java-version}} distribution: 'zulu' - name: Install PyImageJ @@ -52,7 +54,7 @@ jobs: python -m pip install ruff ruff check ruff format --check - + - name: Validate pyproject.toml run: | python -m pip install validate-pyproject[all] diff --git a/conftest.py b/conftest.py index 45b9ddd7..5538a7ef 100644 --- a/conftest.py +++ b/conftest.py @@ -1,8 +1,9 @@ import argparse - +import subprocess import pytest import imagej +from scyjava import config def pytest_addoption(parser): @@ -39,12 +40,16 @@ def ij(request): Create an ImageJ instance to be used by the whole testing environment :param request: Pytest variable passed in to fixtures """ + # get test configuration ij_dir = request.config.getoption("--ij") legacy = request.config.getoption("--legacy") headless = request.config.getoption("--headless") - + # add the nashorn (JavaScript) endpoint if needed, + # nashorn was bundled with the JDK from Java 8 to 14 + if capture_java_version() > 14: + config.endpoints.append("org.openjdk.nashorn:nashorn-core") imagej.when_imagej_starts(lambda ij: setattr(ij, "_testing", True)) - + # initialize the ImageJ gateway mode = "headless" if headless else "interactive" ij = imagej.init(ij_dir, mode=mode, add_legacy=legacy) @@ -53,6 +58,33 @@ def ij(request): ij.dispose() +def capture_java_version() -> int: + """Capture the installed Java version. + + This function captures the JDK version installed in the current + venv without starting the JVM by parsing the Java "-version" + output string. + + :return: The major Java version (8, 11, 21 etc...). + """ + try: + # capture the Java version string + java_ver_str = subprocess.run( + ["java", "-version"], capture_output=True, text=True + ) + # extract the Java version from the string + java_ver = java_ver_str.stderr.split("\n")[0].split(" ")[2] + java_ver = java_ver.strip('"').split(".") + major_ver_arr = [int(java_ver[i]) for i in range(2)] + # find major Java version + if major_ver_arr[0] == 1: + return major_ver_arr[1] # Java 8-10 + else: + return major_ver_arr[0] # Java 11+ + except FileNotFoundError: + raise RuntimeError("No Java installation found.") + + def str2bool(v): """ Convert string inputs into bool diff --git a/dev-environment.yml b/dev-environment.yml index dabc7567..0e46c865 100644 --- a/dev-environment.yml +++ b/dev-environment.yml @@ -24,7 +24,7 @@ dependencies: # Project dependencies - imglyb >= 2.1.0 - jgo >= 1.0.3 - - jpype1 >= 1.3.0 + - jpype1 >= 1.4.0 - labeling >= 0.1.14 - numpy - openjdk=11 diff --git a/environment.yml b/environment.yml index 4fb58f06..edb0b91b 100644 --- a/environment.yml +++ b/environment.yml @@ -24,7 +24,7 @@ dependencies: # Project dependencies - imglyb >= 2.1.0 - jgo >= 1.0.3 - - jpype1 >= 1.3.0 + - jpype1 >= 1.4.0 - labeling >= 0.1.14 - numpy - openjdk=11 diff --git a/pyproject.toml b/pyproject.toml index e396b995..c6ea72b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ requires-python = ">=3.9" dependencies = [ "imglyb >= 2.1.0", "jgo >= 1.0.3", - "jpype1 >= 1.3.0", + "jpype1 >= 1.4.0", "labeling >= 0.1.14", "numpy", "scyjava >= 1.8.0",