Fix stardist worker crash: pin setuptools<82 for pkg_resources#144
Merged
Conversation
stardist==0.9.1 imports `from pkg_resources import get_distribution` at
import time (via stardist/__init__.py -> bioimageio_utils.py). setuptools
82.0.0 (released Feb 2026) removed the bundled `pkg_resources` module, so
fresh deployment builds resolved setuptools>=82 and the container crashed
on `import stardist` with:
ModuleNotFoundError: No module named 'pkg_resources'
Pin setuptools<82 in the conda environment so pkg_resources stays
available. This is the layer where setuptools is installed; later pip
steps don't require >=82, so the pin holds through the build.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Regenerated by the update-worker-docs Claude Code hook after PR creation.
download_models.py caught ImportError (and any Exception), printed a traceback, and then exited 0. This swallowed dependency breakage at build time: the setuptools/pkg_resources failure printed in the build logs but the image built "successfully" and only crashed at runtime on `import stardist`, with the models never even cached. Add sys.exit(1) to both handlers so the Docker `RUN python /download_models.py` step fails loudly when stardist can't be imported or the models can't be downloaded. Add tests (runnable with plain pytest, stdlib only) that run the script with a fake `stardist` package shadowing any real install so the import fails deterministically, and assert the script exits non-zero and reports the error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Regenerated by the update-worker-docs Claude Code hook after PR creation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The stardist worker crashed at runtime in the deployment build with:
Root cause
stardist==0.9.1importsfrom pkg_resources import get_distributionat import time —stardist/__init__.pypulls inbioimageio_utils.py, which fails immediately.pkg_resourceswas bundled withsetuptools, but setuptools 82.0.0 (released Feb 2026) removed it entirely.workers/annotations/stardist/environment.ymldid not pinsetuptools, so fresh builds resolved setuptools ≥82 and shipped an image withoutpkg_resources. The image used to build/run fine only because earlier builds happened to get setuptools <82. This is unpinned-transitive-dependency drift.Why the build didn't catch it
download_models.pyruns at build time and doesfrom stardist.models import StarDist2D, so the build touched the broken import — but it wrapped the import inexcept ImportError/except Exceptionthat only printed the traceback and then exited 0. Docker saw a successfulRUN, so the image built and pushed "successfully" (with the models never cached), and the failure only surfaced at runtime.Fixes
setuptools<82in the conda dependencies sopkg_resourcesstays available. This is the layer where setuptools is installed; none of the later pip steps require setuptools ≥82, so the pin holds through the build.download_models.pyexit non-zero on import/download failure, so future dependency drift fails the Docker build loudly instead of shipping a broken image.Tests
Added
workers/annotations/stardist/tests/test_download_models.py(stdlib-only, runs under plain pytest). It runs the script with a fakestardistpackage shadowing any real install so the import fails deterministically, and asserts the script exits non-zero and reports the error. Written test-first (failed against the old swallow-and-exit-0 behavior, passes after the fix).Verification
The
setuptools<82pin itself can't be validated by a local rebuild here (GPU/CUDA worker, not buildable on a Mac dev machine). After the next deployment build, confirm the worker imports cleanly:Sources for the setuptools 82.0.0
pkg_resourcesremoval:pkg_resourcespypa/setuptools#5174🤖 Generated with Claude Code