From fc7d8a365a33f0de01b1b19b8a2a8ecd42f61f83 2015-03-23 18:22:10 From: MinRK Date: 2015-03-23 18:22:10 Subject: [PATCH] remove simplegeneric from external make it a dependency --- diff --git a/IPython/extensions/rmagic.py b/IPython/extensions/rmagic.py index d0501a1..6e052ad 100644 --- a/IPython/extensions/rmagic.py +++ b/IPython/extensions/rmagic.py @@ -73,7 +73,7 @@ from IPython.testing.skipdoctest import skip_doctest from IPython.core.magic_arguments import ( argument, magic_arguments, parse_argstring ) -from IPython.external.simplegeneric import generic +from simplegeneric import generic from IPython.utils.py3compat import (str_to_unicode, unicode_to_str, PY3, unicode_type) from IPython.utils.text import dedent diff --git a/IPython/external/simplegeneric/__init__.py b/IPython/external/simplegeneric/__init__.py deleted file mode 100644 index a81972a..0000000 --- a/IPython/external/simplegeneric/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -try: - from simplegeneric import * -except ImportError: - from ._simplegeneric import * diff --git a/IPython/external/simplegeneric/_simplegeneric.py b/IPython/external/simplegeneric/_simplegeneric.py deleted file mode 100644 index d417cc9..0000000 --- a/IPython/external/simplegeneric/_simplegeneric.py +++ /dev/null @@ -1,109 +0,0 @@ -"""This is version 0.7 of Philip J. Eby's simplegeneric module -(http://pypi.python.org/pypi/simplegeneric), patched to work with Python 3, -which doesn't support old-style classes. -""" - -#Name: simplegeneric -#Version: 0.7 -#Summary: Simple generic functions (similar to Python's own len(), pickle.dump(), etc.) -#Home-page: http://pypi.python.org/pypi/simplegeneric -#Author: Phillip J. Eby -#Author-email: peak@eby-sarna.com -#License: PSF or ZPL - -__all__ = ["generic"] - -try: - from types import ClassType, InstanceType -except ImportError: - classtypes = type -else: - classtypes = type, ClassType - -def generic(func): - """Create a simple generic function""" - - _sentinel = object() - - def _by_class(*args, **kw): - cls = args[0].__class__ - for t in type(cls.__name__, (cls,object), {}).__mro__: - f = _gbt(t, _sentinel) - if f is not _sentinel: - return f(*args, **kw) - else: - return func(*args, **kw) - - _by_type = {object: func} - try: - _by_type[InstanceType] = _by_class - except NameError: # Python 3 - pass - - _gbt = _by_type.get - - def when_type(*types): - """Decorator to add a method that will be called for the given types""" - for t in types: - if not isinstance(t, classtypes): - raise TypeError( - "%r is not a type or class" % (t,) - ) - def decorate(f): - for t in types: - if _by_type.setdefault(t,f) is not f: - raise TypeError( - "%r already has method for type %r" % (func, t) - ) - return f - return decorate - - - - - _by_object = {} - _gbo = _by_object.get - - def when_object(*obs): - """Decorator to add a method to be called for the given object(s)""" - def decorate(f): - for o in obs: - if _by_object.setdefault(id(o), (o,f))[1] is not f: - raise TypeError( - "%r already has method for object %r" % (func, o) - ) - return f - return decorate - - - def dispatch(*args, **kw): - f = _gbo(id(args[0]), _sentinel) - if f is _sentinel: - for t in type(args[0]).__mro__: - f = _gbt(t, _sentinel) - if f is not _sentinel: - return f(*args, **kw) - else: - return func(*args, **kw) - else: - return f[1](*args, **kw) - - dispatch.__name__ = func.__name__ - dispatch.__dict__ = func.__dict__.copy() - dispatch.__doc__ = func.__doc__ - dispatch.__module__ = func.__module__ - - dispatch.when_type = when_type - dispatch.when_object = when_object - dispatch.default = func - dispatch.has_object = lambda o: id(o) in _by_object - dispatch.has_type = lambda t: t in _by_type - return dispatch - - -def test_suite(): - import doctest - return doctest.DocFileSuite( - 'README.txt', - optionflags=doctest.ELLIPSIS|doctest.REPORT_ONLY_FIRST_FAILURE, - ) diff --git a/IPython/utils/generics.py b/IPython/utils/generics.py index 419e27b..5ffdc86 100644 --- a/IPython/utils/generics.py +++ b/IPython/utils/generics.py @@ -1,26 +1,11 @@ # encoding: utf-8 """Generic functions for extending IPython. -See http://cheeseshop.python.org/pypi/simplegeneric. +See http://pypi.python.org/pypi/simplegeneric. """ -#----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - from IPython.core.error import TryNext -from IPython.external.simplegeneric import generic - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +from simplegeneric import generic @generic diff --git a/setup.py b/setup.py index 2fdab2f..c5c9a60 100755 --- a/setup.py +++ b/setup.py @@ -271,6 +271,7 @@ extras_require['nbconvert'].extend(extras_require['nbformat']) install_requires = [ 'decorator', 'path.py', # required by pickleshare, remove when pickleshare is added here + 'simplegeneric>0.8', ] # add platform-specific dependencies