|
|
@@ -26,28 +26,35 @@ import os
|
|
|
import common
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
+PTH_SYMLINK = 'hue.link.pth'
|
|
|
PTH_FILE = 'hue.pth'
|
|
|
|
|
|
|
|
|
+def _get_pth_symlink():
|
|
|
+ """
|
|
|
+ _get_pth_symlink -> Path to the .pth symlink.
|
|
|
+ May raise SystemError if the virtual env is absent.
|
|
|
+ """
|
|
|
+ return os.path.join(common._get_python_site_packages_dir(), PTH_SYMLINK)
|
|
|
+
|
|
|
+
|
|
|
def _get_pth_filename():
|
|
|
"""
|
|
|
_get_pth_filename -> Path to the .pth file.
|
|
|
+ Location can be defined via HUE_PTH_DIR environment variable.
|
|
|
May raise SystemError if the virtual env is absent.
|
|
|
"""
|
|
|
- glob_path = os.path.join(common.VIRTUAL_ENV, 'lib', 'python*', 'site-packages')
|
|
|
- res = glob.glob(glob_path)
|
|
|
- if len(res) == 0:
|
|
|
- raise SystemError("Cannot find a Python installation in %s. "
|
|
|
- "Did you do `make hue'?" % (glob_path,))
|
|
|
- elif len(res) > 1:
|
|
|
- raise SystemError("Found multiple Python installations in %s. "
|
|
|
- "Please `make clean' first." % (glob_path,))
|
|
|
- return os.path.join(res[0], PTH_FILE)
|
|
|
+ pth_dir = os.environ.get('HUE_PTH_DIR', None)
|
|
|
+ if pth_dir:
|
|
|
+ return os.path.join(pth_dir, PTH_FILE)
|
|
|
+ else:
|
|
|
+ return os.path.join(common._get_python_site_packages_dir(), PTH_FILE)
|
|
|
|
|
|
|
|
|
class PthFile(object):
|
|
|
def __init__(self):
|
|
|
"""May raise SystemError if the virtual env is absent"""
|
|
|
+ self._symlink_path = _get_pth_symlink()
|
|
|
self._path = _get_pth_filename()
|
|
|
self._entries = [ ]
|
|
|
self._read()
|
|
|
@@ -85,11 +92,16 @@ class PthFile(object):
|
|
|
self._entries.remove(path)
|
|
|
|
|
|
def save(self):
|
|
|
- """Save the pth file"""
|
|
|
+ """
|
|
|
+ Save the pth file
|
|
|
+ Create a symlink to the path if it does not already exist.
|
|
|
+ """
|
|
|
tmp_path = self._path + '.new'
|
|
|
file(tmp_path, 'w').write('\n'.join(sorted(self._entries)))
|
|
|
os.rename(tmp_path, self._path)
|
|
|
LOG.info('=== Saved %s' % (self._path,))
|
|
|
+ if not os.path.exists(self._symlink_path):
|
|
|
+ os.symlink(self._path, self._symlink_path)
|
|
|
|
|
|
def sync(self, apps):
|
|
|
"""Sync the .pth file with the installed apps"""
|