Skip to content

Commit 1c98a15

Browse files
authored
Merge pull request #324 from imagej/actions-updates
Test new python versions
2 parents f96da00 + bdd3349 commit 1c98a15

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
matrix:
1919
os: [ubuntu-latest, windows-latest, macos-latest]
2020
python-version: ["3.9", "3.13"]
21+
java-version: ["8", "21"]
22+
2123

2224
steps:
2325
- uses: actions/checkout@v2
@@ -28,7 +30,7 @@ jobs:
2830

2931
- uses: actions/setup-java@v3
3032
with:
31-
java-version: '8'
33+
java-version: ${{matrix.java-version}}
3234
distribution: 'zulu'
3335

3436
- name: Install PyImageJ
@@ -52,7 +54,7 @@ jobs:
5254
python -m pip install ruff
5355
ruff check
5456
ruff format --check
55-
57+
5658
- name: Validate pyproject.toml
5759
run: |
5860
python -m pip install validate-pyproject[all]

conftest.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import argparse
2-
2+
import subprocess
33
import pytest
44

55
import imagej
6+
from scyjava import config
67

78

89
def pytest_addoption(parser):
@@ -39,12 +40,16 @@ def ij(request):
3940
Create an ImageJ instance to be used by the whole testing environment
4041
:param request: Pytest variable passed in to fixtures
4142
"""
43+
# get test configuration
4244
ij_dir = request.config.getoption("--ij")
4345
legacy = request.config.getoption("--legacy")
4446
headless = request.config.getoption("--headless")
45-
47+
# add the nashorn (JavaScript) endpoint if needed,
48+
# nashorn was bundled with the JDK from Java 8 to 14
49+
if capture_java_version() > 14:
50+
config.endpoints.append("org.openjdk.nashorn:nashorn-core")
4651
imagej.when_imagej_starts(lambda ij: setattr(ij, "_testing", True))
47-
52+
# initialize the ImageJ gateway
4853
mode = "headless" if headless else "interactive"
4954
ij = imagej.init(ij_dir, mode=mode, add_legacy=legacy)
5055

@@ -53,6 +58,33 @@ def ij(request):
5358
ij.dispose()
5459

5560

61+
def capture_java_version() -> int:
62+
"""Capture the installed Java version.
63+
64+
This function captures the JDK version installed in the current
65+
venv without starting the JVM by parsing the Java "-version"
66+
output string.
67+
68+
:return: The major Java version (8, 11, 21 etc...).
69+
"""
70+
try:
71+
# capture the Java version string
72+
java_ver_str = subprocess.run(
73+
["java", "-version"], capture_output=True, text=True
74+
)
75+
# extract the Java version from the string
76+
java_ver = java_ver_str.stderr.split("\n")[0].split(" ")[2]
77+
java_ver = java_ver.strip('"').split(".")
78+
major_ver_arr = [int(java_ver[i]) for i in range(2)]
79+
# find major Java version
80+
if major_ver_arr[0] == 1:
81+
return major_ver_arr[1] # Java 8-10
82+
else:
83+
return major_ver_arr[0] # Java 11+
84+
except FileNotFoundError:
85+
raise RuntimeError("No Java installation found.")
86+
87+
5688
def str2bool(v):
5789
"""
5890
Convert string inputs into bool

dev-environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
# Project dependencies
2525
- imglyb >= 2.1.0
2626
- jgo >= 1.0.3
27-
- jpype1 >= 1.3.0
27+
- jpype1 >= 1.4.0
2828
- labeling >= 0.1.14
2929
- numpy
3030
- openjdk=11

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
# Project dependencies
2525
- imglyb >= 2.1.0
2626
- jgo >= 1.0.3
27-
- jpype1 >= 1.3.0
27+
- jpype1 >= 1.4.0
2828
- labeling >= 0.1.14
2929
- numpy
3030
- openjdk=11

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ requires-python = ">=3.9"
3737
dependencies = [
3838
"imglyb >= 2.1.0",
3939
"jgo >= 1.0.3",
40-
"jpype1 >= 1.3.0",
40+
"jpype1 >= 1.4.0",
4141
"labeling >= 0.1.14",
4242
"numpy",
4343
"scyjava >= 1.8.0",

0 commit comments

Comments
 (0)