File tree Expand file tree Collapse file tree
emulator/brainflow_emulator Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import sys
55import time
66
7- import pkg_resources
7+ from importlib . resources import files
88from brainflow_emulator .emulate_common import TestFailureError , Listener , log_multilines
99from serial import Serial
1010
@@ -18,7 +18,15 @@ def read(port, num_bytes):
1818
1919
2020def get_isntaller ():
21- return pkg_resources .resource_filename (__name__ , os .path .join ('com0com' , 'setup_com0com_W7_x64_signed.exe' ))
21+ try :
22+ resource = files (__name__ ).joinpath ('com0com' ).joinpath ('setup_com0com_W7_x64_signed.exe' )
23+ return str (resource )
24+ except (TypeError , AttributeError ):
25+ # Fallback for:
26+ # 1. Python < 3.9 (importlib.resources.files not available)
27+ # 2. NixOS/packaging edge cases where importlib.resources may not work
28+ import pkg_resources
29+ return pkg_resources .resource_filename (__name__ , os .path .join ('com0com' , 'setup_com0com_W7_x64_signed.exe' ))
2230
2331
2432def install_com0com ():
Original file line number Diff line number Diff line change 44import sys
55import time
66
7- import pkg_resources
7+ from importlib . resources import files
88from brainflow_emulator .emulate_common import TestFailureError , log_multilines
99from brainflow_emulator .freeeeg32_emulator import Listener
1010from serial import Serial
@@ -19,7 +19,15 @@ def read(port, num_bytes):
1919
2020
2121def get_isntaller ():
22- return pkg_resources .resource_filename (__name__ , os .path .join ('com0com' , 'setup_com0com_W7_x64_signed.exe' ))
22+ try :
23+ resource = files (__name__ ).joinpath ('com0com' ).joinpath ('setup_com0com_W7_x64_signed.exe' )
24+ return str (resource )
25+ except (TypeError , AttributeError ):
26+ # Fallback for:
27+ # 1. Python < 3.9 (importlib.resources.files not available)
28+ # 2. NixOS/packaging edge cases where importlib.resources may not work
29+ import pkg_resources
30+ return pkg_resources .resource_filename (__name__ , os .path .join ('com0com' , 'setup_com0com_W7_x64_signed.exe' ))
2331
2432
2533def install_com0com ():
Original file line number Diff line number Diff line change 44import sys
55import time
66
7- import pkg_resources
7+ from importlib . resources import files
88from brainflow_emulator .emulate_common import TestFailureError , log_multilines
99from brainflow_emulator .knightboard_emulator import Listener
1010from serial import Serial
@@ -19,7 +19,15 @@ def read(port, num_bytes):
1919
2020
2121def get_isntaller ():
22- return pkg_resources .resource_filename (__name__ , os .path .join ('com0com' , 'setup_com0com_W7_x64_signed.exe' ))
22+ try :
23+ resource = files (__name__ ).joinpath ('com0com' ).joinpath ('setup_com0com_W7_x64_signed.exe' )
24+ return str (resource )
25+ except (TypeError , AttributeError ):
26+ # Fallback for:
27+ # 1. Python < 3.9 (importlib.resources.files not available)
28+ # 2. NixOS/packaging edge cases where importlib.resources may not work
29+ import pkg_resources
30+ return pkg_resources .resource_filename (__name__ , os .path .join ('com0com' , 'setup_com0com_W7_x64_signed.exe' ))
2331
2432
2533def install_com0com ():
Original file line number Diff line number Diff line change 77from typing import List
88
99import numpy
10- import pkg_resources
10+ from importlib . resources import files
1111from brainflow .exit_codes import BrainFlowExitCodes , BrainFlowError
1212from brainflow .utils import LogLevels
1313from numpy .ctypeslib import ndpointer
@@ -21,7 +21,7 @@ class BoardIds(enum.IntEnum):
2121 STREAMING_BOARD = - 2 #:
2222 SYNTHETIC_BOARD = - 1 #:
2323 CYTON_BOARD = 0 #:
24- GANGLION_BOARD = 1 #:
24+ GANGLION_BOARD = 1 #:
2525 CYTON_DAISY_BOARD = 2 #:
2626 GALEA_BOARD = 3 #:
2727 GANGLION_WIFI_BOARD = 4 #:
@@ -173,7 +173,15 @@ def __init__(self):
173173 dll_path = 'lib/libBoardController.dylib'
174174 else :
175175 dll_path = 'lib/libBoardController.so'
176- full_path = pkg_resources .resource_filename (__name__ , dll_path )
176+ try :
177+ resource = files (__name__ ).joinpath (dll_path )
178+ full_path = str (resource )
179+ except (TypeError , AttributeError ):
180+ # Fallback for:
181+ # 1. Python < 3.9 (importlib.resources.files not available)
182+ # 2. NixOS/packaging edge cases where importlib.resources may not work
183+ import pkg_resources
184+ full_path = pkg_resources .resource_filename (__name__ , dll_path )
177185 if os .path .isfile (full_path ):
178186 dir_path = os .path .abspath (os .path .dirname (full_path ))
179187 # for python we load dll by direct path but this dll may depend on other dlls and they will not be found!
Original file line number Diff line number Diff line change 66from typing import List , Tuple
77
88import numpy
9- import pkg_resources
9+ from importlib . resources import files
1010from brainflow .exit_codes import BrainFlowExitCodes , BrainFlowError
1111from brainflow .utils import check_memory_layout_row_major , LogLevels
1212from numpy .ctypeslib import ndpointer
@@ -153,7 +153,15 @@ def __init__(self):
153153 dll_path = 'lib/libDataHandler.dylib'
154154 else :
155155 dll_path = 'lib/libDataHandler.so'
156- full_path = pkg_resources .resource_filename (__name__ , dll_path )
156+ try :
157+ resource = files (__name__ ).joinpath (dll_path )
158+ full_path = str (resource )
159+ except (TypeError , AttributeError ):
160+ # Fallback for:
161+ # 1. Python < 3.9 (importlib.resources.files not available)
162+ # 2. NixOS/packaging edge cases where importlib.resources may not work
163+ import pkg_resources
164+ full_path = pkg_resources .resource_filename (__name__ , dll_path )
157165 if os .path .isfile (full_path ):
158166 dir_path = os .path .abspath (os .path .dirname (full_path ))
159167 # for python 3.8 PATH env var doesnt work anymore
Original file line number Diff line number Diff line change 77from typing import List
88
99import numpy
10- import pkg_resources
10+ from importlib . resources import files
1111from brainflow .board_shim import BrainFlowError , LogLevels
1212from brainflow .exit_codes import BrainFlowExitCodes
1313from numpy .ctypeslib import ndpointer
@@ -78,7 +78,15 @@ def __init__(self):
7878 dll_path = 'lib/libMLModule.dylib'
7979 else :
8080 dll_path = 'lib/libMLModule.so'
81- full_path = pkg_resources .resource_filename (__name__ , dll_path )
81+ try :
82+ resource = files (__name__ ).joinpath (dll_path )
83+ full_path = str (resource )
84+ except (TypeError , AttributeError ):
85+ # Fallback for:
86+ # 1. Python < 3.9 (importlib.resources.files not available)
87+ # 2. NixOS/packaging edge cases where importlib.resources may not work
88+ import pkg_resources
89+ full_path = pkg_resources .resource_filename (__name__ , dll_path )
8290 if os .path .isfile (full_path ):
8391 # for python we load dll by direct path but this dll may depend on other dlls and they will not be found!
8492 # to solve it we can load all of them before loading the main one or change PATH\LD_LIBRARY_PATH env var.
You can’t perform that action at this time.
0 commit comments