Neoteroi / BlackSheep

Fast ASGI web framework for Python
https://www.neoteroi.dev/blacksheep/
MIT License
1.88k stars 77 forks source link

query blacksheep version at runtime #362

Closed remdragon closed 1 year ago

remdragon commented 1 year ago

🚀 Feature Request

I was having a lot of trouble with 1.2.12 which was resolved by upgrading to 1.2.14.

I scoured the blacksheep source code but could not find a way to query for this information at runtime.

It would be nice if I could add some startup logic to my app to check for known issues, something like:

assert blacksheep.__version__ != ( 1, 2, 12 ), 'unsupported version of blacksheep, please run "pip install --upgrade blacksheep"'
RobertoPrevato commented 1 year ago

For version 1 of the web framework, I recommend using built-in features to obtain the version at runtime.

Python 3.11.0 (main, Oct 30 2022, 14:13:55) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.get_distribution("blacksheep").version
'1.2.16'
>>> from importlib.metadata import version
>>> version("blacksheep")
'1.2.16'
import pkg_resources
pkg_resources.get_distribution("blacksheep").version
'1.2.16'

from importlib.metadata import version
version("blacksheep")
'1.2.16'

For version 2, I am considering to use the features from pyproject.toml and use a dynamic version.

RobertoPrevato commented 1 year ago

Marked as completed, as the version for v1 can be obtained using the option described above, and v2 (currently still alpha) now uses a dynamic version.