Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying __version__ using __import__("importlib.metadata") ? #693

Closed
consideRatio opened this issue Nov 1, 2023 · 5 comments
Closed

Comments

@consideRatio
Copy link
Member

consideRatio commented Nov 1, 2023

@bollwyvl made me aware about a strategy to specify __version__ in a way that I've not seen us do in any jupyterhub org package through jupyterhub/jupyter-server-proxy#427 (review).

Currently:

# __version__ should be updated using tbump, based on configuration in
# pyproject.toml, according to instructions in RELEASE.md.
#
__version__ = "4.1.1-0.dev"

With @bollwyvl's suggestion:

__version__ == __import__("importlib.metadata").metadata.version("jupyter_server_proxy")

Is this robust enough to use systematically, reducing the complexity of what tbump or any other tooling is required to accomplish? Should we systematically transition towards this pattern?

@bollwyvl
Copy link

bollwyvl commented Nov 1, 2023

To further expand: ultimately, the complexity is finally removed when there is exactly one source of truth which the python build system and runtime pull from, using only stdlib.

Regarding hatch-nodejs-version in specific: package.json is a good source of truth, as it is fully static, which means you can look across all the millions of package versions on npm and fully rely on them having (valid) version numbers that have been preserved, unchanged, from the source repo. The same cannot be said for PyPI. It is a pity, indeed, that canonical pre-release version strings aren't compatible between pypi and npm. In the case of pyproject.toml and package.jsons, I've found just testing these two values for equivalence, modulo some transformation, gives good enough quality control, vs big rube goldberg contraptions. Heck, during test, i'd pay dearly for something that validated the version, by no-fooling looking at types, etc. to see if a breaking change happened.

Just don't use versioneer 😆

@manics
Copy link
Member

manics commented Nov 1, 2023

Just don't use versioneer 😆

I use setuptools-scm for my (non-js python) projects 🤣

@minrk
Copy link
Member

minrk commented Nov 2, 2023

I think tbump works well, and taking an approach like this doesn't solve a problem that we currently have. I think it's a fine approach to take, but since tbump takes care of it already while also covering the tagging & publishing workflow, it's adding dynamic logic that might be sensitive to unusual things like importing based on PYTHONPATH without installing, etc. where we currently have a simple string that always works.

I use setuptools-scm

I think importlib-metadata is probably a great pair for setuptools-scm, and it even recommends taking this approach, since it's how you have __version__ in sync with what setuptools-scm produced without any build-time steps.

@manics
Copy link
Member

manics commented Nov 2, 2023

@consideRatio Could you say a bit more about the advantages of importlib.metadata? It sounds like it's good when the version is dynamically set, but what are the advantages when it's statically set (by tbump, or anything else)?

@consideRatio
Copy link
Member Author

@consideRatio Could you say a bit more about the advantages of importlib.metadata? It sounds like it's good when the version is dynamically set, but what are the advantages when it's statically set (by tbump, or anything else)?

I don't advocate the approach if there is any possible issues, as tbump does a good job for us handling this. But the minor benefit I see is that our pyproject.toml's configuration of tbump no longer needs one specific entry.

I think tbump works well, and taking an approach like this doesn't solve a problem that we currently have. I think it's a fine approach to take, but since tbump takes care of it already while also covering the tagging & publishing workflow, it's adding dynamic logic that might be sensitive to unusual things like importing based on PYTHONPATH without installing, etc. where we currently have a simple string that always works.

I agree with this thought overall - should we go for a close?

@minrk minrk closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants