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
1585ee15
Unverified
Commit
1585ee15
authored
Mar 07, 2023
by
James Lamb
Committed by
GitHub
Mar 07, 2023
Browse files
[ci] isolate c_api_test library-loading from Python source tree (#5761)
parent
bf1a604a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
35 deletions
+7
-35
tests/c_api_test/test_.py
tests/c_api_test/test_.py
+7
-35
No files found.
tests/c_api_test/test_.py
View file @
1585ee15
# coding: utf-8
# coding: utf-8
import
ctypes
import
ctypes
from
os
import
environ
from
pathlib
import
Path
from
pathlib
import
Path
from
platform
import
system
from
platform
import
system
import
numpy
as
np
import
numpy
as
np
from
scipy
import
sparse
from
scipy
import
sparse
try
:
def
find_lib_path
():
from
lightgbm.basic
import
_LIB
as
LIB
if
environ
.
get
(
'LIGHTGBM_BUILD_DOC'
,
False
):
except
ModuleNotFoundError
:
# we don't need lib_lightgbm while building docs
print
(
"Could not import lightgbm Python package, looking for lib_lightgbm at the repo root"
)
return
[]
curr_path
=
Path
(
__file__
).
absolute
().
parent
dll_path
=
[
curr_path
,
curr_path
.
parents
[
1
],
curr_path
.
parents
[
1
]
/
'python-package'
/
'lightgbm'
/
'compile'
,
curr_path
.
parents
[
1
]
/
'python-package'
/
'compile'
,
curr_path
.
parents
[
1
]
/
'lib'
]
if
system
()
in
(
'Windows'
,
'Microsoft'
):
if
system
()
in
(
'Windows'
,
'Microsoft'
):
dll_path
.
append
(
curr_path
.
parents
[
1
]
/
'python-package'
/
'compile'
/
'Release/'
)
lib_file
=
Path
(
__file__
).
absolute
().
parents
[
2
]
/
"Release"
/
"lib_lightgbm.dll"
dll_path
.
append
(
curr_path
.
parents
[
1
]
/
'python-package'
/
'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
]
else
:
else
:
dll_path
=
[
p
/
'lib_lightgbm.so'
for
p
in
dll_path
]
lib_file
=
Path
(
__file__
).
absolute
().
parents
[
2
]
/
"lib_lightgbm.so"
lib_path
=
[
str
(
p
)
for
p
in
dll_path
if
p
.
is_file
()]
LIB
=
ctypes
.
cdll
.
LoadLibrary
(
lib_file
)
if
not
lib_path
:
dll_path_joined
=
'
\n
'
.
join
(
map
(
str
,
dll_path
))
raise
Exception
(
f
'Cannot find lightgbm library file in following paths:
\n
{
dll_path_joined
}
'
)
return
lib_path
def
LoadDll
():
lib_path
=
find_lib_path
()
if
len
(
lib_path
)
==
0
:
return
None
lib
=
ctypes
.
cdll
.
LoadLibrary
(
lib_path
[
0
])
return
lib
LIB
=
LoadDll
()
LIB
.
LGBM_GetLastError
.
restype
=
ctypes
.
c_char_p
LIB
.
LGBM_GetLastError
.
restype
=
ctypes
.
c_char_p
...
...
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