diff --git a/.github/workflows/cxFreeze.yml b/.github/workflows/cxFreeze.yml new file mode 100644 index 0000000..b75b79d --- /dev/null +++ b/.github/workflows/cxFreeze.yml @@ -0,0 +1,80 @@ +on: + push: + +env: + CHIRP_DIR: ${{github.workspace}}\temp\chirp + BASH: C:\tools\cygwin\bin\bash + +jobs: + build: + runs-on: windows-latest + + steps: + + - name: "Checkout repository" + uses: actions/checkout@v3 + + - name: "Install Python" + uses: actions/setup-python@v5 + with: + python-version: '3.9' + cache: 'pip' + cache-dependency-path: 'chirp\requirements-dev.txt' + + - name: "Instal Python packages" + run: pip install -r chirp\requirements-dev.txt + + - name: "Install Cygwin" + uses: egor-tensin/setup-cygwin@v4 + with: + packages: make gettext + + - name: "Prepare CHIRP repository" + run: > + New-Item -ItemType Directory -Force -Path temp && + cd temp && + git clone https://github.com/kk7ds/chirp.git && + Copy-Item -Path "${{github.workspace}}\chirp\Makefile" -Destination "${{env.CHIRP_DIR}}\chirp\locale\" -Force && + Copy-Item -Path "${{github.workspace}}\chirp\chirp.patch" -Destination "${{env.CHIRP_DIR}}\" -Force && + Copy-Item -Path "${{github.workspace}}\chirp\setupCxFreeze.py" -Destination "${{env.CHIRP_DIR}}\" -Force && + Copy-Item -Path "${{github.workspace}}\uvk5_egzumer.py" -Destination "${{env.CHIRP_DIR}}\chirp\drivers\" -Force && + cd chirp && + git apply chirp.patch; + if ("${{github.ref}}" -like "refs/tags/v*") { + $content = Get-Content -Path "chirp\__init__.py" -Raw; + $content = $content -replace 'CHIRP_VERSION = "py3dev"', "CHIRP_VERSION = `"${{github.ref_name}}`""; + Set-Content -Path "chirp\__init__.py" -Value $content; + $content = Get-Content -Path "setupCxFreeze.py" -Raw; + $content = $content -replace "version = '0.1'", "version = '${{github.ref_name}}'"; + Set-Content -Path "setupCxFreeze.py" -Value $content; + } + + - name: "Build CHIRP locale" + run: > + ${{env.BASH}} --login -c "cd '${{env.CHIRP_DIR}}\chirp\locale'; make" && + ${{env.BASH}} --login -c "cd '${{env.CHIRP_DIR}}'; find chirp/locale/ -maxdepth 1 -type f -delete" + + - name: "Build CHIRP" + run: > + cd "${{env.CHIRP_DIR}}"; + python setupCxFreeze.py build; + cd build; + Get-ChildItem -Directory -Filter 'exe.win*' | ForEach-Object { Rename-Item $_.FullName -NewName 'CHIRP_egzumer' }; + Compress-Archive CHIRP_egzumer\ CHIRP_egzumer.zip + + - name: 'Upload Artifact' + uses: actions/upload-artifact@v3 + with: + name: CHIRP_egzumer + path: ${{env.CHIRP_DIR}}\build\CHIRP_egzumer\ + + - name: Upload onefile to release + if: ${{ startsWith(github.ref, 'refs/tags/v') }} + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{env.CHIRP_DIR}}\build\CHIRP_egzumer.zip + asset_name: CHIRP_egzumer.zip + tag: ${{ github.ref }} + overwrite: true + release_name: release ${{ github.ref_name }} diff --git a/chirp/chirp.patch b/chirp/chirp.patch index 3731fbc..76b5b72 100644 --- a/chirp/chirp.patch +++ b/chirp/chirp.patch @@ -58,3 +58,79 @@ index d2ca7711..d0e4dfc0 100644 @with_session +diff --git a/chirp/drivers/__init__.py b/chirp/drivers/__init__.py +index 649f85ab..c8940547 100644 +--- a/chirp/drivers/__init__.py ++++ b/chirp/drivers/__init__.py +@@ -1,16 +1,8 @@ +-import os + import sys +-from glob import glob +-import warnings ++import pkgutil + +-# This won't be here in the frozen build because we convert this file to +-# a static list of driver modules to import. +-warnings.filterwarnings('once', category=DeprecationWarning, +- module=__name__) +- +-module_dir = os.path.dirname(sys.modules["chirp.drivers"].__file__) ++module_dir = sys.modules["chirp.drivers"].__path__ + __all__ = [] +-for i in sorted(glob(os.path.join(module_dir, "*.py"))): +- name = os.path.basename(i)[:-3] +- if not name.startswith("__"): +- __all__.append(name) ++for i in pkgutil.iter_modules(module_dir): ++ __all__.append(i.name) ++__all__.sort() +diff --git a/chirp/directory.py b/chirp/directory.py +index e25ae10d..618e2cf1 100644 +--- a/chirp/directory.py ++++ b/chirp/directory.py +@@ -14,10 +14,9 @@ + # You should have received a copy of the GNU General Public License + # along with this program. If not, see . + +-import glob + import os + import logging +-import sys ++import chirp.drivers + + from chirp import chirp_common, errors + +@@ -172,27 +171,10 @@ def get_radio_by_image(image_file): + + + def import_drivers(limit=None): +- frozen = getattr(sys, 'frozen', False) +- if sys.platform == 'win32' and frozen: +- # We are in a frozen win32 build, so we can not glob +- # the driver files, but we do not need to anyway +- import chirp.drivers +- for module in chirp.drivers.__all__: +- try: +- __import__('chirp.drivers.%s' % module) +- except Exception as e: +- print('Failed to import %s: %s' % (module, e)) +- return +- +- # Safe import of everything in chirp/drivers. We need to import them +- # to get them to register, but should not abort if one import fails +- chirp_module_base = os.path.dirname(os.path.abspath(__file__)) +- driver_files = glob.glob(os.path.join(chirp_module_base, +- 'drivers', +- '*.py')) +- for driver_file in driver_files: +- module, ext = os.path.splitext(driver_file) +- driver_module = os.path.basename(module) +- if limit and driver_module not in limit: ++ for module in chirp.drivers.__all__: ++ if limit and module not in limit: + continue +- __import__('chirp.drivers.%s' % driver_module) ++ try: ++ __import__('chirp.drivers.%s' % module) ++ except Exception as e: ++ print('Failed to import %s: %s' % (module, e)) diff --git a/chirp/requirements-dev.txt b/chirp/requirements-dev.txt index c70da47..6dd4843 100644 --- a/chirp/requirements-dev.txt +++ b/chirp/requirements-dev.txt @@ -6,4 +6,5 @@ pyserial requests yattag wheel -importlib-resources \ No newline at end of file +importlib-resources +cx_Freeze \ No newline at end of file diff --git a/chirp/setupCxFreeze.py b/chirp/setupCxFreeze.py new file mode 100644 index 0000000..02d81ee --- /dev/null +++ b/chirp/setupCxFreeze.py @@ -0,0 +1,22 @@ +from cx_Freeze import setup, Executable + +# Dependencies are automatically detected, but it might need +# fine tuning. +build_options = { + 'packages': ['chirp.drivers'], + 'excludes': [] + } + +import sys +base = 'Win32GUI' if sys.platform=='win32' else None + +executables = [ + Executable('chirpwx.py', base=base, target_name = 'CHIRP_egzumer', icon = 'chirp/share/chirp.ico') +] + +setup(name='CHIRP egzumer', + version = '0.1', + description = 'modfied CHIRP with UV-K5 egzumer firmware driver', + options = {'build_exe': build_options}, + executables = executables) +