Skip to content

Import __version__ from package metadata to avoid mismatches#53

Merged
LourensVeen merged 2 commits into
developfrom
issue_48_broken_package_version
Jun 12, 2026
Merged

Import __version__ from package metadata to avoid mismatches#53
LourensVeen merged 2 commits into
developfrom
issue_48_broken_package_version

Conversation

@LourensVeen

Copy link
Copy Markdown
Contributor

I tried using setuptools-scm to get the version, but it turns out that that doesn't work with git-flow. Or at least, it'll work for releases, but for e.g. something on develop it will give an odd version because the latest release's tag is not an ancestor.

I think that that could be worked around with a custom setuptools-scm plugin, but that's a bit too complicated for now.

This keeps the version in pyproject.toml and requires manual changes, but at least the ymmsl.__version__ now comes from the metadata and doesn't have to be synchronised by hand.

Addresses #48

@LourensVeen LourensVeen requested a review from maarten-ic June 3, 2026 19:52
@LourensVeen LourensVeen self-assigned this Jun 3, 2026

@maarten-ic maarten-ic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

doesn't work with git-flow. Or at least, it'll work for releases, but for e.g. something on develop it will give an odd version because the latest release's tag is not an ancestor.

Ah, right, that's because of the github-specific annoying thing that any merge (even if it could be a fast-forward merge) gets a merge commit.
So merging develop -> master will push a new commit onto master, which gets the tag on release. The master and develop branch are now diverged and the tag is not in the commit history on develop... 🙁

Either way: one comment on the changes, otherwise good to merge!

Comment thread ymmsl/__init__.py Outdated
This package contains all the classes needed to represent a yMMSL file,
as well as to read and write yMMSL files.
"""
import importlib

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
import importlib
import importlib.metadata

Perhaps it now works because someone (perhaps third party dependency?) already imported the metadata submodule, but in a fresh python session this gives an error:

>>> import importlib
>>> importlib.metadata
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'importlib' has no attribute 'metadata'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks, I'll fix that and test it!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a funny one. It appears that importing something imports importlib and makes

import importlib
importlib.metadata

work, but if you do it before importing anything then it doesn't. So

import ymmsl
print(ymmsl.__version__)

actually works for me even with the original version, probably because import ymmsl loads importlib before loading ymmsl/__init__.py and trying to resolve the import in there.

Of course it's still wrong, so I fixed it anyway and tested both in isolation and in the actual code that it now works.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! Just did a quick check and ymmsl.v0_2.resolver imports importlib.metadata, so that's why it was available before 😉

@LourensVeen

Copy link
Copy Markdown
Contributor Author

It's a git-flow thing actually, I'm doing it exactly as prescribed. Anyway, this'll work for now, and I'll fix the import, thanks!

@LourensVeen LourensVeen merged commit 4c614a1 into develop Jun 12, 2026
15 checks passed
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.

2 participants