Skip to content

Commit

Permalink
CI: Use pkg_resources to list installed dependencies (nilearn#2228)
Browse files Browse the repository at this point in the history
* CI: Use pkg_resources to list installed dependencies

* Moved non-exception raising code to else block
  • Loading branch information
effigies authored and kchawla-pi committed Nov 25, 2019
1 parent 692d778 commit 3edd555
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions continuous_integration/show-python-packages-versions.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import sys
import pkg_resources

DEPENDENCIES = ['numpy', 'scipy', 'scikit-learn', 'joblib', 'matplotlib',
'nibabel']


def print_package_version(package_name, indent=' '):
try:
package = __import__(package_name)
version = getattr(package, '__version__', None)
package_file = getattr(package, '__file__', )
provenance_info = '{0} from {1}'.format(version, package_file)
except ImportError:
dist = pkg_resources.get_distribution(package_name)
except pkg_resources.DistributionNotFound:
provenance_info = 'not installed'
else:
provenance_info = '{0} installed in {1}'.format(dist.version,
dist.location)

print('{0}{1}: {2}'.format(indent, package_name, provenance_info))


if __name__ == '__main__':
print('=' * 120)
print('Python %s' % str(sys.version))
Expand Down

0 comments on commit 3edd555

Please sign in to comment.