summaryrefslogtreecommitdiff
path: root/Cython/Build/IpythonMagic.py
diff options
context:
space:
mode:
Diffstat (limited to 'Cython/Build/IpythonMagic.py')
-rw-r--r--Cython/Build/IpythonMagic.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/Cython/Build/IpythonMagic.py b/Cython/Build/IpythonMagic.py
index 7abb97ec7..7aa7bf666 100644
--- a/Cython/Build/IpythonMagic.py
+++ b/Cython/Build/IpythonMagic.py
@@ -60,15 +60,11 @@ IO_ENCODING = sys.getfilesystemencoding()
IS_PY2 = sys.version_info[0] < 3
try:
- reload
-except NameError: # Python 3
- from imp import reload
-
-try:
- import hashlib
-except ImportError:
- import md5 as hashlib
+ from importlib import reload
+except ImportError: # Python 2 had a builtin function
+ pass
+import hashlib
from distutils.core import Distribution, Extension
from distutils.command.build_ext import build_ext
@@ -192,10 +188,15 @@ class CythonMagics(Magics):
@magic_arguments.magic_arguments()
@magic_arguments.argument(
- '-a', '--annotate', action='store_true', default=False,
+ '-a', '--annotate', action='store_const', const='default', dest='annotate',
help="Produce a colorized HTML version of the source."
)
@magic_arguments.argument(
+ '--annotate-fullc', action='store_const', const='fullc', dest='annotate',
+ help="Produce a colorized HTML version of the source "
+ "which includes entire generated C/C++-code."
+ )
+ @magic_arguments.argument(
'-+', '--cplus', action='store_true', default=False,
help="Output a C++ rather than C file."
)
@@ -317,7 +318,7 @@ class CythonMagics(Magics):
if args.name:
module_name = str(args.name) # no-op in Py3
else:
- module_name = "_cython_magic_" + hashlib.md5(str(key).encode('utf-8')).hexdigest()
+ module_name = "_cython_magic_" + hashlib.sha1(str(key).encode('utf-8')).hexdigest()
html_file = os.path.join(lib_dir, module_name + '.html')
module_path = os.path.join(lib_dir, module_name + self.so_ext)
@@ -439,12 +440,11 @@ class CythonMagics(Magics):
quiet=quiet,
annotate=args.annotate,
force=True,
+ language_level=min(3, sys.version_info[0]),
)
if args.language_level is not None:
assert args.language_level in (2, 3)
opts['language_level'] = args.language_level
- elif sys.version_info[0] >= 3:
- opts['language_level'] = 3
return cythonize([extension], **opts)
except CompileError:
return None