~edwargix/git.sr.ht

ae44baf7a0f99d3e53c2d751db358bdac6db25ca — Ludovic Chabant 7 years ago 3f532d8
Support installing into a virtual environment

It turns out that `virtualenv` has a custom (and non quite working)
implementation of the `site` module, and it doesn't have the
`getsitepackages` method... so since we already need the `$SRHT_PATH`
environment variable, we can use that instead to locate the core `srht`
package.

We also give an error so the user knows what's going on.

Finally, we support situations where Python installs packages in the
`USER_BASE` directory.
1 files changed, 23 insertions(+), 2 deletions(-)

M setup.py
M setup.py => setup.py +23 -2
@@ 6,8 6,29 @@ import os
import site
import sys

site_packages = site.getsitepackages()[0]
srht_path = os.path.join(site_packages, "srht")
if hasattr(site, 'getsitepackages'):
    pkg_dirs = site.getsitepackages()
    if site.getusersitepackages():
        pkg_dirs.append(site.getusersitepackages())
    for pkg_dir in pkg_dirs:
        srht_path = os.path.join(pkg_dir, "srht")
        if os.path.isdir(srht_path):
            break
    else:
        raise Exception("Can't find core srht module in your site packages "
            "directories. Please install it first.")
else:
    srht_path = os.getenv("SRHT_PATH")
    if not srht_path:
        raise Exception("You're running inside a virtual environment. "
            "Due to virtualenv limitations, you need to set the "
            "$SRHT_PATH environment variable to the path of the "
            "core srht module.")
    elif not os.path.isdir(srht_path):
        raise Exception(
            "The $SRHT_PATH environment variable points to an invalid "
            "directory: {}".format(srht_path))

subp = subprocess.run(["make", "SRHT_PATH=" + srht_path])
if subp.returncode != 0:
    sys.exit(subp.returncode)