Skip to content

Commit

Permalink
Auto merge of ycm-core#519 - micbou:find-python-libraries-multiple-fo…
Browse files Browse the repository at this point in the history
…lders, r=Valloric

[READY] Use LIBPL variable to find Python library

Currently, the `build.py` script may found a debug version of the Python library instead of the release version because it searches through all the subdirectories of the standard library path. See issue ycm-core#518 for details. The solution suggested by @jmenashe (using `LIBPL` variable) works fine for system Python but not for `pyenv` because there is no dynamic library in the directory returned by the `LIBPL` variable.

Taking this into account, we now search the Python library in a list of directories. On Windows, this list only contains one directory; the same one as before. On other platforms, it contains two directories:
 - the one returned by the `LIBPL` variable (for system Python);
 - the parent directory of the standard Python library modules (for pyenv).

Closes ycm-core#518.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/519)
<!-- Reviewable:end -->
  • Loading branch information
homu committed Jun 8, 2016
2 parents bdab3d6 + 1254400 commit b779b68
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,19 @@ def CheckOutput( *popen_args, **kwargs ):
return output


def GetPossiblePythonLibraryDirectories():
library_dir = p.dirname( sysconfig.get_python_lib( standard_lib = True ) )
if OnWindows():
return [ p.join( library_dir, 'libs' ) ]
# On pyenv, there is no Python dynamic library in the directory returned by
# the LIBPL variable. Such library is located in the parent folder of the
# standard Python library modules.
return [ sysconfig.get_config_var( 'LIBPL' ), library_dir ]


def FindPythonLibraries():
include_dir = sysconfig.get_python_inc()
# get_python_lib with the standard_lib parameter set to True returns the
# standard Python modules directory. Python libraries should always be in
# the parent directory or one of its subdirectories.
library_dir = p.dirname( sysconfig.get_python_lib( standard_lib = True ) )
library_dirs = GetPossiblePythonLibraryDirectories()

# Since ycmd is compiled as a dynamic library, we can't link it to a Python
# static library. If we try, the following error will occur on Mac:
Expand Down Expand Up @@ -183,17 +190,15 @@ def FindPythonLibraries():
major = PY_MAJOR, minor = PY_MINOR ), re.X )
static_libraries = []

# We search the Python libraries through the library directory and its
# subdirectories.
for root, dirs, files in os.walk( library_dir ):
for library_dir in library_dirs:
# Files are sorted so that we found the non-versioned Python library before
# the versioned one.
for filename in sorted( files ):
for filename in sorted( os.listdir( library_dir ) ):
if dynamic_name.match( filename ):
return p.join( root, filename ), include_dir
return p.join( library_dir, filename ), include_dir

if static_name.match( filename ):
static_libraries.append( p.join( root, filename ) )
static_libraries.append( p.join( library_dir, filename ) )

if static_libraries and not OnWindows():
dynamic_flag = ( '--enable-framework' if OnMac() else
Expand Down

0 comments on commit b779b68

Please sign in to comment.