Skip to content

Commit 3607e57

Browse files
committed
Lint code and fix bugs
1 parent 15d8361 commit 3607e57

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/imagej/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,9 @@ def _guess_java_version() -> Optional[int]:
15731573
# already-installed JVM available on the system. So let's be more
15741574
# nuanced in how we predict the future here.
15751575
fetch_plan = sj.config.get_fetch_java()
1576-
will_fetch = fetch_plan == 'always' or \
1577-
(fetch_rule == 'auto' and version_digits is None)
1576+
will_fetch = fetch_plan == "always" or (
1577+
fetch_plan == "auto" and version_digits is None
1578+
)
15781579
if will_fetch:
15791580
version_to_fetch = sj.config.get_java_version()
15801581
_logger.debug(f"Detected Java version to fetch: {version_to_fetch}")
@@ -1647,7 +1648,7 @@ def _prepare_to_unlock_modules() -> bool:
16471648

16481649
if major_version is not None and major_version >= 9:
16491650
# Allow illegal reflection access. Necessary for Java 17+.
1650-
option = f"--add-opens=java.base/java.lang=ALL-UNNAMED"
1651+
option = "--add-opens=java.base/java.lang=ALL-UNNAMED"
16511652
_logger.debug(f"Adding option: {option}")
16521653
sj.config.add_option(option)
16531654
return True

src/imagej/_java.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ def unlock_modules(logger: logging.Logger) -> None:
2929
Module = jimport("java.lang.Module")
3030
ModuleLayer = jimport("java.lang.ModuleLayer")
3131
String = jimport("java.lang.String")
32-
Method = jimport("java.lang.reflect.Method")
3332

34-
addOpens = Module.class_.getDeclaredMethod("implAddOpens", String.class_, Module.class_)
33+
addOpens = Module.class_.getDeclaredMethod(
34+
"implAddOpens", String.class_, Module.class_
35+
)
3536
addOpens.setAccessible(True)
36-
addExports = Module.class_.getDeclaredMethod("implAddExports", String.class_, Module.class_)
37+
addExports = Module.class_.getDeclaredMethod(
38+
"implAddExports", String.class_, Module.class_
39+
)
3740
addExports.setAccessible(True)
3841

3942
# HACK: We need a class from the unnamed module.
4043
unnamed = jimport("org.scijava.Context").class_.getModule()
4144

4245
for module in ModuleLayer.boot().modules():
43-
for package in m.getPackages():
46+
for package in module.getPackages():
4447
try:
45-
addOpens.invoke(m, package, unnamed)
46-
addExports.invoke(m, package, unnamed)
48+
addOpens.invoke(module, package, unnamed)
49+
addExports.invoke(module, package, unnamed)
4750
except Exception as e:
4851
# Continue with other packages
4952
log_exception(logger, e)

tests/test_callbacks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from scyjava import jimport
22

3+
34
def test_when_imagej_starts(ij):
45
"""
56
The ImageJ2 gateway test fixture registers a callback function via

0 commit comments

Comments
 (0)