Skip to content

Instantly share code, notes, and snippets.

@jsmits
Last active December 24, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jsmits/6867662 to your computer and use it in GitHub Desktop.
Save jsmits/6867662 to your computer and use it in GitHub Desktop.
File for adding buildout omelette paths to virtualenv in vagrant for use by PyCharm. With this file, PyCharm can use the omelette packages from the vagrant remote interpreter. Usage: tweak paths in file if necessary, make it executable and put it in /usr/local/bin. Then run omelette2venv.py.
#!/usr/bin/env python
import os
def main(omelette_dir='/srv/parts/omelette'):
"""
Workaround to enable PyCharm to get access to the project modules.
Requirements:
- omelette directory created by buildout
- a virtualenv with the system packages named /home/vagrant/venv
You can then use /home/vagrant/venv/bin/python as your project's
interpreter in PyCharm.
"""
output = []
for f in os.listdir(omelette_dir):
fp = os.path.join(omelette_dir, f)
if os.path.islink(fp):
output.append(os.path.join('/', *os.readlink(fp).split('/')[:-1]))
pth_file = '/home/vagrant/venv/lib/python2.7/site-packages/omelette.pth'
pf = open(pth_file, 'w')
pf.write("# generated with omelette2venv.py\n")
pf.write("import sys; sys.__plen = len(sys.path)\n")
for o in output:
pf.write("%s\n" % o)
pf.write("import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)\n") # last line
pf.close()
print "succesfully generated %s" % pth_file
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment