Skip to content

Commit c3a28e2

Browse files
authored
fixing pkg resources issue with windows emulator (#793)
* bump python in windows ci to 3.11 Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com> * dont use pkg resources for emulator Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com> --------- Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com>
1 parent 5c46431 commit c3a28e2

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

.github/workflows/run_windows.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
uses: actions/setup-dotnet@v3
2222
with:
2323
dotnet-version: '7.0.x'
24+
- name: Setup Python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: '3.11'
2428
- name: Set Version
2529
id: version
2630
run: if ("tag" -eq $Env:GITHUB_REF_TYPE) { echo "::set-output name=version::$Env:GITHUB_REF_NAME" } else { echo "::set-output name=version::$Env:GITHUB_SHA" }
@@ -67,6 +71,7 @@ jobs:
6771
shell: cmd
6872
- name: Install Emulator
6973
run: |
74+
pip install setuptools
7075
pip install %GITHUB_WORKSPACE%\emulator\
7176
cd %GITHUB_WORKSPACE%
7277
.\emulator\brainflow_emulator\com0com\certmgr.exe /add %GITHUB_WORKSPACE%\emulator\brainflow_emulator\com0com\com0com.cer /s /r localMachine root

emulator/brainflow_emulator/cyton_windows.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import time
66

7-
from importlib.resources import files
7+
from pathlib import Path
88
from brainflow_emulator.emulate_common import TestFailureError, Listener, log_multilines
99
from serial import Serial
1010

@@ -17,24 +17,20 @@ def read(port, num_bytes):
1717
return port.read(num_bytes)
1818

1919

20-
def get_isntaller():
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'))
20+
def get_installer():
21+
return str(
22+
Path(__file__).resolve().parent
23+
/ "com0com"
24+
/ "setup_com0com_W7_x64_signed.exe"
25+
)
3026

3127

3228
def install_com0com():
3329
this_directory = os.path.abspath(os.path.dirname(__file__))
3430
directory = os.path.join(this_directory, 'com0com')
3531
if not os.path.exists(directory):
3632
os.makedirs(directory)
37-
cmds = [get_isntaller(), '/NCRC', '/S', '/D=%s' % directory]
33+
cmds = [get_installer(), '/NCRC', '/S', '/D=%s' % directory]
3834
logging.info('running %s' % ' '.join(cmds))
3935
p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4036
out, err = p.communicate()

emulator/brainflow_emulator/freeeeg32_windows.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import time
66

7-
from importlib.resources import files
7+
from pathlib import Path
88
from brainflow_emulator.emulate_common import TestFailureError, log_multilines
99
from brainflow_emulator.freeeeg32_emulator import Listener
1010
from serial import Serial
@@ -18,24 +18,20 @@ def read(port, num_bytes):
1818
return port.read(num_bytes)
1919

2020

21-
def get_isntaller():
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'))
21+
def get_installer():
22+
return str(
23+
Path(__file__).resolve().parent
24+
/ "com0com"
25+
/ "setup_com0com_W7_x64_signed.exe"
26+
)
3127

3228

3329
def install_com0com():
3430
this_directory = os.path.abspath(os.path.dirname(__file__))
3531
directory = os.path.join(this_directory, 'com0com')
3632
if not os.path.exists(directory):
3733
os.makedirs(directory)
38-
cmds = [get_isntaller(), '/NCRC', '/S', '/D=%s' % directory]
34+
cmds = [get_installer(), '/NCRC', '/S', '/D=%s' % directory]
3935
logging.info('running %s' % ' '.join(cmds))
4036
p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4137
out, err = p.communicate()

0 commit comments

Comments
 (0)