Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add object introspection functions #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Apr 29, 2025
Merged

Add object introspection functions #78

merged 41 commits into from
Apr 29, 2025

Conversation

ctrueden
Copy link
Member

@ctrueden ctrueden commented Apr 2, 2025

This PR is a continuation of #77, targeting the mainline branch, and cleaning up the commit history.

@ctrueden ctrueden self-assigned this Apr 2, 2025
ctrueden added 5 commits April 2, 2025 14:11
To me, the name `find_java` suggests we will be locating a JVM
installation, rather than "finding" information about Java objects.
The information doesn't need to be "found" or "located", but rather
only introspected or interrogated. Technically, I suppose
"introspection" implies read/access while "reflection" implies
write/mutation, but `jintrospect` is rather clunky, whereas the
term "reflection" is widely known in both Java and Python circles.
@ctrueden
Copy link
Member Author

ctrueden commented Apr 2, 2025

I've done all the technical cleanup work I wanted to do. Tomorrow I'll review the actual code changes in more detail. Based on my initial read-through, it looks pretty fabulous.

@ian-coccimiglio
Copy link
Contributor

ian-coccimiglio commented Apr 3, 2025

Super glad this is coming together.

I'm noticing that it'd be good to find the right way to pass a Scijava Logger onto the sf.sourceLocation() function called by the src() function. I was helping someone on image.sc with OrientationJ on pyImageJ and I was trying to find the source code.

I managed to hack this to work (actually by using the reflection functionality on ij!). And what I found was:

# (With OrientationJ.jar in the classpath)
sf.sourceLocation(jimport("OrientationJ_Analysis"), None).toString() # fails & what we have currently
sf.sourceLocation(jimport("OrientationJ_Analysis"), ij.log()).toString() # works

@imagesc-bot
Copy link

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/84

@imagesc-bot
Copy link

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/87

@ctrueden ctrueden force-pushed the object-introspection branch 2 times, most recently from f3172dd to c8867a3 Compare April 25, 2025 02:36
@ctrueden ctrueden force-pushed the object-introspection branch 3 times, most recently from 5857752 to d23669d Compare April 28, 2025 22:44
* scyjava.fields -> scyjava.inspect.fields
* scyjava.methods -> scyjava.inspect.methods
* scyjava.src -> scyjava.inspect.src

And add new `constructors` and `members` convenience functions.
This code worked:

  import scyjava
  print(scyjava.config)

But this code didn't:

  import scyjava
  print(scyjava.inspect)

Because scyjava.config was being imported in another file
further down the chain. Better to be explicit about wanting
both of these submodules available at the top level.
@ctrueden ctrueden force-pushed the object-introspection branch from d23669d to 7485091 Compare April 29, 2025 01:03
And do not try so hard with exception handling; it should be up to
higher level functions like scyjava.inspect.src to catch such failures.
When invoking scyjava.inspect functions, they can optionally report the
source URL at the top, before printing the members. But this only works
if scijava-search is on the classpath. Let's let the source flag default
to None, in which case it swallows source code URL detection failures
gracefully, to make the common case of scijava-search not being
available work without hassle.

And let's have the various inspect functions accept static and source
boolean flags, which get passed along to the internal _print_data
routine, as was previously the case when they were partial functions.
@ctrueden ctrueden force-pushed the object-introspection branch from 7485091 to 5c06747 Compare April 29, 2025 01:19
@ctrueden ctrueden merged commit f83edfa into main Apr 29, 2025
@ctrueden ctrueden deleted the object-introspection branch April 29, 2025 18:42
@ctrueden
Copy link
Member Author

Thanks again @ian-coccimiglio for spearheading this work!

@ian-coccimiglio
Copy link
Contributor

Glad to be involved!

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

Successfully merging this pull request may close these issues.

3 participants