GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add scyjava-stubgen cli command, and `scyjava.types` namespace, which provide type-safe imports with lazy init by tlambert03 · Pull Request #82 · scijava/scyjava

Conversation

@tlambert03

@tlambert03 tlambert03 commented Apr 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

many more details and tests to follow... but just wanted to open this as a WIP.
edit: see #82 (comment) for details

Basic idea, after checking out this branch and running pip install -e . again:

  1. create stubs with a cli commend, e.g. scyjava-stubgen org.scijava:parsington:3.1.0
  2. Import names provided by that endpoint: python -c "from scyjava.types.org.scijava.parsington import Function; print(Function(1))". Only at the moment of class instantiation will the jvm be started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ctrueden reacted with heart emoji
All reactions
  • ❤️ 1 reaction
tlambert03 added 15 commits April 22, 2025 22:50
@tlambert03
ignore types folder
0f70b03
@tlambert03
Add scyjava-stubs CLI and dynamic import functionality
459a999
- Introduced `scyjava-stubs` executable for generating Python type stubs from Java classes.
- Implemented dynamic import logic in `_dynamic_import.py`.
- Added stub generation logic in `_genstubs.py`.
- Updated `pyproject.toml` to include new dependencies and scripts.
- Created `__init__.py` for the `_stubs` package to expose key functionalities.
@tlambert03
remove import
a8b2da7
@tlambert03
add test
686739b
@tlambert03
add comment to clarify stubgen command execution in test
7fe31af
@tlambert03
refactor: clean up jpype imports in stubgen test and main module
afcc7a7
@tlambert03
remove unused jpype import from _genstubs.py
a5cacc8
@tlambert03
fix: add future annotations import to _cli.py
ab1bc2d
@tlambert03
refactor: enhance dynamic_import function to accept base_prefix and i…
11649fa
…mprove stub generation
@tlambert03
refactor: rename dynamic_import to setup_java_imports and update usag…
2cb4836
…e in stubs
@tlambert03
reword
71f761e
@tlambert03
feat: add Hatchling build hook for generating Java stubs
65cc471
@tlambert03
wip
6e4181e
@tlambert03
fix inclusion
6e92b13
@tlambert03
add docs
0d231cc
@codecov

codecov Bot commented Apr 25, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 77.46479% with 48 lines in your changes missing coverage. Please review.

Project coverage is 75.98%. Comparing base (34bfae2) to head (0d231cc).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/scyjava/_stubs/_cli.py 49.20% 32 Missing ⚠️
src/scyjava/_stubs/_genstubs.py 89.15% 9 Missing ⚠️
src/scyjava/_stubs/_dynamic_import.py 88.88% 4 Missing ⚠️
tests/test_stubgen.py 92.59% 2 Missing ⚠️
src/scyjava/_jvm.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #82       +/-   ##
===========================================
+ Coverage   52.72%   75.98%   +23.25%     
===========================================
  Files          12       20        +8     
  Lines        1303     1653      +350     
===========================================
+ Hits          687     1256      +569     
+ Misses        616      397      -219     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tlambert03 added 3 commits April 25, 2025 08:17
@tlambert03
setuptools plugin stub
79524b0
@tlambert03
Merge branch 'main' into stubs
9bdba53
@tlambert03
remove repr test
51937b5
@tlambert03

tlambert03 commented May 1, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator Author

hey @ctrueden, I'm struggling to run the jep tests locally (on my mac). I have openjdk version "11.0.27" 2025-04-15 but still get:

--> tests/it/java_heap.py [OK]
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

Traceback (most recent call last):
  File "/Users/talley/dev/self/scyjava/tests/it/jvm_version.py", line 11, in <module>
    before_version = scyjava.jvm_version()
  File "/Users/talley/dev/self/scyjava/src/scyjava/_jvm.py", line 70, in jvm_version
    default_jvm_path = jpype.getDefaultJVMPath()
  File "/Users/talley/dev/self/scyjava/.venv/lib/python3.13/site-packages/jpype/_jvmfinder.py", line 70, in getDefaultJVMPath
    return finder.get_jvm_path()
           ~~~~~~~~~~~~~~~~~~~^^
  File "/Users/talley/dev/self/scyjava/.venv/lib/python3.13/site-packages/jpype/_jvmfinder.py", line 184, in get_jvm_path
    jvm = method()
  File "/Users/talley/dev/self/scyjava/.venv/lib/python3.13/site-packages/jpype/_jvmfinder.py", line 311, in _javahome_binary
    return subprocess.check_output(
           ~~~~~~~~~~~~~~~~~~~~~~~^
        ['/usr/libexec/java_home']).strip()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/talley/.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/subprocess.py", line 472, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               **kwargs).stdout
               ^^^^^^^^^
  File "/Users/talley/.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/subprocess.py", line 577, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/usr/libexec/java_home']' returned non-zero exit status 1.

