From 87d0e0e32ee7864d349c953de9849ef035b56f10 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:04:04 +0200 Subject: [PATCH 01/10] rework cli --- requirements.txt | 1 + src/iSponsorBlockTV/helpers.py | 88 +++++++++++++++++++++------------- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/requirements.txt b/requirements.txt index e30c014..a30b6c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ ssdp==1.3.0 textual==0.58.0 textual-slider==0.1.1 xmltodict==0.13.0 +rich_click==1.8.3 \ No newline at end of file diff --git a/src/iSponsorBlockTV/helpers.py b/src/iSponsorBlockTV/helpers.py index 3bce12c..aa5490a 100644 --- a/src/iSponsorBlockTV/helpers.py +++ b/src/iSponsorBlockTV/helpers.py @@ -1,4 +1,4 @@ -import argparse +import rich_click as click import json import logging import os @@ -126,35 +126,59 @@ class Config: return False -def app_start(): - # If env has a data dir use that, otherwise use the default - default_data_dir = os.getenv("iSPBTV_data_dir") or user_data_dir( - "iSponsorBlockTV", "dmunozv04" - ) - parser = argparse.ArgumentParser(description="iSponsorblockTV") - parser.add_argument( - "--data-dir", "-d", default=default_data_dir, help="data directory" - ) - parser.add_argument( - "--setup", "-s", action="store_true", help="setup the program graphically" - ) - parser.add_argument( - "--setup-cli", - "-sc", - action="store_true", - help="setup the program in the command line", - ) - parser.add_argument("--debug", action="store_true", help="debug mode") - args = parser.parse_args() - - config = Config(args.data_dir) - if args.debug: +@click.group(invoke_without_command=True) +@click.option('--data', '-d', default=lambda: os.getenv("iSPBTV_data_dir") or user_data_dir("iSponsorBlockTV", "dmunozv04"), help='data directory') +@click.option('--debug', is_flag=True, help='debug mode') +#legacy commands as arguments +@click.option('--setup', is_flag=True, help='Setup the program graphically', hidden=True) +@click.option('--setup-cli', is_flag=True, help='Setup the program in the command line', hidden=True) +@click.pass_context +def cli(ctx, data, debug, setup, setup_cli): + """iSponsorblockTV""" + ctx.ensure_object(dict) + ctx.obj['data_dir'] = data + ctx.obj['debug'] = debug + if debug: logging.basicConfig(level=logging.DEBUG) - if args.setup: # Set up the config file graphically - setup_wizard.main(config) - sys.exit() - if args.setup_cli: # Set up the config file - config_setup.main(config, args.debug) - else: - config.validate() - main.main(config, args.debug) + if ctx.invoked_subcommand is None: + if setup: + ctx.invoke(setup_command) + elif setup_cli: + ctx.invoke(setup_cli_command) + else: + ctx.invoke(start) + +@cli.command() +@click.pass_context +def setup(ctx): + """Setup the program graphically""" + config = Config(ctx.obj['data_dir']) + setup_wizard.main(config) + sys.exit() +setup_command = setup +@cli.command() +@click.pass_context +def setup_cli(ctx): + """Setup the program in the command line""" + config = Config(ctx.obj['data_dir']) + config_setup.main(config, ctx.obj['debug']) +setup_cli_command = setup_cli +@cli.command() +@click.pass_context +def start(ctx): + """Start the main program""" + config = Config(ctx.obj['data_dir']) + config.validate() + main.main(config, ctx.obj['debug']) + +# Create fake "self" group to show pyapp options in help menu +#Subcommands remove, restore, update +pyapp_group = click.RichGroup("self", help="pyapp options (update, remove, restore)") +pyapp_group.add_command(click.RichCommand("update", help="Update the package to the latest version")) +pyapp_group.add_command(click.Command("remove", help="Remove the package, wiping the installation but not the data")) +pyapp_group.add_command(click.RichCommand("restore", help="Restore the package to its original state by reinstalling it")) +if os.getenv("PYAPP"): + cli.add_command(pyapp_group) + +def app_start(): + cli(obj={}) \ No newline at end of file From 547a47b9ece51e29bfee93c94da61f20f9bf5d81 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:04:34 +0200 Subject: [PATCH 02/10] modify action to create and publish binaries --- .github/workflows/release.yml | 204 +++++++++++++++++++++++++++++ .github/workflows/release_pypi.yml | 37 ------ 2 files changed, 204 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/release_pypi.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..bec0fd9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,204 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Release Package + +on: +# push: +# tags: +# - v* +# branches: +# - master +# pull_request: +# branches: +# - master + release: + types: [published] + +defaults: + run: + shell: bash + +env: + PYTHON_VERSION: "3.11" +permissions: + contents: read +jobs: + build-sdist-and-wheel: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python ${{ env.PYTHON_VERSION }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install Hatch + run: | + python -m pip install --upgrade pip + pip install hatch + + - name: Build package + run: python -m hatch build + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: sdist-and-wheel + path: dist/* + if-no-files-found: error + + + build-binaries: + name: Build binaries for ${{ matrix.job.target }} (${{ matrix.job.os }}) + runs-on: ${{ matrix.job.os }} + strategy: + fail-fast: false + matrix: + job: + # Linux + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + cross: true + release_suffix: x86_64-linux + # - target: x86_64-unknown-linux-musl + # os: ubuntu-latest + # cross: true + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + cross: true + release_suffix: aarch64-linux + # - target: i686-unknown-linux-gnu + # os: ubuntu-latest + # cross: true + # release_suffix: i686-linux + # Windows + - target: x86_64-pc-windows-msvc + os: windows-2022 + release_suffix: x86_64-windows + # - target: i686-pc-windows-msvc + # os: windows-2022 + # release_suffix: i686-windows + # macOS + - target: aarch64-apple-darwin + os: macos-14 + release_suffix: aarch64-osx + - target: x86_64-apple-darwin + os: macos-12 + release_suffix: x86_64-osx + + env: + PYAPP_PASS_LOCATION: "1" + PYAPP_UV_ENABLED: "1" + HATCH_BUILD_LOCATION: dist + CARGO: cargo + CARGO_BUILD_TARGET: ${{ matrix.job.target }} + PYAPP_REPO: pyapp # Use local copy of pyapp (needed for cross-compiling) + PYAPP_VERSION: v0.23.0 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Clone PyApp + run: git clone --depth 1 --branch $PYAPP_VERSION https://github.com/ofek/pyapp $PYAPP_REPO + + - name: Set up Python ${{ env.PYTHON_VERSION }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install Hatch + run: | + python -m pip install --upgrade pip + pip install hatch + + - name: Install Rust toolchain + if: ${{ !matrix.job.cross }} + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.job.target }} + + - name: Set up cross compiling tools + if: matrix.job.cross + uses: taiki-e/setup-cross-toolchain-action@v1 + with: + target: ${{ matrix.job.target}} + + - name: Show toolchain information + run: |- + rustup toolchain list + rustup default + rustup -V + rustc -V + cargo -V + hatch --version + + - name: Get artifact + uses: actions/download-artifact@v4 + with: + name: sdist-and-wheel + path: ${{ github.workspace }}/dist + merge-multiple: true + + - name: Build Binary + working-directory: ${{ github.workspace }} + run: |- + current_version=$(hatch version) + PYAPP_PROJECT_PATH="${{ github.workspace }}/dist/isponsorblocktv-${current_version}-py3-none-any.whl" hatch -v build -t binary + + - name: Rename binary + working-directory: ${{ github.workspace }} + run: |- + mv dist/binary/dma* dist/binary/dma-${{ matrix.job.release_suffix }} + + - name: Upload built binary package + uses: actions/upload-artifact@v4 + with: + name: binaries-${{ matrix.job.release_suffix }} + path: dist/binary/* + if-no-files-found: error + + + publish-to-pypi: + needs: build-sdist-and-wheel + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + # only run step if the event is a published release + if: github.event_name == 'release' && github.event.action == 'published' + runs-on: ubuntu-latest + steps: + - name: Get artifact + uses: actions/download-artifact@v4 + with: + name: sdist-and-wheel + path: dist + merge-multiple: true + + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + + + publish-to-release: + needs: + - build-sdist-and-wheel + - build-binaries + if: github.event_name == 'release' && github.event.action == 'published' + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + name: Get artifact + with: + path: dist + merge-multiple: true + - name: Add assets to release + uses: softprops/action-gh-release@v2 + with: + files: dist/* \ No newline at end of file diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml deleted file mode 100644 index 180d5b9..0000000 --- a/.github/workflows/release_pypi.yml +++ /dev/null @@ -1,37 +0,0 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Upload Python Package - -on: - release: - types: [published] - -permissions: - contents: read - id-token: write # IMPORTANT: this permission is mandatory for trusted publishing -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build wheel - - name: Build package - run: python -m build - - name: Publish package - uses: pypa/gh-action-pypi-publish@release/v1 From 464baa7c5977ce23537d5f91402037607658e864 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:07:47 +0200 Subject: [PATCH 03/10] trigger on test branch --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bec0fd9..bbce891 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,6 +17,9 @@ on: # pull_request: # branches: # - master + push: + branches: + - build-binaries # Testing branch release: types: [published] From f9c7b58ece82490ddaa639260eac04bcc17ad7a6 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:12:49 +0200 Subject: [PATCH 04/10] add needs --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bbce891..fecf4f4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,6 +61,8 @@ jobs: build-binaries: name: Build binaries for ${{ matrix.job.target }} (${{ matrix.job.os }}) + needs: + - build-sdist-and-wheel runs-on: ${{ matrix.job.os }} strategy: fail-fast: false From fd400d077ade63b72c6d6bfed2b34c157b53b7b1 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:19:39 +0200 Subject: [PATCH 05/10] update upload-artifact to v4 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fecf4f4..1105477 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -52,7 +52,7 @@ jobs: run: python -m hatch build - name: Upload artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: sdist-and-wheel path: dist/* From 9ad335793a71f15c6fdc7ec04478e5066c9450d0 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:35:02 +0200 Subject: [PATCH 06/10] rename prefix --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1105477..8c5a04f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -162,7 +162,7 @@ jobs: - name: Rename binary working-directory: ${{ github.workspace }} run: |- - mv dist/binary/dma* dist/binary/dma-${{ matrix.job.release_suffix }} + mv dist/binary/iSponsorBlockTV* dist/binary/iSponsorBlockTV-${{ matrix.job.release_suffix }} - name: Upload built binary package uses: actions/upload-artifact@v4 From cb738965a78b00d0140fb937a73843fd03511d0b Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:07:35 +0200 Subject: [PATCH 07/10] run on all events (and only publish on release) --- .github/workflows/release.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c5a04f..86b249f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,17 +9,14 @@ name: Release Package on: -# push: -# tags: -# - v* -# branches: -# - master -# pull_request: -# branches: -# - master push: branches: - - build-binaries # Testing branch + - '*' + tags: + - 'v*' + pull_request: + branches: + - '*' release: types: [published] From fb3c40d477b54fdc4f64a9740d12ae004d59b00e Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:58:15 +0200 Subject: [PATCH 08/10] also build armv7 --- .github/workflows/release.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 86b249f..753391d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,24 +70,22 @@ jobs: os: ubuntu-latest cross: true release_suffix: x86_64-linux - # - target: x86_64-unknown-linux-musl - # os: ubuntu-latest - # cross: true - target: aarch64-unknown-linux-gnu os: ubuntu-latest cross: true release_suffix: aarch64-linux - # - target: i686-unknown-linux-gnu - # os: ubuntu-latest - # cross: true - # release_suffix: i686-linux + - target: armv7-unknown-linux-gnueabihf + os: ubuntu-latest + cross: true + release_suffix: armv7-linux # Windows - target: x86_64-pc-windows-msvc os: windows-2022 release_suffix: x86_64-windows - # - target: i686-pc-windows-msvc - # os: windows-2022 - # release_suffix: i686-windows + - target: aarch64-pc-windows-msvc + os: windows-2022 + cross: true + release_suffix: aarch64-windows # macOS - target: aarch64-apple-darwin os: macos-14 From 167383dea891e1604d85f0cc5c4234961e8cb4b2 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 18 Aug 2024 16:11:54 +0200 Subject: [PATCH 09/10] revert --- .github/workflows/release.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 753391d..d04d88a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -74,18 +74,10 @@ jobs: os: ubuntu-latest cross: true release_suffix: aarch64-linux - - target: armv7-unknown-linux-gnueabihf - os: ubuntu-latest - cross: true - release_suffix: armv7-linux # Windows - target: x86_64-pc-windows-msvc os: windows-2022 release_suffix: x86_64-windows - - target: aarch64-pc-windows-msvc - os: windows-2022 - cross: true - release_suffix: aarch64-windows # macOS - target: aarch64-apple-darwin os: macos-14 From bde4ecb72f769c28e7bf6686531aa9dd8e4a11c0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:23:15 +0000 Subject: [PATCH 10/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/release.yml | 10 ++--- requirements.txt | 2 +- src/iSponsorBlockTV/helpers.py | 70 +++++++++++++++++++++++++--------- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d04d88a..d4d628a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -145,7 +145,7 @@ jobs: run: |- current_version=$(hatch version) PYAPP_PROJECT_PATH="${{ github.workspace }}/dist/isponsorblocktv-${current_version}-py3-none-any.whl" hatch -v build -t binary - + - name: Rename binary working-directory: ${{ github.workspace }} run: |- @@ -164,7 +164,7 @@ jobs: permissions: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing # only run step if the event is a published release - if: github.event_name == 'release' && github.event.action == 'published' + if: github.event_name == 'release' && github.event.action == 'published' runs-on: ubuntu-latest steps: - name: Get artifact @@ -179,10 +179,10 @@ jobs: publish-to-release: - needs: + needs: - build-sdist-and-wheel - build-binaries - if: github.event_name == 'release' && github.event.action == 'published' + if: github.event_name == 'release' && github.event.action == 'published' runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v4 @@ -193,4 +193,4 @@ jobs: - name: Add assets to release uses: softprops/action-gh-release@v2 with: - files: dist/* \ No newline at end of file + files: dist/* diff --git a/requirements.txt b/requirements.txt index a30b6c1..0b6deb3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,4 @@ ssdp==1.3.0 textual==0.58.0 textual-slider==0.1.1 xmltodict==0.13.0 -rich_click==1.8.3 \ No newline at end of file +rich_click==1.8.3 diff --git a/src/iSponsorBlockTV/helpers.py b/src/iSponsorBlockTV/helpers.py index aa5490a..6b4880e 100644 --- a/src/iSponsorBlockTV/helpers.py +++ b/src/iSponsorBlockTV/helpers.py @@ -1,10 +1,10 @@ -import rich_click as click import json import logging import os import sys import time +import rich_click as click from appdirs import user_data_dir from . import config_setup, main, setup_wizard @@ -127,17 +127,30 @@ class Config: @click.group(invoke_without_command=True) -@click.option('--data', '-d', default=lambda: os.getenv("iSPBTV_data_dir") or user_data_dir("iSponsorBlockTV", "dmunozv04"), help='data directory') -@click.option('--debug', is_flag=True, help='debug mode') -#legacy commands as arguments -@click.option('--setup', is_flag=True, help='Setup the program graphically', hidden=True) -@click.option('--setup-cli', is_flag=True, help='Setup the program in the command line', hidden=True) +@click.option( + "--data", + "-d", + default=lambda: os.getenv("iSPBTV_data_dir") + or user_data_dir("iSponsorBlockTV", "dmunozv04"), + help="data directory", +) +@click.option("--debug", is_flag=True, help="debug mode") +# legacy commands as arguments +@click.option( + "--setup", is_flag=True, help="Setup the program graphically", hidden=True +) +@click.option( + "--setup-cli", + is_flag=True, + help="Setup the program in the command line", + hidden=True, +) @click.pass_context def cli(ctx, data, debug, setup, setup_cli): """iSponsorblockTV""" ctx.ensure_object(dict) - ctx.obj['data_dir'] = data - ctx.obj['debug'] = debug + ctx.obj["data_dir"] = data + ctx.obj["debug"] = debug if debug: logging.basicConfig(level=logging.DEBUG) if ctx.invoked_subcommand is None: @@ -148,37 +161,58 @@ def cli(ctx, data, debug, setup, setup_cli): else: ctx.invoke(start) + @cli.command() @click.pass_context def setup(ctx): """Setup the program graphically""" - config = Config(ctx.obj['data_dir']) + config = Config(ctx.obj["data_dir"]) setup_wizard.main(config) sys.exit() + + setup_command = setup + + @cli.command() @click.pass_context def setup_cli(ctx): """Setup the program in the command line""" - config = Config(ctx.obj['data_dir']) - config_setup.main(config, ctx.obj['debug']) + config = Config(ctx.obj["data_dir"]) + config_setup.main(config, ctx.obj["debug"]) + + setup_cli_command = setup_cli + + @cli.command() @click.pass_context def start(ctx): """Start the main program""" - config = Config(ctx.obj['data_dir']) + config = Config(ctx.obj["data_dir"]) config.validate() - main.main(config, ctx.obj['debug']) + main.main(config, ctx.obj["debug"]) + # Create fake "self" group to show pyapp options in help menu -#Subcommands remove, restore, update +# Subcommands remove, restore, update pyapp_group = click.RichGroup("self", help="pyapp options (update, remove, restore)") -pyapp_group.add_command(click.RichCommand("update", help="Update the package to the latest version")) -pyapp_group.add_command(click.Command("remove", help="Remove the package, wiping the installation but not the data")) -pyapp_group.add_command(click.RichCommand("restore", help="Restore the package to its original state by reinstalling it")) +pyapp_group.add_command( + click.RichCommand("update", help="Update the package to the latest version") +) +pyapp_group.add_command( + click.Command( + "remove", help="Remove the package, wiping the installation but not the data" + ) +) +pyapp_group.add_command( + click.RichCommand( + "restore", help="Restore the package to its original state by reinstalling it" + ) +) if os.getenv("PYAPP"): cli.add_command(pyapp_group) + def app_start(): - cli(obj={}) \ No newline at end of file + cli(obj={})