packaging.python.org icon indicating copy to clipboard operation
packaging.python.org copied to clipboard

Add importlib.metadata as an approach in "Single-sourcing the package version"

Open chrahunt opened this issue 6 years ago • 3 comments

The current version of "Single-sourcing the package version" has an example using pkg_resources. It would probably make sense to include an item using importlib.metadata since it will be standard in 3.8+ with a backport as importlib_metadata and can serve the same purpose. That may look like

from importlib_metadata import version

__version__ = version(__package__)

chrahunt avatar May 07 '19 17:05 chrahunt

I think this issue can be closed as it is already handled in 3c7c07f135303896a8c13a14697e136c99d4237b (and followup tweaks)

soxofaan avatar Apr 01 '22 11:04 soxofaan

I think the documentation could be improved; looking at option 5 in https://packaging.python.org/en/latest/guides/single-sourcing-package-version/, I don't actually see a complete example of this technique.

bhrutledge avatar Apr 01 '22 22:04 bhrutledge

I suggest that we close this out and file a separate issue for improving the option 5 to de-emphasize pkg_resources and prefer importlib.metadata on 3.8+.

pradyunsg avatar Jun 18 '22 20:06 pradyunsg