Expected Behavior: Importing the module works without bundling Package Metadata in application
Actual Behavior: Stripping Package Metadata breaks imports
Cause:
The pattern of directly using importlib.metadata to set the version assumes that package metadata is included in the location where the package is being used.  As a result, this breaks when using slimmed down deployment artifacts, as package metadata is not bundled.  I have seen a standard approach to this to be to wrap this self-referential version within a try/except block, e.g.
try:
    __version__ = version("annotated-doc")
except Exception:
    __version__ = "unknown" 
https://github.com/fastapi/annotated-doc/blob/7dd21fb75ea6882caf79725881690551ab28c5ff/src/annotated_doc/__init__.py#L5C1-L5C39