PKuK\`iversions/__init__.py"""A cell magic command for IPython/Jupyter to display name and version of the imported modules""" __version__ = "0.0.1" __all__ = ['iversions'] from .iversions import IVersions def load_ipython_extension(ipython): ipython.register_magics(IVersions) PKtKHZZiversions/iversions.py#!/usr/bin/env python # -*- coding: utf-8 -*- # Aziz Alto # Aug. 26, 2017 """ iversions is a simple cell magic command for IPython/Jupyter, to display name and version of all imported modules (non built-in) in the current environment. Usage: after loading it `%load_ext iversions` and importing some modules, just type: %iversions Note: Currently, it does not work with non-module imports `from X import Y` :( """ from sys import version_info as ver_info import types from datetime import datetime PYTHON_VER = '.'.join(map(str, [ver_info.major, ver_info.minor, ver_info.micro])) def now(): return datetime.strftime(datetime.now(), '%a %b %d, %Y %H:%M:%S %Z') def imports(vars): """ a generator over the imported modules in vars :param vars: globals() or locals() see https://stackoverflow.com/a/4858123/2839786 """ for val in list(vars.values()): if isinstance(val, types.ModuleType): yield val def imports_versions(modules): """ :param modules: a list of modules (types.ModuleType) :return: dict, {module_name: version_number} """ vers = {} for module_ in modules: try: vers[module_.__name__] = module_.__version__ except AttributeError: # built-ins will be excepted continue return vers.items() def print_versions(symbol_table=locals()): imported = imports(symbol_table) for k, v in imports_versions(imported): print('{:<10} {}'.format(k, v)) print('\nPython {} [{}]'.format(PYTHON_VER, now().strip())) # notebook cellmagic interface from IPython.core.magic import Magics from IPython.core.magic import magics_class from IPython.core.magic import line_magic, register_line_magic, cell_magic @magics_class class IVersions(Magics): @line_magic def iversions(self, line): """ Display name and version of the imported modules in current environment. Usage: import some modules, just type %iversions enjoy :-) """ print_versions(self.shell.user_ns) PKhK(ld44!iversions-0.0.1.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2017 Aziz Alto Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!H١Wdiversions-0.0.1.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,Q0343 /, (-JLR()*M ILR(4KM̫#DPK!HH@S|q"iversions-0.0.1.dist-info/METADATATn@}@";.T RMNx/m/<3sN̞> 9lcDyQ)69q) _%. euq8 k0,ߠ&n:v4%@qAL+QgC>W2?%W^"?ʥО/Ɠ/cFH% ⲢZ ƩjUjfx]qe)A;NsLG8֙Hgm`6vn;4%QV'Pf5D5#UYܯZi8.<$-v2aex1wmPC; Gm2clW*Vo\Yۺ'z?AYx/NHYNP $,k:;cIݞ1f4jN IO1I~]한\͉Yڡz^*Yqdk >=y7>XSڬف1/YCxɵyq]O8VӰ(c)xN71܉_Wc] hMoc{ENcaPD b[:jPK!HK? ) iversions-0.0.1.dist-info/RECORD}=w0"0t@~TPp,Dă_.Nnwz=/O'miJrMS"$^:}φ3yl!Iu!QYws ڈ<5 6کWH_t.lwzf`?ܖίu 7_exϟUYb*rhIs(. + Ц/xÜ9 >2;-9l~io/XmCA-iy\9e3j99nu t+g%W-lm[F?PKuK\`iversions/__init__.pyPKtKHZZ4iversions/iversions.pyPKhK(ld44! iversions-0.0.1.dist-info/LICENSEPK!H١Wd5iversions-0.0.1.dist-info/WHEELPK!HH@S|q"iversions-0.0.1.dist-info/METADATAPK!HK? ) ziversions-0.0.1.dist-info/RECORDPK