Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0f70b03
ignore types folder
tlambert03 Apr 23, 2025
459a999
Add scyjava-stubs CLI and dynamic import functionality
tlambert03 Apr 23, 2025
a8b2da7
remove import
tlambert03 Apr 23, 2025
686739b
add test
tlambert03 Apr 23, 2025
7fe31af
add comment to clarify stubgen command execution in test
tlambert03 Apr 23, 2025
afcc7a7
refactor: clean up jpype imports in stubgen test and main module
tlambert03 Apr 23, 2025
a5cacc8
remove unused jpype import from _genstubs.py
tlambert03 Apr 23, 2025
ab1bc2d
fix: add future annotations import to _cli.py
tlambert03 Apr 23, 2025
11649fa
refactor: enhance dynamic_import function to accept base_prefix and i…
tlambert03 Apr 23, 2025
2cb4836
refactor: rename dynamic_import to setup_java_imports and update usag…
tlambert03 Apr 23, 2025
71f761e
reword
tlambert03 Apr 23, 2025
65cc471
feat: add Hatchling build hook for generating Java stubs
tlambert03 Apr 25, 2025
6e4181e
wip
tlambert03 Apr 25, 2025
6e92b13
fix inclusion
tlambert03 Apr 25, 2025
0d231cc
add docs
tlambert03 Apr 25, 2025
79524b0
setuptools plugin stub
tlambert03 Apr 25, 2025
9bdba53
Merge branch 'main' into stubs
tlambert03 Apr 30, 2025
51937b5
remove repr test
tlambert03 May 1, 2025
192be35
skip in jep
tlambert03 May 1, 2025
e714abb
remove setuptools plugin
tlambert03 May 1, 2025
e7bc894
Merge branch 'main' into stubs
tlambert03 Aug 20, 2025
a18d9d9
remove hatch plugin
tlambert03 Aug 22, 2025
b53e795
newlines
tlambert03 Aug 22, 2025
ed0add6
update docs
tlambert03 Aug 22, 2025
43cb06d
initial
tlambert03 Aug 22, 2025
b181bd7
working principle
tlambert03 Aug 23, 2025
76d9bfa
remove readme
tlambert03 Aug 23, 2025
c579490
remove x
tlambert03 Aug 23, 2025
a519d35
Merge branch 'delay-import' into stubs-metafinder
tlambert03 Aug 23, 2025
93e4e51
cleaner
tlambert03 Aug 23, 2025
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
Prev Previous commit
Next Next commit
add test
  • Loading branch information
tlambert03 committed Apr 23, 2025
commit 686739b56c0645e1dc57f129169098a283f63e58
4 changes: 4 additions & 0 deletions src/scyjava/_stubs/_genstubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def generate_stubs(
stub generator wrote to it (and therefore inaccurate).
"""
import jpype

# FIXME: either remove the _JImportLoader from sys.meta_path after this is done
# (if it wasn't there to begin with), or replace the import_module calls below
# with a more direct JPackage call
import jpype.imports

startJVM = jpype.startJVM
Expand Down
56 changes: 56 additions & 0 deletions tests/test_stubgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING
from unittest.mock import patch

import jpype
import jpype.imports

import scyjava
from scyjava._stubs import _cli

if TYPE_CHECKING:
from pathlib import Path

import pytest


def test_stubgen(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
monkeypatch.setattr(
sys,
"argv",
[
"scyjava-stubgen",
"org.scijava:parsington:3.1.0",
"--output-dir",
str(tmp_path),
],
)
_cli.main()

# remove the `jpype.imports` magic from the import system if present
mp = [x for x in sys.meta_path if not isinstance(x, jpype.imports._JImportLoader)]
monkeypatch.setattr(sys, "meta_path", mp)

# add tmp_path to the import path
monkeypatch.setattr(sys, "path", [str(tmp_path)])

# first cleanup to make sure we are not importing from the cache
sys.modules.pop("org", None)
sys.modules.pop("org.scijava", None)
sys.modules.pop("org.scijava.parsington", None)
# make sure the stubgen command works and that we can now impmort stuff

with patch.object(scyjava._jvm, "start_jvm") as mock_start_jvm:
from org.scijava.parsington import Function

assert Function is not None
assert repr(Function) == "<scyjava class 'org.scijava.parsington.Function'>"
# ensure that no calls to start_jvm were made
mock_start_jvm.assert_not_called()

# only after instantiating the class should we have a call to start_jvm
func = Function(1)
mock_start_jvm.assert_called_once()
assert isinstance(func, jpype.JObject)
Loading