Skip to content

Conversation

@tlambert03
Copy link
Collaborator

@tlambert03 tlambert03 commented Apr 20, 2025

this PR adds logic to automatically setup a competent java environment (with a JRE and maven) if one is not already available and cjdk is installed (either manually, or via the new scyjava[cjdk] extra). The goal is to enable someone to simply pip install scyjava[cjdk], without having java or maven installed on their system, and have it just work.

there is a new fetch_java argument to start_jvm, which:

  • if None (default), will try to fetch a JRE and maven iff cjdk is importable.
  • if True, will raise an exception if cjdk is not available.
  • if False, will fall back to the current behavior of letting an exception raise up if a JVM or maven is unavailable.

happy to change those defaults too!

(note: this work came from tlambert03/bffile#3 ... but it seems like it might be reasonable to have here too)

@ctrueden ctrueden force-pushed the auto-java branch 3 times, most recently from f762cfe to 34bfae2 Compare April 20, 2025 23:57
@codecov
Copy link

codecov bot commented Apr 20, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 52.72%. Comparing base (1e54c4b) to head (34bfae2).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/scyjava/_jvm.py 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #80      +/-   ##
==========================================
- Coverage   52.88%   52.72%   -0.17%     
==========================================
  Files          12       12              
  Lines        1299     1303       +4     
==========================================
  Hits          687      687              
- Misses        612      616       +4     

☔ 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.

@ctrueden ctrueden force-pushed the auto-java branch 2 times, most recently from 71ef66b to ece66ce Compare April 21, 2025 00:19
* Include java version in job names, to disambiguate them.
* As a hack for now, just fail if Java >= v17 or <8.
@ctrueden
Copy link
Member

Thanks, @tlambert03 !!

Getting the CI to pass was "fun"—even though actions/setup-java is skipped in the add-on job, openjdk 17 is still available for some reason. So the cjdk-related features may not even be getting exercised by that job. But scyjava's jep mode tests were dying with that mystery openjdk 17, maybe due to JPMS reflection rules being tightened (I'm not sure, but seems plausible to me). So for now I just added a hack to skip the jep tests when java -version isn't in the range 1.8 thru 16.

I'm not sure how I feel about the extra; cjdk is such a small dependency that I'd be inclined to just leave it as a regular ol' dep and dispense with some of the case logic here, knowing it's always available. Would you be OK with that?

@tlambert03
Copy link
Collaborator Author

the cjdk-related features may not even be getting exercised by that job

Ah, that's interesting.

I can say that I'm confident locally that removing either maven or java does exercise the logic, but yeah: I hadn't yet confirmed for myself on my other PR that removing the setup action actually left the system java-less.

I'd be inclined to just leave it as a regular ol' dep and dispense with some of the case logic here, knowing it's always available. Would you be OK with that?

Absolutely, just didn't want to assume. Also, feel free to change the bool | None nature of the fetch_java argument too, to make it only bool (I can do that too). And let me know what default you prefer.

Lastly... I'm curious about your replacement of pipe with Union, even with the __future__ import. Is that a personal preference?

@ctrueden
Copy link
Member

I'm curious about your replacement of pipe with Union, even with the future import. Is that a personal preference?

Oh, no, I was just trying to fix an error regarding the bool | None syntax when using Python 3.8:

$ cat go.py
def go(a: bool | None) -> None:
    print("Hello")

go(True)
$ python go.py
Traceback (most recent call last):
  File "go.py", line 1, in <module>
    def go(a: bool | None) -> None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

But I have since learned—while troubleshooting setuptools's breaking change to the license field of pyproject.toml—that setuptools 77.0.0 does not work with Python 3.8. So if I want to make uv build work, I need to bump to python 3.9 as minimum anyway. ☹️ So we could restore the bool | None syntax, since it is more elegant.

@tlambert03
Copy link
Collaborator Author

tlambert03 commented Apr 21, 2025

... but you can still use the pipe on 3.8 as long as you have from __future__ import annotation ... since that tells the parser to interpret all type hints as strings... therefore making even newer syntax technically valid (even if you'd never be able to resolve the ForwardRef at runtime on 3.8). So, the general rule is, if you don't care about runtime type checking (and you don't care about running mypy using python 3.8) then you can still use the pipe

... so in your example, add from __future__ import annotations to the beginning of go.py

@tlambert03
Copy link
Collaborator Author

i just pushed an update including cjdk by default, and making fetch_java: bool = True by default

And bump the minimum Python version to 3.9, since that version of
setuptools requires it.

And raise the test ceiling from Python 3.12 to 3.13.
@tlambert03
Copy link
Collaborator Author

thanks for considering this PR. the prospect of not having to require end users to install java separately definitely makes me happy! :)

@ctrueden ctrueden merged commit 1a8a1a7 into scijava:main Apr 21, 2025
9 checks passed
@tlambert03 tlambert03 deleted the auto-java branch April 21, 2025 01:28
@ctrueden
Copy link
Member

the prospect of not having to require end users to install java separately definitely makes me happy! :)

Me too! 😸

Future steps:

  • Add logic at the jgo layer to use cjdk to do this, and update scyjava to simply lean on that.
  • Also at the jgo layer, finish my pure-Python Maven dependency resolver, so that Maven does not need to be installed, either.

In the meantime, for scyjava on conda-forge: I guess we should probably get cjdk onto conda-forge as well, so that the conda dependencies are better aligned...

@tlambert03
Copy link
Collaborator Author

Yep, I’ll handle cjdk on conda forge

@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 added a commit to ctrueden/scyjava-feedstock that referenced this pull request Apr 23, 2025
* Remove openjdk and maven dependencies in favor of cjdk instead; see:
  - scijava/scyjava#80
  - scijava/scyjava@5753a59

* Update python and setuptools minimum versions; see:
  - scijava/scyjava@0af3f65

* Remove jpype1 and jgo from build dependencies.
  This is a pure Python project, and should not need
  these runtime dependencies to build the package.

* Document why there is a JPype upper bound.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants