Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
58bc3af7
Unverified
Commit
58bc3af7
authored
Jul 28, 2022
by
James Lamb
Committed by
GitHub
Jul 28, 2022
Browse files
[python-package] make library-loading stricter (#5357)
parent
68b7315f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
10 deletions
+9
-10
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+9
-5
python-package/lightgbm/libpath.py
python-package/lightgbm/libpath.py
+0
-5
No files found.
python-package/lightgbm/basic.py
View file @
58bc3af7
...
...
@@ -7,7 +7,7 @@ import warnings
from
collections
import
OrderedDict
from
copy
import
deepcopy
from
functools
import
wraps
from
os
import
SEEK_END
from
os
import
SEEK_END
,
environ
from
os.path
import
getsize
from
pathlib
import
Path
from
tempfile
import
NamedTemporaryFile
...
...
@@ -108,11 +108,9 @@ def _log_callback(msg: bytes) -> None:
_log_native
(
str
(
msg
.
decode
(
'utf-8'
)))
def
_load_lib
()
->
Optional
[
ctypes
.
CDLL
]
:
def
_load_lib
()
->
ctypes
.
CDLL
:
"""Load LightGBM library."""
lib_path
=
find_lib_path
()
if
len
(
lib_path
)
==
0
:
return
None
lib
=
ctypes
.
cdll
.
LoadLibrary
(
lib_path
[
0
])
lib
.
LGBM_GetLastError
.
restype
=
ctypes
.
c_char_p
callback
=
ctypes
.
CFUNCTYPE
(
None
,
ctypes
.
c_char_p
)
...
...
@@ -122,7 +120,13 @@ def _load_lib() -> Optional[ctypes.CDLL]:
return
lib
_LIB
=
_load_lib
()
# we don't need lib_lightgbm while building docs
_LIB
:
ctypes
.
CDLL
if
environ
.
get
(
'LIGHTGBM_BUILD_DOC'
,
False
):
from
unittest.mock
import
Mock
# isort: skip
_LIB
=
Mock
(
ctypes
.
CDLL
)
# type: ignore
else
:
_LIB
=
_load_lib
()
NUMERIC_TYPES
=
(
int
,
float
,
bool
)
...
...
python-package/lightgbm/libpath.py
View file @
58bc3af7
# coding: utf-8
"""Find the path to LightGBM dynamic library files."""
from
os
import
environ
from
pathlib
import
Path
from
platform
import
system
from
typing
import
List
...
...
@@ -14,10 +13,6 @@ def find_lib_path() -> List[str]:
lib_path: list of str
List of all found library paths to LightGBM.
"""
if
environ
.
get
(
'LIGHTGBM_BUILD_DOC'
,
False
):
# we don't need lib_lightgbm while building docs
return
[]
curr_path
=
Path
(
__file__
).
absolute
().
parent
dll_path
=
[
curr_path
,
curr_path
.
parents
[
1
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment