~edwargix/git.sr.ht

9e44fb17111d19fea80513ce68dbd15831e4c3dc — Ludovic Chabant 7 years ago b8252c1
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.
1 files changed, 12 insertions(+), 3 deletions(-)

M setup.py
M setup.py => setup.py +12 -3
@@ 6,9 6,18 @@ import os
import site
import sys

site_packages = site.getsitepackages()[0]
srht_path = os.path.join(site_packages, "srht")
subp = subprocess.run(["make", "SRHT_PATH=" + srht_path])
srht_path = os.getenv("SRHT_PATH")
if not srht_path:
    if hasattr(site, 'getsitepackages'):
        site_packages = site.getsitepackages()[0]
        srht_path = os.path.join(site_packages, "srht")
    else:
        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 "
            "`coresrht` module.")

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