diff --git a/.github/workflows/release-tests.yml b/.github/workflows/release-tests.yml index cdd31cee..6f841db9 100644 --- a/.github/workflows/release-tests.yml +++ b/.github/workflows/release-tests.yml @@ -31,7 +31,7 @@ jobs: deb-package: needs: version - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Install Makedeb run: | @@ -41,9 +41,9 @@ jobs: sudo apt install makedeb - name: Prepare source directory run: | - git clone https://mpr.hunterwittenborn.com/rare.git build + git clone https://mpr.makedeb.org/rare build sed -i 's/source=.*/source=("rare-test::git+$url")/g' build/PKGBUILD - sed -i "s/\$pkgver/test/g" build/PKGBUILD + sed -i "s/\$pkgver/${{ needs.version.outputs.tag_abbrev }}.${{ needs.version.outputs.tag_offset }}/g" build/PKGBUILD - name: build deb run: | @@ -73,7 +73,6 @@ jobs: sudo pip3 install appimage-builder - name: Build run: | - cp rare/__main__.py . appimage-builder --skip-test mv Rare-*.AppImage Rare.AppImage mv Rare-*.AppImage.zsync Rare.AppImage.zsync @@ -198,7 +197,7 @@ jobs: pip3 install -r requirements-presence.txt pip3 install . - name: Build - run: cxfreeze -c rare/__main__.py --target-dir dist --target-name rare --icon rare/resources/images/Rare.ico -OO --base-name Win32GUI + run: cxfreeze -c rare/main.py --target-dir dist --target-name rare --icon rare/resources/images/Rare.ico -OO --base-name Win32GUI - name: Compress run: | python -c "import shutil; shutil.make_archive('Rare-Windows', 'zip', 'dist')" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c0273f6c..185637e4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,7 +35,7 @@ jobs: twine upload dist/* deb-package: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Install Makedeb run: | @@ -78,7 +78,6 @@ jobs: sudo pip3 install appimage-builder - name: Build run: | - cp rare/__main__.py . appimage-builder --skip-test mv Rare-*.AppImage Rare.AppImage mv Rare-*.AppImage.zsync Rare.AppImage.zsync @@ -212,7 +211,7 @@ jobs: pip3 install -r requirements-presence.txt pip3 install . - name: Build - run: cxfreeze -c rare/__main__.py --target-dir dist --target-name rare --icon rare/resources/images/Rare.ico -OO --base-name Win32GUI + run: cxfreeze -c rare/main.py --target-dir dist --target-name rare --icon rare/resources/images/Rare.ico -OO --base-name Win32GUI - name: Compress run: | python -c "import shutil; shutil.make_archive('Rare-Windows', 'zip', 'dist')" diff --git a/AppImageBuilder.yml b/AppImageBuilder.yml index 2c9a4cae..908bbe38 100644 --- a/AppImageBuilder.yml +++ b/AppImageBuilder.yml @@ -3,13 +3,12 @@ version: 1 script: # Remove any previous build - - rm -rf AppDir Rare | true + - rm -rf AppDir | true # Make usr and icons dirs - mkdir -p AppDir/usr/src - mkdir -p AppDir/usr/share/icons/hicolor/256x256/apps/ # Copy source files - cp -r rare AppDir/usr/src/rare - - mv AppDir/usr/src/rare/__main__.py AppDir/usr/src/ # copy Logo - cp AppDir/usr/src/rare/resources/images/Rare.png AppDir/usr/share/icons/hicolor/256x256/apps/ # Install application dependencies @@ -23,7 +22,7 @@ AppDir: icon: Rare version: 1.10.7 exec: usr/bin/python3 - exec_args: $APPDIR/usr/src/__main__.py $@ + exec_args: $APPDIR/usr/src/rare/main.py $@ apt: arch: amd64 allow_unauthenticated: true diff --git a/freeze.py b/freeze.py index 19f4bf48..99c1b49a 100644 --- a/freeze.py +++ b/freeze.py @@ -31,9 +31,11 @@ bdist_msi_options = { base = "Win32GUI" exe = Executable( - "rare/__main__.py", - base=base, icon="rare/resources/images/Rare.ico", - target_name="Rare") + "rare/main.py", + base=base, + icon="rare/resources/images/Rare.ico", + target_name=name +) setup( name=name, diff --git a/pyproject.toml b/pyproject.toml index 466ea084..4e33bca5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ legendary-gl = "^0.20.34" typing-extensions = "^4.3.0" [tool.poetry.scripts] -start = "rare.__main__:main" +start = "rare.main:main" [tool.poetry.dev-dependencies] Nuitka = "^1.0.6" diff --git a/rare/__init__.py b/rare/__init__.py index 55431f1d..a1e30886 100644 --- a/rare/__init__.py +++ b/rare/__init__.py @@ -4,7 +4,5 @@ __codename__ = "Garlic Crab" # For PyCharm profiler if __name__ == "__main__": import sys - from argparse import Namespace - from rare import client - status = client.start(Namespace(debug=True, silent=False, offline=False, test_start=False)) - sys.exit(status) + from rare.main import main + sys.exit(main()) diff --git a/rare/__main__.py b/rare/__main__.py old mode 100755 new mode 100644 index 73c789a8..6d290a34 --- a/rare/__main__.py +++ b/rare/__main__.py @@ -1,29 +1,4 @@ -import os -import pathlib -import sys - if __name__ == "__main__": + import sys from rare.main import main - - # run from source - # insert raw legendary submodule - # sys.path.insert( - # 0, os.path.join(pathlib.Path(__file__).parent.absolute(), "legendary") - # ) - - # insert source directory - 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 - # 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())): - # 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') - sys.exit(main()) diff --git a/rare/main.py b/rare/main.py old mode 100644 new mode 100755 index 7d1c5dd1..312bdafe --- a/rare/main.py +++ b/rare/main.py @@ -1,9 +1,22 @@ import multiprocessing import os +import pathlib +import sys from argparse import ArgumentParser def main() -> int: + # 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())): + # 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') + # fix cx_freeze multiprocessing.freeze_support() @@ -101,3 +114,18 @@ def main() -> int: from rare.components import start return start(args) + + +if __name__ == "__main__": + # run from source + # insert raw legendary submodule + # sys.path.insert( + # 0, os.path.join(pathlib.Path(__file__).parent.absolute(), "legendary") + # ) + + # insert source directory if running `main.py` as python script + # Required by AppImage + if "__compiled__" not in globals(): + sys.path.insert(0, str(pathlib.Path(__file__).parents[1].absolute())) + + sys.exit(main()) diff --git a/rare/utils/paths.py b/rare/utils/paths.py index a6593623..45cf02d1 100644 --- a/rare/utils/paths.py +++ b/rare/utils/paths.py @@ -142,7 +142,7 @@ def get_rare_executable() -> List[str]: if sys.executable == os.path.abspath(sys.argv[0]): executable = [sys.executable] else: - executable = [sys.executable, os.path.abspath(sys.argv[0])] + executable = [os.path.abspath(sys.argv[0])] elif platform.system() == "Windows": executable = [sys.executable]