Created
April 3, 2013 17:42
-
-
Save vbmendes/5303446 to your computer and use it in GitHub Desktop.
Script to open source code of python modules in sublime. Useful to see your dependencies source code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf8 | |
import imp | |
import sys, os | |
module_name = sys.argv[1] | |
bits = module_name.split('.') | |
name = imp.find_module(bits[0])[1] | |
if len(bits) > 1: | |
subname = os.path.join(*bits[1:]) | |
dir_path = os.path.join(name, subname) | |
else: | |
dir_path = name | |
if os.path.exists(dir_path): | |
final_path = dir_path | |
else: | |
py_path = dir_path + '.py' | |
if os.path.exists(py_path): | |
final_path = py_path | |
else: | |
print u'Module not found:\n%s\n%s\n' % (dir_path, py_path) | |
final_path = None | |
if final_path: | |
cmd = "subl %s" % final_path | |
os.system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you dont have subl command in osx, follow this documentation:
http://www.sublimetext.com/docs/2/osx_command_line.html