Commit 5453cd0b authored by Tom Verhoeff's avatar Tom Verhoeff
Browse files

Improved logging. Added option to show version. Added example notebook. ...

Improved logging.  Added option to show version.  Added example notebook.  Updated README.md accordingly.
parent edfe71e8
This diff is collapsed.
......@@ -5,7 +5,7 @@
## Installation
* Move the `nb-mypy.py` script into your IPython profile's startup directory.
* Download the [`nb-mypy.py`](nb-mypy.py) script and move it into your IPython profile's startup directory.
The IPython directory can be found by running `ipython locate` in a terminal.
Within this directory, the default profile's startup directory is `profile_default/startup/`.
......@@ -42,6 +42,7 @@ if 'nb_mypy' in get_ipython().magics_manager.magics.get('line'):
%nb_mypy On
```
Here are the ways to use the line magic `%nb_mypy`
* `%nb_mypy -v`: show version
* `%nb_mypy`: show the current state
* `%nb_mypy On`: enable automatic type checking
* `%nb_mypy Off`: disable automatic type checking
......@@ -51,5 +52,4 @@ Here are the ways to use the line magic `%nb_mypy`
## Examples
(Example notebook to be provided.
See Lecture 4-B of Software Development for Engineers.)
For examples, see the Jupyter notebook [`Nb-Mypy.ipynb`](Nb-Mypy.ipynb).
......@@ -13,7 +13,7 @@ Current version was inspired by github user BradyHu
https://gist.github.com/BradyHu/f4dc997d4b53f9b23e1120940fb8f0d1
"""
__version__ = '2020.5.9'
__version__ = '2020.5.10'
import ast
import re
......@@ -23,7 +23,7 @@ import logging
from typing import Set
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger = logging.getLogger('nb-mypy')
# List names in names objects, or tuples.
......@@ -322,12 +322,17 @@ class __MypyIPython:
mypy_shell.run_cell = mypy_tmp
def version(self):
"""Show version.
"""
logger.info(f"Version {__version__}")
def state(self):
"""Show current state.
"""
on_off = {True: 'On', False: 'Off'}
debug_on_off = {True: 'DebugOn', False: 'DebugOff'}
logger.info(f"nb_mypy state: {on_off[self.mypy_typecheck]} {debug_on_off[self.debug]}")
logger.info(f"State: {on_off[self.mypy_typecheck]} {debug_on_off[self.debug]}")
def stop(self):
"""Disable automatic type checking.
......@@ -359,6 +364,7 @@ def nb_mypy(line):
"""
switcher = {
'': __Nb_Mypy_TypeChecker.state,
'-v': __Nb_Mypy_TypeChecker.version,
'On': __Nb_Mypy_TypeChecker.start,
'Off': __Nb_Mypy_TypeChecker.stop,
'DebugOn': __Nb_Mypy_TypeChecker.debug_on,
......@@ -367,9 +373,9 @@ def nb_mypy(line):
# logger.info(f"line magic argument: {line!r}")
def unknown():
logger.error(f"nb_mypy: Unknown argument\nValid arguments: {list(switcher.keys())!r}")
logger.error(f"Unknown argument\nValid arguments: {list(switcher.keys())!r}")
switcher.get(line, unknown)()
logger.info(f"nb-mypy.py version {__version__}")
__Nb_Mypy_TypeChecker.version()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment