libpath.py 1.42 KB
Newer Older
wxchan's avatar
wxchan committed
1
# coding: utf-8
2
"""Find the path to LightGBM dynamic library files."""
3
4
from os import environ
from pathlib import Path
5
from platform import system
Deddy Jobson's avatar
Deddy Jobson committed
6
from typing import List
7

wxchan's avatar
wxchan committed
8

Deddy Jobson's avatar
Deddy Jobson committed
9
def find_lib_path() -> List[str]:
wxchan's avatar
wxchan committed
10
    """Find the path to LightGBM library files.
11

wxchan's avatar
wxchan committed
12
13
    Returns
    -------
14
15
    lib_path: list of strings
       List of all found library paths to LightGBM.
wxchan's avatar
wxchan committed
16
    """
17
    if environ.get('LIGHTGBM_BUILD_DOC', False):
18
19
20
        # we don't need lib_lightgbm while building docs
        return []

21
    curr_path = Path(__file__).absolute().parent
22
    dll_path = [curr_path,
23
24
25
26
                curr_path.parents[1],
                curr_path / 'compile',
                curr_path.parent / 'compile',
                curr_path.parents[1] / 'lib']
27
    if system() in ('Windows', 'Microsoft'):
28
29
30
31
32
        dll_path.append(curr_path.parent / 'compile' / 'Release')
        dll_path.append(curr_path.parent / 'compile' / 'windows' / 'x64' / 'DLL')
        dll_path.append(curr_path.parents[1] / 'Release')
        dll_path.append(curr_path.parents[1] / 'windows' / 'x64' / 'DLL')
        dll_path = [p / 'lib_lightgbm.dll' for p in dll_path]
wxchan's avatar
wxchan committed
33
    else:
34
35
        dll_path = [p / 'lib_lightgbm.so' for p in dll_path]
    lib_path = [str(p) for p in dll_path if p.is_file()]
wxchan's avatar
wxchan committed
36
    if not lib_path:
37
38
        dll_path_joined = '\n'.join(map(str, dll_path))
        raise Exception(f'Cannot find lightgbm library file in following paths:\n{dll_path_joined}')
wxchan's avatar
wxchan committed
39
    return lib_path