Can you inspect code from "own" package with importlib.metadata?

Viewed 31

I have a wheel-packaged web application which gets installed into the active environment.

Inside of that package I want to access the version of itself via importlib.metadata so I don't have to rely on some convention like providing a __version__ object at the packages's root.

Is that possible? Currently I can only read the version of other packages installed in this particular environment, following the description in https://docs.python.org/3/library/importlib.metadata.html

For example: If this code below is packaged in a wheel with version 0.1.1 then self_version should be 0.1.1.

from importlib.metadata import version  

# How to determine 'the_name_of_the_package_this_code_runs_in'?
# Is there another way?
self_version = version('the_name_of_the_package_this_code_runs_in')
0 Answers
Related