Skip to content

Commit 411caec

Browse files
committed
Let scyjava.config accept JPype keyword arguments
Closes #79.
1 parent c171e75 commit 411caec

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/scyjava/_jvm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ def start_jvm(options=None, *, fetch_java: bool = True) -> None:
198198
_logger.debug("Starting JVM")
199199
if options is None:
200200
options = scyjava.config.get_options()
201-
jpype.startJVM(*options, interrupt=True)
201+
kwargs = scyjava.config.get_kwargs()
202+
jpype.startJVM(*options, **kwargs)
202203

203204
# replace JPype/JVM shutdown handling with our own
204205
jpype.config.onexit = False

src/scyjava/config.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
_cache_dir = Path.home() / ".jgo"
1919
_m2_repo = Path.home() / ".m2" / "repository"
2020
_options = []
21+
_kwargs = {"interrupt": True}
2122
_shortcuts = {}
2223

2324

@@ -318,6 +319,27 @@ def get_options() -> list[str]:
318319
return _options
319320

320321

322+
def add_kwargs(**kwargs) -> None:
323+
"""
324+
Add keyword arguments to be passed to JPype at JVM startup. Examples:
325+
326+
jvmpath = "/path/to/my_jvm"
327+
ignoreUnrecognized = True
328+
convertStrings = True
329+
interrupt = True
330+
"""
331+
global _kwargs
332+
_kwargs.update(kwargs)
333+
334+
335+
def get_kwargs() -> dict[str, str]:
336+
"""
337+
Get the keyword arguments to be passed to JPype at JVM startup.
338+
"""
339+
global _kwargs
340+
return _kwargs
341+
342+
321343
def add_shortcut(k: str, v: str):
322344
"""
323345
Add a shortcut key/value to be used by jgo for evaluating endpoints.

0 commit comments

Comments
 (0)