Skip to content

Commit c068e54

Browse files
committed
Add build with pyinstaller and remove build with nuitka
1 parent bc23d71 commit c068e54

File tree

4 files changed

+103
-18
lines changed

4 files changed

+103
-18
lines changed

build_with_nuitka.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

build_with_pyinstaller.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
pyinstaller \
3+
--console \
4+
--collect-data torch\
5+
--collect-data biotite\
6+
--collect-all biotite\
7+
--collect-data torch_geometric\
8+
--collect-all torch_geometric\
9+
--hidden-import torch_geometric\
10+
gui/qt_window.py
11+
# --add-data=X/:X/. \

gui/qt_window.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
# GUI created with PyQT/PySide
2-
import re
2+
#import re
33
import sys
4+
from io import StringIO
45
import os
56
import subprocess
67
from PySide6 import QtCore, QtWidgets
78
from PySide6.QtCore import QSize
89
pypef_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
10+
#sys.path.append(pypef_root)
11+
from pypef import __version__
912
from pypef.main import run_main
1013

1114

1215
EXEC_API_OR_CLI = ['api', 'cli'][0]
1316

1417

18+
class Capturing(list):
19+
"""https://stackoverflow.com/questions/16571150/how-to-capture-stdout-output-from-a-python-function-call"""
20+
def __enter__(self):
21+
self._stdout = sys.stdout
22+
sys.stdout = self._stringio = StringIO()
23+
return self
24+
def __exit__(self, *args):
25+
self.extend(self._stringio.getvalue().splitlines())
26+
del self._stringio # free up some memory
27+
sys.stdout = self._stdout
28+
29+
1530
def capture(command):
1631
proc = subprocess.Popen(
1732
command,
@@ -22,8 +37,8 @@ def capture(command):
2237
return out, err, proc.returncode
2338

2439

25-
out, err, exitcode = capture([f'python', f'{pypef_root}/run.py', '--version'])
26-
version = re.findall(r"[-+]?(?:\d*\.*\d.*\d+)", str(out))[0]
40+
#out, err, exitcode = capture([f'python', f'{pypef_root}/run.py', '--version'])
41+
#version = re.findall(r"[-+]?(?:\d*\.*\d.*\d+)", str(out))[0]
2742

2843
button_style = """
2944
QPushButton {
@@ -71,7 +86,7 @@ def __init__(
7186

7287
# Texts #############################################################################
7388
layout = QtWidgets.QGridLayout(self)
74-
self.version_text = QtWidgets.QLabel(f"PyPEF v. {version}", alignment=QtCore.Qt.AlignRight)
89+
self.version_text = QtWidgets.QLabel(f"PyPEF v. {__version__}", alignment=QtCore.Qt.AlignRight)
7590
self.ncores_text = QtWidgets.QLabel("Single-/multiprocessing")
7691
self.llm_text = QtWidgets.QLabel("LLM")
7792
self.regression_model_text = QtWidgets.QLabel("Regression model")
@@ -266,8 +281,8 @@ def __init__(
266281
layout.addWidget(self.textedit_out, 8, 0, 1, -1)
267282

268283
self.process = QtCore.QProcess(self)
269-
self.process.setProcessChannelMode(QtCore.QProcess.MergedChannels)
270-
self.process.readyReadStandardOutput.connect(self.on_readyReadStandardOutput)
284+
#self.process.setProcessChannelMode(QtCore.QProcess.MergedChannels)
285+
#self.process.readyReadStandardOutput.connect(self.on_readyReadStandardOutput)
271286
self.process.started.connect(lambda: self.button_help.setEnabled(False))
272287
self.process.finished.connect(lambda: self.button_help.setEnabled(True))
273288
self.process.started.connect(lambda: self.button_mklsts.setEnabled(False))
@@ -463,8 +478,20 @@ def exec_pypef_cli(self, cmd):
463478
self.textedit_out.append("=" * 104 + "\n")
464479

465480
def exec_pypef_api(self, cmd):
466-
run_main(argv=cmd)
467-
pass
481+
self.textedit_out.append(f'Executing command:{cmd}')
482+
try:
483+
with Capturing() as captured_output:
484+
run_main(argv=cmd)
485+
print(captured_output)
486+
for cap_out_text in captured_output:
487+
self.textedit_out.append(cap_out_text)
488+
except Exception as e: # anything
489+
self.textedit_out.append(f"Provided wrong inputs! Error: {e}")
490+
finally:
491+
self.process.finished.connect(self.process_finished)
492+
if self.c > 0:
493+
self.textedit_out.append("=" * 104 + "\n")
494+
468495

469496
def process_finished(self):
470497
self.version_text.setText("Finished...")

qt_window.spec

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
from PyInstaller.utils.hooks import collect_data_files
3+
from PyInstaller.utils.hooks import collect_all
4+
5+
datas = []
6+
binaries = []
7+
hiddenimports = ['torch_geometric']
8+
datas += collect_data_files('torch')
9+
datas += collect_data_files('biotite')
10+
datas += collect_data_files('torch_geometric')
11+
tmp_ret = collect_all('biotite')
12+
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
13+
tmp_ret = collect_all('torch_geometric')
14+
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
15+
16+
17+
a = Analysis(
18+
['gui/qt_window.py'],
19+
pathex=[],
20+
binaries=binaries,
21+
datas=datas,
22+
hiddenimports=hiddenimports,
23+
hookspath=[],
24+
hooksconfig={},
25+
runtime_hooks=[],
26+
excludes=[],
27+
noarchive=False,
28+
optimize=0,
29+
)
30+
pyz = PYZ(a.pure)
31+
32+
exe = EXE(
33+
pyz,
34+
a.scripts,
35+
[],
36+
exclude_binaries=True,
37+
name='qt_window',
38+
debug=False,
39+
bootloader_ignore_signals=False,
40+
strip=False,
41+
upx=True,
42+
console=True,
43+
disable_windowed_traceback=False,
44+
argv_emulation=False,
45+
target_arch=None,
46+
codesign_identity=None,
47+
entitlements_file=None,
48+
)
49+
coll = COLLECT(
50+
exe,
51+
a.binaries,
52+
a.datas,
53+
strip=False,
54+
upx=True,
55+
upx_exclude=[],
56+
name='qt_window',
57+
)

0 commit comments

Comments
 (0)