Skip to content

Commit

Permalink
Fixes #153: Use "distutils.sysconfig.get_python_lib()" when "site.get…
Browse files Browse the repository at this point in the history
…sitepackages()" is unavailable (#154)
  • Loading branch information
BR0kEN- authored Jul 5, 2018
1 parent 07a547a commit 8e6e0d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 12 additions & 0 deletions lib/getsitepackages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import site

if hasattr(site, 'getsitepackages'):
print site.getsitepackages()
else:
# If "site" module has no "getsitepackages" function then most probably Python is running inside of "virtualenv".
# - https://github.com/pypa/virtualenv/issues/355
# - https://github.com/SFTtech/openage/pull/1031
# - https://github.com/dmlc/tensorboard/issues/38#issuecomment-343017735
from distutils.sysconfig import get_python_lib

print [get_python_lib()]
14 changes: 7 additions & 7 deletions lib/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
)
)

dirs = {
'lib': os.path.realpath(__file__ + '/..'),
'self': os.path.realpath(__file__ + '/../..'),
'project': os.environ.get('CIKIT_PROJECT_DIR'),
}

# It's an interesting trick for detecting Python interpreter. Sometimes it
# may differ. Especially on MacOS, when Ansible installed via Homebrew. For
# instance, "which python" returns the "/usr/local/Cellar/python/2.7.13/
Expand All @@ -40,7 +46,7 @@
if PYTHON_SYSTEM != PYTHON_ANSIBLE:
import ast

for site_packages in ast.literal_eval(functions.call(PYTHON_ANSIBLE, '-c', 'import site; print(site.getsitepackages())')):
for site_packages in ast.literal_eval(functions.call(PYTHON_ANSIBLE, dirs['lib'] + '/getsitepackages.py')):
if site_packages not in sys.path:
sys.path.append(site_packages)

Expand All @@ -67,12 +73,6 @@
],
})

dirs = {
'lib': os.path.realpath(__file__ + '/..'),
'self': os.path.realpath(__file__ + '/../..'),
'project': os.environ.get('CIKIT_PROJECT_DIR'),
}

if None is dirs['project']:
dirs['project'] = os.getcwd()
dirs['scripts'] = dirs['self']
Expand Down

0 comments on commit 8e6e0d1

Please sign in to comment.