Skip to content

Commit f8b07cd

Browse files
committed
Let scyjava.config accept JPype keyword arguments
Closes #79.
1 parent 0f48293 commit f8b07cd

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
@@ -20,6 +20,7 @@
2020
_cache_dir = Path.home() / ".jgo"
2121
_m2_repo = Path.home() / ".m2" / "repository"
2222
_options = []
23+
_kwargs = {"interrupt": True}
2324
_shortcuts = {}
2425

2526

@@ -320,6 +321,27 @@ def get_options() -> list[str]:
320321
return _options
321322

322323

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

0 commit comments

Comments
 (0)