ein-inspector: Getting organized, remove cruft.

This commit is contained in:
John Miller 2017-09-30 16:06:36 -05:00
parent 1ab98b0c9d
commit 0bc7ab813a
2 changed files with 29 additions and 50 deletions

View file

@ -44,7 +44,25 @@
(if (not (plist-get oinfo :type))
(ein:log 'warn "[EIN:INSPECTOR]: %s" (plist-get oinfo :error))
(ein:render-inspector oinfo)))
(ein:log 'warn "[EIN:INSPECTOR]: Could not find inspect data for object at point!"))))
(ein:log 'warn "[EIN:INSPECTOR]: Could not find inspect data for object %s." oname))))
(defclass ein:iobject ()
((name :accessor ein:iobject-name :documentation "String representation can be evaluated in python to generate the object being inspected.")
(type :accessor ein:iobject-type :documentation "Python type of object, as returned by `type()`.")
(repr :accessor ein:iobject-repr :documentation "Value of object, as returned by its `__str__` method.")
(source-file :accessor ein:iobject-sfile :documentation "If availabe, the filename where the source for this object is to be found.")
(source-lines :accessor ein:iobject-slines :documentation "If available, the line in the file where the source for this object is found.")
(doc :accessor ein:iobject-doc :documentation "If available, the documentation string for this object."))
:documentation "Class to hold information returned by Python `inspect` module for a Python object identified in the `name` slot.")
(defun ein:new-inspector-object (object-info)
(make-instance 'ein:iobject
:name (plist-get object-info :name)
:type (plist-get object-info :type)
:repr (plist-get object-info :repr)
:source-file (plist-get object-info :source_file)
:source-lines (plist-get object-info :source_lines)
:doc (plist-get object-info :doc)))
(defvar ein:inspector-visit-source-map (make-sparse-keymap))
@ -68,18 +86,18 @@
(let ((inhibit-read-only t))
(erase-buffer))
(remove-overlays)
(lexical-let* (
(type (plist-get oinfo :type))
(lexical-let* ((type (plist-get oinfo :type))
(repr (plist-get oinfo :repr))
(sfile (plist-get oinfo :source_file))
(slines (last (plist-get oinfo :source_lines))))
(slines (last (plist-get oinfo :source_lines)))
(info-str (format "%s = {%s} %s" name type repr)))
(if sfile
(widget-create 'link
:notify
(lambda (&rest ignore)
(ein:goto-file sfile (car slines)))
repr)
(widget-insert (propertize repr 'face 'bold)))
info-str)
(widget-insert (propertize info-str 'face 'bold)))
(widget-insert (format "\n\n%s\n\n" (make-string 80 ?\u2501)))
(widget-insert (format "%s\n\n%s\n\n" (plist-get oinfo :doc) (make-string 80 ?\u2501)))
(widget-insert (propertize (format "%s: %s\n" type name)
@ -87,6 +105,8 @@
(ein:inspector-mode)
(widget-setup))
(defun ein:inspector-visit-source ()
(message "Visit source!"))

View file

@ -31,7 +31,8 @@ def generate_inspector_data(obj_str, globals, locals):
odata['error'] = 'Object {} not found.'.format(obj_str)
else:
odata['doc'] = inspect.getdoc(obj)
odata['type'], odata['repr'] = determine_object_type(obj)
odata['type'] = str(type(obj))
odata['repr'] = str(obj)
try:
odata['source_file'] = inspect.getsourcefile(obj)
odata['source_lines'] = inspect.getsourcelines(obj)
@ -41,46 +42,4 @@ def generate_inspector_data(obj_str, globals, locals):
print(json.dumps(odata))
return odata
def determine_object_type(obj):
if inspect.ismodule(obj):
return 'Module', obj.__str__()
elif inspect.isclass(obj):
return 'Class', obj.__str__()
elif inspect.ismethod(obj):
return 'Method', obj.__str__()
elif inspect.isfunction(obj):
return 'Function', obj.__str__()
elif inspect.isgeneratorfunction(obj):
return 'Generator Function', obj.__str__()
elif inspect.isgenerator(obj):
return 'Generator', obj.__str__()
elif inspect.iscoroutinefunction(obj):
return 'Coroutine Function', obj.__str__()
elif inspect.iscoroutine(obj):
return 'Coroutine', obj.__str__()
elif inspect.isawaitable(obj):
return 'Awaitable', obj.__str__()
elif inspect.istraceback(obj):
return 'Traceback', obj.__str__()
elif inspect.isframe(obj):
return 'Frame', obj.__str__()
elif inspect.iscode(obj):
return 'Code', obj.__str__()
elif inspect.isbuiltin(obj):
return 'Builtin', obj.__str__()
elif inspect.isroutine(obj):
return 'Routine', obj.__str__()
elif inspect.isabstract(obj):
return 'Abstract Base Class', obj.__str__()
elif inspect.ismethoddescriptor(obj):
return 'Method Descriptor', obj.__str__()
elif inspect.isdatadescriptor(obj):
return 'Data Descriptor', obj.__str__()
elif inspect.isgetsetdescriptor(obj):
return 'Getset Descriptor', obj.__str__()
elif inspect.ismemberdescriptor(obj):
return 'Member Descriptor', obj.__str__()
elif inspect.isbuiltin(obj):
return str(type(obj)), obj.__str__()
else:
return str(type(obj)), obj.__str__()