Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__pycache__/
README.html
doc/tags
venv
21 changes: 15 additions & 6 deletions python3/ghost_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from os import path
import os
import vim
import venv


def install():
Expand All @@ -13,17 +14,25 @@ def isvim():
req = "requirements_win.txt" if sys.platform == "win32" else \
"requirements_posix.txt"
reqFile = path.join(base, req)
venv_dir = path.join(base, "venv")

print("ghost: creating virtualenv at %s" % venv_dir)
venv.create(venv_dir, with_pip=True)

if sys.platform == "win32":
pip_exe = path.join(venv_dir, "Scripts", "pip.exe")
else:
pip_exe = path.join(venv_dir, "bin", "pip")

print("ghost: installing dependencies from %s" % reqFile)
py3 = sys.executable
# on windows vim reports sys.executable as the path to gvim/vim
if isvim() and sys.platform == "win32":
py3 = path.normpath(path.join(os.__file__, "../..", "python.exe"))
out = subprocess.check_output([py3,
"-m", "pip", "install", "--user", "-r",
out = subprocess.check_output([pip_exe,
"install", "-r",
reqFile], stderr=subprocess.STDOUT,
shell=False)
for l in out.decode().split(os.linesep):
print("ghost: %s" % l)
print("ghost: dependencies installed successfully")
except subprocess.CalledProcessError as cpe:
print("ghost: error installing dependencies: %s" % cpe)
except Exception as e:
print("ghost: error: %s" % e)
17 changes: 17 additions & 0 deletions pythonx/ghost_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import os
import sys
import site
import glob

# Inject virtualenv site-packages if it exists
_plugin_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
_venv_path = os.path.join(_plugin_root, 'venv')
if os.path.exists(_venv_path):
if sys.platform == 'win32':
_site_packages = os.path.join(_venv_path, 'Lib', 'site-packages')
else:
_site_packages_matches = glob.glob(os.path.join(_venv_path, 'lib', 'python3.*', 'site-packages'))
_site_packages = _site_packages_matches[0] if _site_packages_matches else None
if _site_packages and os.path.exists(_site_packages):
site.addsitedir(_site_packages)

from ghost import Ghost as _Ghost
import vim

Expand Down
19 changes: 17 additions & 2 deletions rplugin/python3/ghost.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import os
import sys
import site
import glob

# Inject virtualenv site-packages if it exists
_plugin_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
_venv_path = os.path.join(_plugin_root, 'venv')
if os.path.exists(_venv_path):
if sys.platform == 'win32':
_site_packages = os.path.join(_venv_path, 'Lib', 'site-packages')
else:
_site_packages_matches = glob.glob(os.path.join(_venv_path, 'lib', 'python3.*', 'site-packages'))
_site_packages = _site_packages_matches[0] if _site_packages_matches else None
if _site_packages and os.path.exists(_site_packages):
site.addsitedir(_site_packages)

import subprocess
from http.server import HTTPServer, BaseHTTPRequestHandler
from random import randint
from threading import Thread
from tempfile import mkstemp
import logging
import json
import os
import sys
import platform
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
try:
Expand Down