it's a bit unclear to me whether I should be trying to get these to work at all with jep, or just add a skip to the test

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ctrueden

ctrueden commented May 1, 2025

Copy link
Copy Markdown
Member

As a workaround, you could try setting JAVA_HOME? Then maybe jpype wouldn't try to invoke the java_home command. Out of curiosity: what does /usr/libexec/java_home -V say when you run it from the CLI?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlambert03

tlambert03 commented May 1, 2025

Copy link
Copy Markdown
Collaborator Author

got that working... and commented out the "don't run on macos cause it's flaky" bit, and now get this:

-------------------------------------------
|  Testing Jep mode (Python inside Java)  |
-------------------------------------------
DEBUG 2025-05-01 08:20:23,154: Using settings:     {'m2repo': '/Users/talley/.m2/repository', 'cachedir': '/Users/talley/.jgo', 'links': 'auto'}
DEBUG 2025-05-01 08:20:23,155: Using repositories: {'scijava.public': 'https://maven.scijava.org/content/groups/public'}
DEBUG 2025-05-01 08:20:23,155: Using shortcuts:    {}
DEBUG 2025-05-01 08:20:23,155: Returning expanded coordinate black.ninia:jep:jep.Run.
DEBUG 2025-05-01 08:20:23,155: Returning expanded coordinate org.scijava:scijava-table.
INFO 2025-05-01 08:20:23,155: First time start-up may be slow. Downloaded dependencies will be cached for shorter start-up times in subsequent executions.
DEBUG 2025-05-01 08:20:23,155: Executing: ('/Users/talley/Library/Caches/cjdk/v0/misc-dirs/98cdba9371f93e1b5b8b95941b562d1647aecc21/apache-maven-3.9.9/bin/mvn', '-B', '-f', '/Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/pom.xml', 'dependency:resolve', '-X')
DEBUG 2025-05-01 08:20:31,600: Relevant mvn output: [INFO]    black.ninia:jep:jar:4.2.2:compile -- module jep (auto)
DEBUG 2025-05-01 08:20:31,600: Linking source /Users/talley/.m2/repository/black/ninia/jep/4.2.2/jep-4.2.2.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/jep-4.2.2.jar with link_type auto
DEBUG 2025-05-01 08:20:31,600: Linking source /Users/talley/.m2/repository/black/ninia/jep/4.2.2/jep-4.2.2.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/jep-4.2.2.jar with link_type hard
DEBUG 2025-05-01 08:20:31,601: Relevant mvn output: [INFO]    org.scijava:scijava-table:jar:1.0.2:compile -- module org.scijava.table [auto]
DEBUG 2025-05-01 08:20:31,601: Linking source /Users/talley/.m2/repository/org/scijava/scijava-table/1.0.2/scijava-table-1.0.2.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/scijava-table-1.0.2.jar with link_type auto
DEBUG 2025-05-01 08:20:31,601: Linking source /Users/talley/.m2/repository/org/scijava/scijava-table/1.0.2/scijava-table-1.0.2.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/scijava-table-1.0.2.jar with link_type hard
DEBUG 2025-05-01 08:20:31,601: Relevant mvn output: [INFO]    org.scijava:scijava-common:jar:2.89.0:compile -- module org.scijava [auto]
DEBUG 2025-05-01 08:20:31,601: Linking source /Users/talley/.m2/repository/org/scijava/scijava-common/2.89.0/scijava-common-2.89.0.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/scijava-common-2.89.0.jar with link_type auto
DEBUG 2025-05-01 08:20:31,601: Linking source /Users/talley/.m2/repository/org/scijava/scijava-common/2.89.0/scijava-common-2.89.0.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/scijava-common-2.89.0.jar with link_type hard
DEBUG 2025-05-01 08:20:31,601: Relevant mvn output: [INFO]    org.scijava:parsington:jar:3.0.0:compile -- module org.scijava.parsington [auto]
DEBUG 2025-05-01 08:20:31,601: Linking source /Users/talley/.m2/repository/org/scijava/parsington/3.0.0/parsington-3.0.0.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/parsington-3.0.0.jar with link_type auto
DEBUG 2025-05-01 08:20:31,601: Linking source /Users/talley/.m2/repository/org/scijava/parsington/3.0.0/parsington-3.0.0.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/parsington-3.0.0.jar with link_type hard
DEBUG 2025-05-01 08:20:31,601: Relevant mvn output: [INFO]    org.bushe:eventbus:jar:1.4:compile -- module eventbus (auto)
DEBUG 2025-05-01 08:20:31,601: Linking source /Users/talley/.m2/repository/org/bushe/eventbus/1.4/eventbus-1.4.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/eventbus-1.4.jar with link_type auto
DEBUG 2025-05-01 08:20:31,601: Linking source /Users/talley/.m2/repository/org/bushe/eventbus/1.4/eventbus-1.4.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/eventbus-1.4.jar with link_type hard
DEBUG 2025-05-01 08:20:31,602: Relevant mvn output: [INFO]    org.scijava:scijava-optional:jar:1.0.1:compile -- module org.scijava.optional [auto]
DEBUG 2025-05-01 08:20:31,602: Linking source /Users/talley/.m2/repository/org/scijava/scijava-optional/1.0.1/scijava-optional-1.0.1.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/scijava-optional-1.0.1.jar with link_type auto
DEBUG 2025-05-01 08:20:31,602: Linking source /Users/talley/.m2/repository/org/scijava/scijava-optional/1.0.1/scijava-optional-1.0.1.jar to target /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/scijava-optional-1.0.1.jar with link_type hard
DEBUG 2025-05-01 08:20:31,602: class path: /Users/talley/.jgo/black.ninia/jep/RELEASE/598a6cd55c0501d03b71b81bc3431f66189c760bf00c14fed5e4f9e4b66a9b83/*
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Fatal Python error: Failed to import encodings module
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000001716a3000 (most recent call first):
  <no Python frame>

that's probably not the flaky bit right? looks like a poor setup of the python environment

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlambert03

tlambert03 commented May 1, 2025

Copy link
Copy Markdown
Collaborator Author

i think i see the issue, i'll work on the jgo ... jep_test.py command directly and see if I can figure out what assumptions it's making about my environment setup

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlambert03
skip in jep
192be35
@tlambert03

tlambert03 commented May 1, 2025

Copy link
Copy Markdown
Collaborator Author

after digging a bit deeper into how jgo and jep itself is working, I'm skipping stubgen tests on jep for now. it seems extremely dependent on some careful manual setup of the python environment. I was able to get it to find my standard library, but then it lost the pure python parts of jep. After fixing that, it was unable to find my (editable) install of scyjava because it's not following .pth files in a standard way. I don't understand all the variables well enough yet (I don't understand who's doing the magic, whether it's jep.Run itself or the jgo command line), so don't know where to attack it

ctrueden reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlambert03
remove setuptools plugin
e714abb
@tlambert03

tlambert03 commented May 1, 2025

Copy link
Copy Markdown
Collaborator Author

code-wise, this is ready to go... however, I don't expect it to be "human-interpretable" yet. There are many ways we could choose to document this and encourage/discourage its usage in various scenarios. Might be best to have a zoom about it so we can tinker with it together and discuss

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@imagesc-bot

imagesc-bot commented May 19, 2025

Copy link
Copy Markdown

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/fiji-friends-weekly-dev-update-thread/103718/94

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@imagesc-bot

imagesc-bot commented Jun 3, 2025

Copy link
Copy Markdown

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/poll-which-priorities-are-most-urgent-for-fijis-python-support/113172/1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ctrueden

ctrueden commented Aug 15, 2025

Copy link
Copy Markdown
Member

Just a quick update: I removed the testing of jep mode awhile back, so that should no longer gum up the works here. @tlambert03 I'm hoping we can make a little time to revisit this PR some time next week.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlambert03

tlambert03 commented Aug 15, 2025

Copy link
Copy Markdown
Collaborator Author

yes that would be great! i do think a little chat would be super useful here

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlambert03
Merge branch 'main' into stubs
e7bc894
@tlambert03

tlambert03 commented Aug 20, 2025

Copy link
Copy Markdown
Collaborator Author

Writing some notes to self here (after having not looked at it for a while) that might help others understand what's going on here. This PR...

  • adds a new CLI command called scyjava-stubgen. It's worth mentioning this is the first CLI command offered by scyjava (i.e. this PR adds project.scripts to pyproject.toml for the first time). This command can be used to generate type stubs for any maven endpoint, for example: scyjava-stubgen org.scijava:parsington:3.1.0.

  • That CLI command just parses the arguments and calls the function scyjava._stubs.generate_stubs. (generate_stubs is a good candidate for a public function but I haven't touched the scyjava public API yet). Importantly, when called via the CLI it writes stubs by default to scyjava.types namespace itself. In other words it permantently writes stub files inside of the scyjava package (this could have permissions issues on some computers). For example, that parsington call above would create scyjava.types.org.scijava.parsington...

  • After running that command (and having generated stubs) you can now import those stubs directly from the namespace:

    from scyjava.types.org.scijava.parsington import Function

    with full static type support in IDEs. Which is great! that's the main goal here. 🎉

  • The important question to ask here, of course, is "when is the JVM started". That import alone does not start the JVM, instead, it returns a thin Proxy object that will start the JVM when an instance of that class is created (i.e. in the __new__ method). The logic for that is defined in scyjava._stubs.setup_java_imports. (That setup_java_imports function is used heavily by the generated type stubs, it generates the module level __getattr__ function that returns the Proxy objects imported from scyjava.types...)

  • an important detail here (as usual) is that all things would need to be imported before any of them are instantiated

open questions:

to me, the biggest open question here is "who is responsible for generating stubs, and where do they go?".

possibilities include:

  1. after the environment and scyjava is setup. the user could call that command line argument. That's fine and good, but not "portable" since it requires action after pip install to get the type stubs.
  2. Which brings the second part of this PR (which should probably be broken into a new PR), which are hatch and setuptools plugins to allow developers to build and include stubs in their own packages. More on that elsewhere
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlambert03

tlambert03 commented Aug 20, 2025

Copy link
Copy Markdown
Collaborator Author

after talking with @ctrueden ... something I will try to implement:

  1. implement a sys.meta_path importer that sees imports from scyjava.types and dynamically generates types
  2. implement a entry-point specification that allows packages to declare which endpoints they need (in order to generate dynamically imported types)

for this PR I will pull out everything by the stub generating mechanism, and do the above in another PR

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tlambert03 added 3 commits August 22, 2025 19:17
@tlambert03
remove hatch plugin
a18d9d9
@tlambert03
newlines
b53e795
@tlambert03
update docs
ed0add6
@tlambert03

tlambert03 commented Aug 22, 2025

Copy link
Copy Markdown
Collaborator Author

ok @ctrueden, I think this is ready for final review. I've removed the hatch/setuptools plugins, and double checked all the documentation. will follow up on usage patterns in another PR. Let me know if you have any questions!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlambert03 tlambert03 mentioned this pull request Aug 23, 2025
scyjava.types metafinder #86
Draft
@tlambert03

tlambert03 commented Nov 29, 2025

Copy link
Copy Markdown
Collaborator Author

@ctrueden, any thoughts on this step? I think it stands alone as useful, without imposing/deciding too much on who is going to use it

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ctrueden

ctrueden commented Dec 2, 2025

Copy link
Copy Markdown
Member

@tlambert03 Yes, sorry! I started working on a revamp of jgo a few days ago, and it's been eating my entire brain. I will try to review and merge this PR this week!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ctrueden ctrueden self-assigned this Dec 2, 2025
@ctrueden

ctrueden commented Dec 9, 2025

Copy link
Copy Markdown
Member

Just a quick followup to say that I'm looking at this today. I am also considering whether this feature would be best in scyjava or jgo. It will definitely land somewhere, hopefully today.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tlambert03

tlambert03 commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator Author

Yeah I think it could still easily live anywhere... the only thing that might eventually pin it somewhere is a decision to establish a shared public namespace like "scyjava.types". Which is still a big question mark anyway (ie, it make stay forever as a local dev tool)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ctrueden and others added 3 commits December 9, 2025 21:24
@ctrueden @claude
Rewrite type references in stubs to include prefix
4f54611
Stubs are placed in the scyjava.types namespace by default,
but have imports with a toplevel namespace; for example,
when generating stubs for org.scijava:scijava-common, the file:

    src/scijava/types/org/scijava/__init__.pyi

would declare imports:

    import java.lang
    import java.util

    import org.scijava.annotations
    import org.scijava.app
    import org.scijava.cache
    import org.scijava.command

and so on. But these imports yield errors when browsing in an IDE,
and prevent the type checker from resolving all the types properly.

This commit makes the following changes to address the problem:

- Add a python_package_prefix parameter to generate_stubs() function
- Add a _rewrite_stub_imports() function that:
  - Rewrites import foo.bar.X → import {python_package_prefix}.foo.bar.X
  - Rewrites type references similarly to have the python_package_prefix
- Update the CLI to automatically pass
  python_package_prefix="scyjava.types" when using the default location
- If --output-python-path gives a different prefix, use that instead
- Add a new test_stubgen_type_references to validate rewriting behavior

So then the following example above gets rewritten to be:

    import java.lang
    import java.util

    import scyjava.stubs.org.scijava.annotations
    import scyjava.stubs.org.scijava.app
    import scyjava.stubs.org.scijava.cache
    import scyjava.stubs.org.scijava.command

Note that the java.lang and java.util imports are not rewritten,
because they are not among the classes whose stubs are being generated.

With this change, IDEs now autocomplete expressions involving these Java
classes correctly, even when chained; for example:

    import scyjava.stubs.org.scijava.Context

    Context().getServiceIndex().getA

shows getAll as a valid completion, because getAll() is a member method
of a supertype of ServiceIndex, the class returned by getServiceIndex().
Before this patch, such chained type completions did not work.

Co-authored-by: Claude <[email protected]>
@ctrueden
Fix typo: _get_ouput_dir -> _get_output_dir
6783f57
@ctrueden
Fix printf-style string syntax typo
fb8c3ef
@ctrueden

ctrueden commented Dec 10, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

OK, after reflecting on it, this work is much more suitable here in scyjava than it would be in jgo. The jgo project does not depend on jpype, whereas scyjava is, in a nutshell, unioning the benefits of jgo and jpype. (And now with the stub generation: +stubgenj as well) The only other places I could imagine this work to go would be one of jpype or stubgenj—but we can always explore pushing it upstream later after we run it through its paces.

So, in testing this work, I ran into problems making the type completions work in VSCode and PyCharm. The issue was a mismatch between the prefixed classes e.g. scyjava.types.org.scijava.Context that get stubified with stubgenj's assumption that the Python class names will match the Java class names in the toplevel Python namespace.

Or to put it another way: the stub file at e.g. src/scyjava/types/org/scijava/__init__.pyi had imports beginning with import org.scijava., rather than import scyjava.types.org.scijava.. So the type reasoning logic would have problems, like hitting dead ends for every method return type. So you couldn't type e.g.:

from scyjava.types.org.scijava import Context
from scyjava.types.org.scijava.ui import UIService
ctx = Context()
ui = ctx.service(UIService).show<ctrl+space>

and see the UIService's show methods.

With 4f54611, this now works, because all the type references in the stubs now get rewritten to have the proper Python package prefix preceding the Java code's own package prefix.

@tlambert03 I'm not actually sure though: is the above code how you intended this feature to be used? Or did you want to write:

from org.scijava import Context
from org.scijava.ui import UIService
ctx = Context()
ui = ctx.service(UIService).show<ctrl+space>

without the scyjava.types Python package prefixes? If the latter, we would need to generate the stubs at the top level src, not at src/scyjava/types, right?

Secondly: there remains an issue with core Java classes: this commit does not rewrite imports like import java.lang to import scyjava.types.java.lang. I think maybe it should, but wanted your opinion.

Thirdly: due to my lack of knowledge in this area, I leaned rather heavily on Claude to write this patch, and it may have errors or stupidities. What do you think? Are we on the right track here?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ctrueden ctrueden

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@tlambert03 @ctrueden @imagesc-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.