forked from justinmayer/django-autoslug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_version_helper.py
28 lines (24 loc) · 920 Bytes
/
_version_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import inspect
import io
import os
__all__ = ['__version__']
# A simple `from autoslug import __version__` would trigger a cascading import
# of `autoslug.fields`, then `django`. As the latter may not be available
# (being a dependency), we try to work around it.
#
# Cases:
# 1) building the package with a global interpreter and no dependencies
# installed globally;
# 2) building documentation e.g. on RTFD server (no Django settings available
# on runtime);
# 3) installing django-autoslug before Django itself (highly unlikely).
#
__version__ = None
thisfile = inspect.getfile(inspect.currentframe())
path = os.path.join(os.path.abspath(os.path.dirname(thisfile)), 'autoslug/__init__.py')
with io.open(path, encoding='utf8') as f:
for line in f:
if line.startswith('__version__'):
exec(line)
break
assert __version__, 'autoslug.__version__ must be imported correctly'