Skip to content

Catch all exceptions getting version from VCS, fallback to importlib#1972

Merged
flying-sheep merged 2 commits into
scverse:mainfrom
rgoya:catch_all_exceptions_getting_version
Apr 29, 2025
Merged

Catch all exceptions getting version from VCS, fallback to importlib#1972
flying-sheep merged 2 commits into
scverse:mainfrom
rgoya:catch_all_exceptions_getting_version

Conversation

@rgoya
Copy link
Copy Markdown
Contributor

@rgoya rgoya commented Apr 20, 2025

This closes #1960.

anndata developers are using hatch build tool with a hatchling backend and relying on the hatch project configuration to make sure the version is up to date. However, the chosen approach can generate conflicts when the user has a pyproject.toml file of their own (see #1960).

This PR makes sure to catch all exceptions generated while trying to read the dev configuration and fall back to importlib. Additionally, as a safeguard, even if hatchling can parse and provide the data from the pyproject.toml, we will fallback to importlib if the project found does not match the expected project name.

The project name is placed as a private constant so that it can be ported to other scverse tools that need it.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.07%. Comparing base (089ed92) to head (657cc3d).
⚠️ Report is 38 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1972      +/-   ##
==========================================
- Coverage   87.13%   85.07%   -2.07%     
==========================================
  Files          47       47              
  Lines        6848     6852       +4     
==========================================
- Hits         5967     5829     -138     
- Misses        881     1023     +142     
Files with missing lines Coverage Δ
src/anndata/_version.py 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

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

@rgoya rgoya marked this pull request as ready for review April 21, 2025 00:13
@rgoya
Copy link
Copy Markdown
Contributor Author

rgoya commented Apr 26, 2025

@flying-sheep , a gentle poke on this PR.

You mentioned you were over the versioning thing; however, not being familiar with how your dev/build process looks like, I didn't feel confident removing the hatchling code.

Instead, the code here:

  • adds some guardrails to ensure the right data is being accessed (e.g. if pyproject.toml is found, make sure it is anndata's), and
  • ensures that if the hatchling related versioning fails for any reason, it fallbacks to importlib (e.g. silently catching known exceptions, and unknown exceptions with a warning).

@flying-sheep
Copy link
Copy Markdown
Member

Hi! Yeah, that looks wonderful and thorough. The decision of keeping or removing the whole thing can happen independently from making it more robust!

Thank you

@flying-sheep flying-sheep merged commit b860cdb into scverse:main Apr 29, 2025
18 of 22 checks passed
flying-sheep pushed a commit that referenced this pull request Apr 29, 2025
@scverse scverse deleted a comment from lumberbot-app Bot Apr 29, 2025
flying-sheep added a commit that referenced this pull request Apr 29, 2025
…lback to `importlib` (#1977)

Co-authored-by: Rodrigo Goya <rgoya@users.noreply.github.com>
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.

Latest anndata (v0.11.4) fails to import after trying and failing to get data from pyproject.toml

2 participants