Skip to content

Test new python versions #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +30,7 @@ jobs:

- uses: actions/setup-java@v3
with:
java-version: '8'
java-version: ${{matrix.java-version}}
distribution: 'zulu'

- name: Install PyImageJ
Expand All @@ -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]
Expand Down
38 changes: 35 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import argparse

import subprocess
import pytest

import imagej
from scyjava import config


def pytest_addoption(parser):
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading