├── .gitignore ├── flit.ini ├── iversions ├── __init__.py └── iversions.py ├── LICENSE ├── README.rst └── demo.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | dist/* 2 | .DS_Store 3 | __pycache__ 4 | *.pyc 5 | .ipynb_checkpoints 6 | -------------------------------------------------------------------------------- /flit.ini: -------------------------------------------------------------------------------- 1 | [metadata] 2 | module = iversions 3 | author = Aziz Alto 4 | author-email = iamaziz.alto@gmail.com 5 | home-page = https://github.com/iamaziz/iversions 6 | description-file = README.rst 7 | classifiers = License :: OSI Approved :: MIT License 8 | -------------------------------------------------------------------------------- /iversions/__init__.py: -------------------------------------------------------------------------------- 1 | """A cell magic command for IPython/Jupyter to display name and version of the imported modules""" 2 | 3 | __version__ = "0.0.10" 4 | __all__ = ['iversions'] 5 | 6 | from .iversions import IVersions 7 | 8 | def load_ipython_extension(ipython): 9 | ipython.register_magics(IVersions) 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Aziz Alto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | iversions 2 | ^^^^^^^^^ 3 | 4 | A cell magic command for IPython/Jupyter to display name and version of 5 | all imported (non built-in) modules in the current session. 6 | 7 | Installation 8 | ^^^^^^^^^^^^ 9 | 10 | .. code:: bash 11 | 12 | $ pip install iversions 13 | 14 | Usage 15 | ^^^^^ 16 | 17 | .. code:: python 18 | 19 | In [1]: %load_ext iversions 20 | 21 | In [2]: import numpy as np 22 | ...: import pandas as pd 23 | ...: import tensorflow as tf 24 | ...: import os 25 | ...: import sys 26 | 27 | In [3]: %iversions 28 | numpy 1.13.1 29 | pandas 0.20.3 30 | tensorflow 1.3.0 31 | 32 | Python 3.6.2 [Sun Aug 27, 2017 13:50:43] 33 | 34 | In [4]: 35 | 36 | 37 | 38 | Inspired by amazing similar projects: 39 | ===================================== 40 | 41 | - `version\_information `__ 42 | - `watermark `__ 43 | 44 | 45 | TODO 46 | ==== 47 | 48 | - Add a feature to output to ``requirements.txt`` 49 | 50 | 51 | KNOWN ISSUES 52 | ============ 53 | 54 | - Non-module imports do not work e.g. ``from X import Y`` 55 | -------------------------------------------------------------------------------- /iversions/iversions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Aziz Alto 5 | # Aug. 26, 2017 6 | 7 | 8 | """ 9 | iversions is a simple cell magic command for IPython/Jupyter, 10 | to display name and version of all imported modules (non built-in) in the current environment. 11 | 12 | Usage: 13 | 14 | after loading it `%load_ext iversions` and importing some modules, just type: 15 | 16 | %iversions 17 | 18 | Note: 19 | 20 | Currently, it does not work with non-module imports `from X import Y` :( 21 | """ 22 | 23 | from sys import version_info as ver_info 24 | import types 25 | from datetime import datetime 26 | 27 | PYTHON_VER = '.'.join(map(str, [ver_info.major, ver_info.minor, ver_info.micro])) 28 | 29 | 30 | def now(): 31 | return datetime.strftime(datetime.now(), '%a %b %d, %Y %H:%M:%S %Z') 32 | 33 | 34 | def print_versions(symbol_table=locals()): 35 | """:param symbol_table: globals() or locals() 36 | """ 37 | 38 | for val in symbol_table.values(): 39 | if isinstance(val, types.ModuleType): 40 | try: 41 | print('{:>10} {}'.format(val.__name__, val.__version__)) 42 | except AttributeError: 43 | # built-ins will be excepted 44 | continue 45 | print('\nPython {} [{}]'.format(PYTHON_VER, now().strip())) 46 | 47 | 48 | # notebook cellmagic interface 49 | from IPython.core.magic import Magics 50 | from IPython.core.magic import magics_class 51 | from IPython.core.magic import line_magic, register_line_magic, cell_magic 52 | 53 | 54 | @magics_class 55 | class IVersions(Magics): 56 | @line_magic 57 | def iversions(self, line): 58 | """ 59 | Display name and version of the imported modules in current environment. 60 | 61 | Usage: 62 | import some modules, just type 63 | 64 | %iversions 65 | 66 | enjoy :-) 67 | """ 68 | print_versions(self.shell.user_ns) 69 | -------------------------------------------------------------------------------- /demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Example on how to use `iversions` cell magic" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "%load_ext iversions" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 2, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "import pandas as pd\n", 26 | "import numpy as np\n", 27 | "import torch\n", 28 | "import sys" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 3, 34 | "metadata": {}, 35 | "outputs": [ 36 | { 37 | "name": "stdout", 38 | "output_type": "stream", 39 | "text": [ 40 | "pandas 0.20.3\n", 41 | "numpy 1.13.1\n", 42 | "torch 0.2.0_1\n", 43 | "\n", 44 | "Python 3.6.2 [Sun Aug 27, 2017 14:10:07]\n" 45 | ] 46 | } 47 | ], 48 | "source": [ 49 | "%iversions" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 4, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "import sklearn \n", 59 | "import tensorflow as tf" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 5, 65 | "metadata": {}, 66 | "outputs": [ 67 | { 68 | "name": "stdout", 69 | "output_type": "stream", 70 | "text": [ 71 | "pandas 0.20.3\n", 72 | "numpy 1.13.1\n", 73 | "torch 0.2.0_1\n", 74 | "sklearn 0.19.0\n", 75 | "tensorflow 1.3.0\n", 76 | "\n", 77 | "Python 3.6.2 [Sun Aug 27, 2017 14:10:07]\n" 78 | ] 79 | } 80 | ], 81 | "source": [ 82 | "%iversions" 83 | ] 84 | } 85 | ], 86 | "metadata": { 87 | "kernelspec": { 88 | "display_name": "Python 3", 89 | "language": "python", 90 | "name": "python3" 91 | }, 92 | "language_info": { 93 | "codemirror_mode": { 94 | "name": "ipython", 95 | "version": 3 96 | }, 97 | "file_extension": ".py", 98 | "mimetype": "text/x-python", 99 | "name": "python", 100 | "nbconvert_exporter": "python", 101 | "pygments_lexer": "ipython3", 102 | "version": "3.6.2" 103 | } 104 | }, 105 | "nbformat": 4, 106 | "nbformat_minor": 2 107 | } 108 | --------------------------------------------------------------------------------