forked from WojtekWeclewski/workshop-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__version__.py
31 lines (25 loc) · 836 Bytes
/
__version__.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
29
30
31
""" # doctest: +SKIP_FILE
>>> sys.tracebacklimit = 0
>>> assert sys.version_info > (3, 8, 0), \
'Python 3.8+ is required'
>>> assert 'VIRTUAL_ENV' in os.environ, \
'Please make sure you are using venv environment.'
"""
import os
import sys
import importlib
import re
print(f'Python:', sys.version[:6])
print(f'Venv:', 'VIRTUAL_ENV' in os.environ)
with open('requirements.txt') as file:
for line in file:
module_name = r.group() if (r := re.search(r'^[\w_\-]+', line)) else None
if not module_name:
continue
try:
module = importlib.import_module(module_name)
except Exception as err:
print(f'{module_name}: {err.__class__.__name__}')
else:
version = getattr(module, '__version__', 'unknown')
print(f'{module_name}: {version}')