From 92e1771db5a4bf9c73af4337ee77f82a62774cee Mon Sep 17 00:00:00 2001 From: "Michal Krenek (Mikos)" Date: Thu, 23 Mar 2017 18:11:05 +0100 Subject: [PATCH] Add support for creating frozen executables with cx_Freeze; use new setup_qt module for building Qt UI files --- qspectrumanalyzer.py | 5 +++ qspectrumanalyzer/backends/__init__.py | 6 +++- setup-qt.py | 29 ---------------- setup.py | 47 ++++++++++++++++++++++++-- soapy_power.py | 5 +++ 5 files changed, 60 insertions(+), 32 deletions(-) create mode 100755 qspectrumanalyzer.py delete mode 100755 setup-qt.py create mode 100755 soapy_power.py diff --git a/qspectrumanalyzer.py b/qspectrumanalyzer.py new file mode 100755 index 0000000..825e1e6 --- /dev/null +++ b/qspectrumanalyzer.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +from qspectrumanalyzer.__main__ import main + +if __name__ == '__main__': + main() diff --git a/qspectrumanalyzer/backends/__init__.py b/qspectrumanalyzer/backends/__init__.py index d6eebbd..4d9ff6e 100644 --- a/qspectrumanalyzer/backends/__init__.py +++ b/qspectrumanalyzer/backends/__init__.py @@ -106,7 +106,11 @@ class BasePowerThread(QtCore.QThread): # Build list of all backends -_backends_files = glob.glob(os.path.join(os.path.dirname(__file__), "*.py")) +_base_path = os.path.realpath(os.path.dirname(__file__)) +_backends_files = (glob.glob(os.path.join(_base_path, "*.py")) + + glob.glob(os.path.join(_base_path, "*.pyc")) + + glob.glob(os.path.join(_base_path, "*.pyo"))) + __all__ = [os.path.splitext(os.path.basename(f))[0] for f in _backends_files if os.path.isfile(f) and not os.path.basename(f).startswith("_")] diff --git a/setup-qt.py b/setup-qt.py deleted file mode 100755 index fdd0bff..0000000 --- a/setup-qt.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python - -import os, shutil -from glob import glob - -package = "qspectrumanalyzer" -languages = ["cs"] - -print("Rebuilding PyQt resource files...") -for f in glob("{}/*.qrc".format(package)): - os.system("pyrcc5 -o {}/qrc_{}.py {}".format(package, os.path.basename(f[:-4]), f)) - -print("Rebuilding PyQt UI files...") -for f in glob("{}/*.ui".format(package)): - os.system("pyuic5 -o {}/ui_{}.py {}".format(package, os.path.basename(f[:-3]), f)) - -print("Changing compiled UI files from PyQt5 to Qt.py wrapper...") -os.system("sed -i 's/^from PyQt5 import/from Qt import/g' {}/ui_*.py".format(package)) - -print("Updating translations...") -lang_files = " ".join("{}/languages/{}_{}.ts".format(package, package, lang) for lang in languages) -os.system("pylupdate5 {}/*.py -ts {}".format(package, lang_files)) -os.system("lrelease {}/languages/*.ts".format(package)) - -print("Regenerating .pyc files...") -shutil.rmtree("{}/__pycache__".format(package), ignore_errors=True) -for f in glob("{}/*.pyc".format(package)): - os.remove(f) -__import__("{}.__main__".format(package)) diff --git a/setup.py b/setup.py index a48c4d1..a421423 100755 --- a/setup.py +++ b/setup.py @@ -1,8 +1,33 @@ #!/usr/bin/env python -from setuptools import setup +import sys, pathlib, subprocess, shutil, re +import setuptools + from qspectrumanalyzer.version import __version__ +setup_cmdclass = {} +setup_kwargs = {} + +# Allow compilation of Qt .qrc, .ui and .ts files (build_qt command) +try: + from setup_qt import build_qt + setup_cmdclass['build_qt'] = build_qt +except ImportError: + pass + +# Allow building of frozen executables with cx_Freeze (build_exe command) +try: + from cx_Freeze import setup, Executable + + base = 'Win32GUI' if sys.platform == 'win32' else None + setup_kwargs['executables'] = [ + Executable('qspectrumanalyzer.py', base=base), + Executable('soapy_power.py', base=None), + ] +except ImportError: + from setuptools import setup + + setup( name="QSpectrumAnalyzer", version=__version__, @@ -48,5 +73,23 @@ setup( "Programming Language :: Python :: 3", "Topic :: Communications :: Ham Radio", "Topic :: Scientific/Engineering :: Visualization" - ] + ], + options={ + 'build_exe': { + 'packages': ['qspectrumanalyzer', 'qspectrumanalyzer.backends'], + 'excludes': [], + 'includes': [ + 'numpy.core._methods', 'numpy.lib.format', 'pyqtgraph.debug', 'pyqtgraph.ThreadsafeTimer' + ], + 'include_msvcr': True, + 'optimize': 2, + }, + 'build_qt': { + 'packages': ['qspectrumanalyzer'], + 'languages': ['cs'], + 'replacement_bindings': 'Qt' + }, + }, + cmdclass=setup_cmdclass, + **setup_kwargs ) diff --git a/soapy_power.py b/soapy_power.py new file mode 100755 index 0000000..b8765f6 --- /dev/null +++ b/soapy_power.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +from soapypower.__main__ import main + +if __name__ == '__main__': + main()