deprecate `__version__`
davidism opened this issue · 4 comments
The __version__
attribute is an old pattern from early in Python packaging. Setuptools eventually made it easier to use the pattern by allowing reading the value from the attribute at build time, and some other build backends have done the same.
However, there's no reason to expose this directly in code anymore. It's usually easier to use feature detection (hasattr
, try/except
) instead. importlib.metadata.version("werkzeug")
can be used to get the version at runtime in a standard way, if it's really needed.
Reported to Sentry here: getsentry/sentry-python#2316
Hello @davidism ,
I'm new to contributing to this repo & worked on addressin deprecation of version as per this issue. After removing version attribute, I tried to install Flask in editable mode with pip install -e . but faced an error. Below is snippet of the error for reference, build tool is expecting a version string. I'm unsure about how to proceed to smooth packaging and installation processes without the version attribute. Any suggestions on the best approach to take?
File "/private/var/folders/s0/7jlcj_t57vz0r3bnk_wz3jx40000gq/T/pip-build-env-x3a6o9q7/overlay/lib/python3.11/site-packages/flit_core/common.py", line 251, in check_version
raise NoVersionError('Cannot package module without a version string. '
flit_core.common.NoVersionError: Cannot package module without a version string. Please define a `__version__ = "x.y.z"` in your module.
[end of output]
I guess this wasn't clear, but this isn't an issue we we looking for a contributor for. For one thing, this didn't say remove, this says deprecate, which is a different process. I've already done this, just haven't made a PR yet.
Thanks for the clarification. I misunderstood the goal of the issue. The phrasing "there's no reason to expose this directly in code anymore" thought me to believe that it might be a good idea to remove version. I see now that intention was to deprecate it rather than remove it outright.
I am eager to learn, contribute more effectively to the project. If there are other areas or issues where I can help, please let me know @davidism