Skip to content

Commit

Permalink
BUILD: fix issue of calling site.getsitepackages() under virtualenv
Browse files Browse the repository at this point in the history
Method `site.getsitepackages()` won't work with `virtualenv`, so that
we have to use `distutils.sysconfig`get_python_lib()` instead. See
also: pypa/virtualenv#737
  • Loading branch information
NaleRaphael committed Oct 27, 2020
1 parent 5d8d4a7 commit eea6fa9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
from pathlib import Path
from setuptools import setup, find_packages

# Method `site.getsitepackages()` won't work with `virtualenv`, see also:
# https://github.com/pypa/virtualenv/issues/737
if not hasattr(site, 'getsitepackages'):
from distutils.sysconfig import get_python_lib
getsitepackages = get_python_lib
else:
getsitepackages = site.getsitepackages

THIS_DIR = Path(__file__).parent

Expand All @@ -24,6 +31,7 @@
EXTRAS_REQUIRE['dot'].append('pygraphviz>=1.6')
EXTRAS_REQUIRE['full'] = list(set([v for req_list in EXTRAS_REQUIRE.values() for v in req_list]))


def get_version(fn_version_setting):
version = open(fn_version_setting, 'r').read().strip()
parts = version.split('.')
Expand Down Expand Up @@ -112,7 +120,7 @@ def prepare_data_files():
path_map[rel_parent].append(rel_path)

# Prefix keys in `path_map` with "lib/site-packages" (depends on OS)
prefix = Path(site.getsitepackages()[0]).relative_to(sys.prefix)
prefix = Path(getsitepackages()[0]).relative_to(sys.prefix)
path_map = {str(prefix.joinpath(k)): v for k, v in path_map.items()}

# Convert `Path` object to str
Expand Down

0 comments on commit eea6fa9

Please sign in to comment.