forked from scikit-image/scikit-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_versions.py
executable file
·38 lines (30 loc) · 1.27 KB
/
build_versions.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
32
33
34
35
36
37
38
#!/usr/bin/env python
from pathlib import Path
import pkg_resources
import re
def main():
requirements_dir = Path(__file__).parent / '..' / 'requirements'
for requirement_file in requirements_dir.glob('*.txt'):
print(requirement_file.name)
with open(str(requirement_file), 'r') as f:
for req in f:
# Remove trailing and leading whitespace.
req = req.strip()
if not req:
# skip empty or white space only lines
continue
elif req.startswith('#'):
continue
# Get the name of the package
req = re.split('<|>|=|!|;', req)[0]
try:
# use pkg_resources to reliably get the version at install
# time by package name. pkg_resources needs the name of the
# package from pip, and not "import".
# e.g. req is 'scikit-learn', not 'sklearn'
version = pkg_resources.get_distribution(req).version
print(req.rjust(20), version)
except pkg_resources.DistributionNotFound:
print(req.rjust(20), 'is not installed')
if __name__ == '__main__':
main()