Skip to content

Conversation

dangotbanned
Copy link
Member

@dangotbanned dangotbanned commented Sep 15, 2025

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below

(#3130 (comment))

The failure in (#3130 (review)) happens when your venv was installed against a previous version of narwhals.
In this case 2.4.0, which just means you need to reinstall to get (v2.5.0 (release)) 🙂

I also get bitten by that test regularly and was thinking about rewriting it yesterday 😭
We should really be testing against the version that is locally installed - which can be older than pyproject.toml

@dangotbanned dangotbanned marked this pull request as ready for review September 15, 2025 14:23
dangotbanned added a commit that referenced this pull request Sep 15, 2025
Comment on lines 21 to 26
if version != pyproject_version: # pragma: no cover
# NOTE: metadata from venv is outdated (https://github.com/narwhals-dev/narwhals/pull/3130#issuecomment-3291578373)
version_comp = parse_version(version)
assert version_comp < parse_version(pyproject_version)
assert version_comp == parse_version(dist_version)
assert version == dist_version
Copy link
Member

@FBruzzesi FBruzzesi Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand that locally this can be problematic (it happened to me multiple times), I am not sure that working around the test itself is the best solution here.

  • In CI this should never happen, unless we are actually doing something wrong, and if that's the case, we could end up not noticing it.
  • I would suggest to add a message in the current assert that explicitly suggestion why this happens and what to do, something along the lines of:
- assert nw.__version__ == pyproject_version
+ msg = "metadata is out of sync, either ignore this failure locally or re-install narwhals: `uv pip install -e .`"
+ assert nw.__version__ == pyproject_version, msg

Copy link
Member Author

@dangotbanned dangotbanned Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @FBruzzesi

In CI this should never happen, unless we are actually doing something wrong, and if that's the case, we could end up not noticing it.

You make a good point! 😄

Would (2f22890) and (0500e3c) help alleviate this concern?
(provided I've RTFM correctly 😂)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3134 (comment)

I am not sure that working around the test itself is the best solution here

I get that using pyproject.toml provides a proxy value with a different static source (+1).
But as we don't use a lockfile, I don't think it quite fits this definition of assertion

... that always should evaluate to true at that point in code execution

We've both sadly experienced this not being an always - because of how it interacts with -e 😔

So the question for me was:
Is there anything else we can confidently assert, where a failure still indicates a regression?

Given that this is a very thin wrapper around importlib.metadata.version our options are limited:

def __getattr__(name: _t.Literal["__version__"]) -> str: # type: ignore[misc]
if name == "__version__":
global __version__ # noqa: PLW0603
from importlib import metadata
__version__ = metadata.version(__name__)
return __version__

But we can use that to our advantage! To me, that implies the likely points for breakage are:

  1. A future refactor changes how we wrap version
  2. We revert back to not using version

In either case - we'll know that something is wrong because nw.__version__ no longer returns a string that is equal to importlib.metadata.version("narwhals").

Copy link
Member

@FBruzzesi FBruzzesi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dangotbanned 🙏🏼 nice trick for GHA 😉

@dangotbanned dangotbanned merged commit cc69bac into main Sep 16, 2025
25 of 38 checks passed
@dangotbanned dangotbanned deleted the test-fix-version branch September 16, 2025 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants