Allow me to deviate from your actual question to offer what I thing is a better solution.
If you have to get the package version while developing (from an outside script) then you should split such information from your setup.cfg
/setup.py
.
You want setup.cfg
(i.e, setuptools) to get that information from a file, for instance. Then, you can have the version just by reading the corresponding file.
Check the docs for details: https://setuptools.pypa.io/en/latest/userguide/declarative_config.html. Notice the #meta-1
anchor/note in that page.
Basically, you'll use attr
or file
attributes (in your setup.cfg
metadata section) to get the version from another place:
version = file: VERSION.txt