From 9d2868080492d5c68a1ddf0082f462ee5a7493a0 Mon Sep 17 00:00:00 2001 From: Stelios Tsampas Date: Mon, 12 Sep 2022 14:19:24 +0300 Subject: [PATCH] Build: enable console output on windows if it is a test build --- .github/workflows/release-tests.yml | 25 ++++++++++++++++++++----- .github/workflows/release.yml | 25 ++++++++++++++++++++----- misc/nuitka_build.bat | 28 ++++++++++++++++++++++++++++ misc/nuitka_rare.bat | 1 - rare/__main__.py | 11 +++++++---- requirements-full.txt | 2 ++ requirements-webview.txt | 2 ++ 7 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 misc/nuitka_build.bat delete mode 100644 misc/nuitka_rare.bat diff --git a/.github/workflows/release-tests.yml b/.github/workflows/release-tests.yml index 9f3cdb4c..03974bc2 100644 --- a/.github/workflows/release-tests.yml +++ b/.github/workflows/release-tests.yml @@ -86,16 +86,31 @@ jobs: run: >- python -m nuitka --assume-yes-for-downloads - --follow-imports --prefer-source-code --mingw64 --lto=no --jobs=2 --static-libpython=no --standalone - --enable-plugin=anti-bloat --enable-plugin=pyqt5 --show-anti-bloat-changes --nofollow-import-to="*.tests" - --nofollow-import-to="*.distutils" --include-package-data=qtawesome + --mingw64 + --lto=no + --jobs=2 + --static-libpython=no + --standalone + --enable-plugin=anti-bloat + --enable-plugin=pyqt5 + --show-modules + --show-anti-bloat-changes + --follow-stdlib + --follow-imports + --nofollow-import-to="*.tests" + --nofollow-import-to="*.distutils" + --prefer-source-code + --include-package=pypresence + --include-package-data=qtawesome --include-data-dir=rare\resources\images=rare\resources\images --include-data-files=rare\resources\languages=rare\resources\languages="*.qm" --windows-icon-from-ico=rare\resources\images\Rare.ico - --windows-company-name=Rare --windows-product-name=Rare --windows-file-description=rare.exe + --windows-company-name=Rare + --windows-product-name=Rare + --windows-file-description=rare.exe --windows-file-version=0.0.0.0 --windows-product-version=0.0.0.0 - --windows-disable-console + --enable-console rare - name: Upload to Artifacts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 391878ac..1c6ce322 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -118,16 +118,31 @@ jobs: run: >- python -m nuitka --assume-yes-for-downloads - --follow-imports --prefer-source-code --mingw64 --lto=no --jobs=2 --static-libpython=no --standalone - --enable-plugin=anti-bloat --enable-plugin=pyqt5 --show-anti-bloat-changes --nofollow-import-to="*.tests" - --nofollow-import-to="*.distutils" --include-package-data=qtawesome + --mingw64 + --lto=no + --jobs=2 + --static-libpython=no + --standalone + --enable-plugin=anti-bloat + --enable-plugin=pyqt5 + --show-modules + --show-anti-bloat-changes + --follow-stdlib + --follow-imports + --nofollow-import-to="*.tests" + --nofollow-import-to="*.distutils" + --prefer-source-code + --include-package=pypresence + --include-package-data=qtawesome --include-data-dir=rare\resources\images=rare\resources\images --include-data-files=rare\resources\languages=rare\resources\languages="*.qm" --windows-icon-from-ico=rare\resources\images\Rare.ico - --windows-company-name=Rare --windows-product-name=Rare --windows-file-description=rare.exe + --windows-company-name=Rare + --windows-product-name=Rare + --windows-file-description=rare.exe --windows-file-version=${{ github.event.release.tag_name }} --windows-product-version=${{ github.event.release.tag_name }} - --windows-disable-console + --disable-console rare - name: Compress run: | diff --git a/misc/nuitka_build.bat b/misc/nuitka_build.bat new file mode 100644 index 00000000..5d00c1da --- /dev/null +++ b/misc/nuitka_build.bat @@ -0,0 +1,28 @@ +python -m nuitka ^ +--assume-yes-for-downloads ^ +--mingw64 ^ +--lto=no ^ +--jobs=2 ^ +--static-libpython=no ^ +--standalone ^ +--enable-plugin=anti-bloat ^ +--enable-plugin=pyqt5 ^ +--show-modules ^ +--show-anti-bloat-changes ^ +--follow-stdlib ^ +--follow-imports ^ +--nofollow-import-to="*.tests" ^ +--nofollow-import-to="*.distutils" ^ +--prefer-source-code ^ +--include-package=pypresence ^ +--include-package-data=qtawesome ^ +--include-data-dir=rare\resources\images=rare\resources\images ^ +--include-data-files=rare\resources\languages=rare\resources\languages="*.qm" ^ +--windows-icon-from-ico=rare\resources\images\Rare.ico ^ +--windows-company-name=Rare ^ +--windows-product-name=Rare ^ +--windows-file-description=rare.exe ^ +--windows-file-version=0.0.0.0 ^ +--windows-product-version=0.0.0.0 ^ +--enable-console ^ +rare diff --git a/misc/nuitka_rare.bat b/misc/nuitka_rare.bat deleted file mode 100644 index aeb701a1..00000000 --- a/misc/nuitka_rare.bat +++ /dev/null @@ -1 +0,0 @@ -python -m nuitka --assume-yes-for-downloads --follow-imports --prefer-source-code --mingw64 --lto=no --jobs=2 --static-libpython=no --standalone --enable-plugin=anti-bloat --enable-plugin=pyqt5 --show-anti-bloat-changes --nofollow-import-to="*.tests" --nofollow-import-to="*.distutils" --include-package-data=qtawesome --include-data-dir=rare\resources\images=rare\resources\images --include-data-files=rare\resources\languages=rare\resources\languages="*.qm" --windows-icon-from-ico=rare\resources\images\Rare.ico --windows-company-name=Rare --windows-product-name=Rare --windows-file-description=rare.exe --windows-file-version=1.9.0 --windows-product-version=1.9.0 --windows-disable-console rare diff --git a/rare/__main__.py b/rare/__main__.py index 5a9348d6..6cd6d50c 100644 --- a/rare/__main__.py +++ b/rare/__main__.py @@ -117,12 +117,15 @@ if __name__ == "__main__": if "__compiled__" not in globals(): sys.path.insert(0, str(pathlib.Path(__file__).parents[1].absolute())) - # If we are on Windows, and we are in a "compiled" GUI application form + # If we are on Windows, and we are in a "compiled" GUI application form # stdout (and stderr?) will be None. So to avoid `'NoneType' object has no attribute 'write'` # errors, redirect both of them to devnull if os.name == "nt" and (getattr(sys, "frozen", False) or ("__compiled__" in globals())): - f = open(os.devnull, 'w') - sys.stdout = f - sys.stderr = f + # Check if stdout and stderr are None before redirecting + # This is useful in the case of test builds that enable console + if sys.stdout is None: + sys.stdout = open(os.devnull, 'w') + if sys.stderr is None: + sys.stderr = open(os.devnull, 'w') main() diff --git a/requirements-full.txt b/requirements-full.txt index 7ee86ac0..cbd4cb0c 100644 --- a/requirements-full.txt +++ b/requirements-full.txt @@ -6,5 +6,7 @@ setuptools legendary-gl pywin32; platform_system == "Windows" pywebview[qt]; platform_system == "Linux" +pythonnet>=3.0.0rc4; platform_system == "Windows" +cefpython3; platform_system == "Windows" pywebview[cef]; platform_system == "Windows" pypresence diff --git a/requirements-webview.txt b/requirements-webview.txt index 1ee0e8e6..32befea2 100644 --- a/requirements-webview.txt +++ b/requirements-webview.txt @@ -1,3 +1,5 @@ pywebview[qt]; platform_system == "Linux" +pythonnet>=3.0.0rc4; platform_system == "Windows" +cefpython3; platform_system == "Windows" pywebview[cef]; platform_system == "Windows"