• Stars
    star
    104
  • Rank 323,966 (Top 7 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code inspection for Python builtins

cinspect

cinspect is an attempt to extend Python's built-in inspect module to add "inspection" for Python's builtins and other objects not written in Python.

The project is inspired by pry-doc and tries to generate indexes of the sources for C-extensions, which are then used when objects are being inspected.

How it works

  1. We use libclang's Python bindings to parse the C-code and generate indexes out of it.

  2. When an object is inspected, we look up the required data from the indexes and use it.

Installation and Usage

Python 3x vs 2x

cinspect's indexing tool only works with Python 2.x. The indexing tool cinspect-index is not made available in Python 3.x, since libclang's Python bindings are not Python 3.x compatible.

However, cinspect's index lookup functionality is Python 3.x compatible. See the section Downloading indexes

Installation

cinspect depends on having libclang installed in the system, for indexing sources. If you can obtain the indexed sources from a different location, you will not require libclang.

Something like the following should do it, depending on which system you are on.

sudo apt-get install libclang1-3.5 libclang-common-3.5

The easiest way to install the package currently is to run (in a virtual environment).

python setup.py develop

The cinspect module currently exposes only a getsource and getfile, which are similar to equivalent functions in the built-in inspect module.

Downloading indexes

Index files for some of the most common versions of Python are made available for download, so you do not have to do the indexing yourself. These indexes are available in the cinspect-data repository.

You can download these indexes by simply

cinspect-download

Usage

Once you have created/downloaded the indexes, you can use the getsource or getfile functions exposed by cinspect, to inspect your objects.

Indexing your sources

If you want to generate your own indexes instead of using the ones available here, you will need to run the indexer.

The indexer is exposed as the cinspect-index command. You can run it as follows,

cinspect-index -I/usr/lib/clang/3.5/include \
               -I/home/punchagan/software/random/cpython/Include \
               -I/home/punchagan/software/random/cpython/ \

			   /home/punchagan/software/random/cpython/

Essentially, you tell cinspect-cindex the path to the directory you wish to index. Since we use libclang to index the sources, any additional arguments you pass to this script are passed on to libclang. To get the indexer to work, you will have to make sure that

  1. libclang is able to find its own includes.
  2. You pass-in the include dirs that the project you are indexing needs, to compile.

The indexes are currently saved at ~/.cinspect/index-<version>.json. The version of the source code being indexed is by default assumed to be the same as the version of the Python being run. Use the --version flag to change this, if required.

IPython monkey-patch startup script.

We have a startup script for IPython, that monkey patches it, to enable it to use cinspect. Drop the script provided in utils/00-cinspect.py into your IPython startup directory.

cp utils/00-cinspect.py `ipython locate profile default`/startup

Now, ? and ?? will be patched to try and use the cinspect indexes, once you restart IPython (using the default profile).

More Repositories

1

resume

Source files for my resume
TeX
67
star
2

GetHub

A Chrome extension for GitHub News Feed pop-up notifications
JavaScript
27
star
3

org-ghi

A GitHub issues plugin for Org-mode -- A Dead project now. Similar project at http://orgmode.org/w/?p=org-sync.git
Emacs Lisp
20
star
4

papers-we-love-hyd

An archive of resources from the Papers We Love meet-ups in Hyderabad
Shell
18
star
5

artful-dodger

A Next.js site to host an art gallery using Google Spreadsheets and Google Drive as a backend
JavaScript
16
star
6

hack-and-tell-hyd

Discussions and wrap-ups of Hack-and-Tell, Hyderabad
12
star
7

zulip-helpers.el

Some helpers to post from my org-mode file to Zulip
Emacs Lisp
11
star
8

howdy

An Emacs utility to help you keep in touch with people
Emacs Lisp
11
star
9

playo-find-venue

Find good Playo venues in convenient locations
JavaScript
11
star
10

github-cue

Provide recommendations of GitHub repos to follow
JavaScript
10
star
11

ox-gist

Export Org mode buffers and subtrees to GitHub gists
Emacs Lisp
10
star
12

childrens-park

A Jabber/Google-talk bot that can be used as a chatroom. (Based on python-jabberbot)
Python
10
star
13

blog-files

Build files for my web-site (no-longer maintained. Moved to o-blog!)
Python
9
star
14

earworm

Create a simple web page to listen to audio files in a directory
Python
8
star
15

IGZen

Post to Instagram, Zen style
Python
7
star
16

expense-tracker

Expense Tracker
Python
7
star
17

html-preview

Preview html files inside Emacs' webkit xwidget
Emacs Lisp
6
star
18

statiki

statiki is an easy-to-use service for deploying simple web-sites.
Python
6
star
19

talks

my talk slides
Jupyter Notebook
5
star
20

dot-emacs

My dot-emacs
Emacs Lisp
5
star
21

pari-mukha

A Facial map of India
JavaScript
5
star
22

ideas

A repository of ideas
5
star
23

read-later-to-kindle

Pull items from read-it-later queues to kindle
Python
5
star
24

ramfox

A Firefox extension that sort of makes it behave like Rambox
Python
5
star
25

org-hyde

Export org-mode trees to hyde ready html files
Emacs Lisp
4
star
26

wa-share

A (local) app to copy and share messages from a WhatsApp chat
JavaScript
4
star
27

bookmarklets

A collection of my bookmarklets to automate various things in the browser
HTML
4
star
28

ukulele-tutorials

Code to populate the Ukulele Tutorials site
JavaScript
4
star
29

omnium-gatherum

Everything that can't go anywhere else.
Python
4
star
30

dotfiles

Repo to keep track of my dotfiles
Python
3
star
31

what-changed

A simple tool to diff public API changes of a Python library
Python
3
star
32

r2k

Send rss feeds to the Kindle using rss2email.
Python
3
star
33

experiri

All my experiments with github are done on this repo
SCSS
3
star
34

preview

Preview is a graphical preview tool for git repositories
Clojure
3
star
35

data-projects

Repository for my data related projects
HTML
3
star
36

android-dotfiles

Dot files for use with Termux on my phone
Shell
3
star
37

hs-twitter-lists

A script to create private lists of Hacker Schoolers or twitter, batch-wise.
Python
2
star
38

cowsnbulls

An online version of Cows & Bulls.
Elm
2
star
39

weblogviz

A CLI utility to parse apache web logs and show useful statistics
Rust
2
star
40

crumb

A disqus-like commenting system using GitHub issues
JavaScript
2
star
41

git-mob-sh

Git subcommand that makes mob programming workflows easier
Shell
2
star
42

project-euler

My (age old) attempts to solve problems at Project Euler
Python
2
star
43

prang

A python script that shows the color name at the pixel where the mouse is present
Python
2
star
44

parktain

A slack bot for the park-ers
Python
2
star
45

ansible-raspberry-pi

Reproducible setup for my Raspberry Pi
Python
2
star
46

upai-scripts

Miscellaneous scripts to help automate various tasks for UPAI
Python
2
star
47

ansible-system-setup

Repository to bootstrap and setup my laptop and other machines
Shell
2
star
48

v_block

An Android script that let's you block calls from unwanted numbers.
Python
2
star
49

python-tut

Python tutorial code
Python
1
star
50

ml-class-exercises

My solutions to the programming exercises of ML class.
MATLAB
1
star
51

tree-house

In memory of all those songs with heroes and heroines running around the trees.
JavaScript
1
star
52

jijnasa-scripts

Scripts to manage Jijnasa
Shell
1
star
53

sync-rpi

Sync scripts for phone and computer running on the Raspberry Pi
Shell
1
star
54

wcbu-2017-viz

Dash playground for visualizing WCBU 2017 data
Python
1
star
55

share-post-action

Action to share posts on social media using GitHub Actions
Shell
1
star
56

bangalore-transit-analysis

Bangalore Transit data analysis
Jupyter Notebook
1
star
57

bodypix-experiments

JavaScript
1
star
58

punchagan.muse-amuse.in

The sources for my website/blog
HTML
1
star
59

dot-doom

Doom Emacs configuration
Emacs Lisp
1
star
60

delhi-events

OCaml
1
star