diff --git a/.github/workflows/main.yml b/.github/workflows/build_docker_images.yml similarity index 100% rename from .github/workflows/main.yml rename to .github/workflows/build_docker_images.yml diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..467ee79 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,37 @@ +# 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@v3 + - name: Set up Python + uses: actions/setup-python@v3 + 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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 32abc18..8b87a07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,17 +2,18 @@ FROM python:3.11-alpine -ENV PIP_NO_CACHE_DIR=off iSPBTV_docker=True TERM=xterm-256color COLORTERM=truecolor +ENV PIP_NO_CACHE_DIR=off iSPBTV_docker=True iSPBTV_data_dir=data TERM=xterm-256color COLORTERM=truecolor COPY requirements.txt . RUN pip install --upgrade pip wheel && \ pip install -r requirements.txt -COPY requirements.txt . WORKDIR /app -COPY . . +RUN python -m compileall + +COPY src . ENTRYPOINT ["python3", "-u", "main.py"] \ No newline at end of file diff --git a/main-macos.py b/main-macos.py deleted file mode 100644 index ac7e117..0000000 --- a/main-macos.py +++ /dev/null @@ -1,7 +0,0 @@ -from iSponsorBlockTV import helpers -import sys -import os - -if getattr(sys, "frozen", False): - os.environ["SSL_CERT_FILE"] = os.path.join(sys._MEIPASS, "lib", "cert.pem") -helpers.app_start() diff --git a/main-macos.spec b/main-macos.spec deleted file mode 100644 index f0ee8d9..0000000 --- a/main-macos.spec +++ /dev/null @@ -1,47 +0,0 @@ -# -*- mode: python ; coding: utf-8 -*- - -from PyInstaller.utils.hooks import exec_statement -cert_datas = exec_statement(""" - import ssl - print(ssl.get_default_verify_paths().cafile)""").strip().split() -cert_datas = [(f, 'lib') for f in cert_datas] - -block_cipher = None - -options = [ ('u', None, 'OPTION') ] - -a = Analysis(['main-macos.py'], - pathex=[], - binaries=[], - datas=cert_datas, - hiddenimports=['certifi'], - hookspath=[], - hooksconfig={}, - runtime_hooks=[], - excludes=[], - win_no_prefer_redirects=False, - win_private_assemblies=False, - cipher=block_cipher, - noarchive=False) -pyz = PYZ(a.pure, a.zipped_data, - cipher=block_cipher) - -exe = EXE(pyz, - a.scripts, - a.binaries, - a.zipfiles, - a.datas, - [], - options, - name='iSponsorBlockTV-macos', - debug=False, - bootloader_ignore_signals=False, - strip=False, - upx=True, - upx_exclude=[], - runtime_tmpdir=None, - console=True, - disable_windowed_traceback=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d40904d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,30 @@ +[project] +name = "iSponsorBlockTV" +version = "2.0.3" +authors = [ + {"name" = "dmunozv04"} +] +description = "SponsorBlock client for all YouTube TV clients" +readme = "README.md" +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: OS Independent", + "Topic :: Home Automation" +] +dynamic = ["dependencies"] + +[tool.hatch.metadata.hooks.requirements_txt] +files = ["requirements.txt"] + +[project.urls] +"Homepage" = "https://github.com/dmunozv04/iSponsorBlockTV" +"Bug Tracker" = "https://github.com/dmunozv04/iSponsorBlockTV/issues" + +[project.scripts] +"iSponsorBlockTV" = "iSponsorBlockTV.__main__:main" + +[build-system] +requires = ["hatchling", "hatch-requirements-txt"] +build-backend = "hatchling.build" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index fad23ea..39ba4fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ aiohttp==3.9.0 +appdirs==1.4.4 argparse==1.4.0 async-cache==1.1.1 pyytlounge==1.6.3 @@ -6,5 +7,4 @@ rich==13.6.0 ssdp==1.3.0 textual==0.40.0 textual-slider==0.1.1 -xmltodict==0.13.0 - +xmltodict==0.13.0 \ No newline at end of file diff --git a/iSponsorBlockTV/__init__.py b/src/iSponsorBlockTV/__init__.py similarity index 100% rename from iSponsorBlockTV/__init__.py rename to src/iSponsorBlockTV/__init__.py diff --git a/src/iSponsorBlockTV/__main__.py b/src/iSponsorBlockTV/__main__.py new file mode 100644 index 0000000..7a3a6f4 --- /dev/null +++ b/src/iSponsorBlockTV/__main__.py @@ -0,0 +1,8 @@ +from . import helpers + +def main(): + helpers.app_start() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/iSponsorBlockTV/api_helpers.py b/src/iSponsorBlockTV/api_helpers.py similarity index 100% rename from iSponsorBlockTV/api_helpers.py rename to src/iSponsorBlockTV/api_helpers.py diff --git a/iSponsorBlockTV/conditional_ttl_cache.py b/src/iSponsorBlockTV/conditional_ttl_cache.py similarity index 100% rename from iSponsorBlockTV/conditional_ttl_cache.py rename to src/iSponsorBlockTV/conditional_ttl_cache.py diff --git a/iSponsorBlockTV/config_setup.py b/src/iSponsorBlockTV/config_setup.py similarity index 100% rename from iSponsorBlockTV/config_setup.py rename to src/iSponsorBlockTV/config_setup.py diff --git a/iSponsorBlockTV/constants.py b/src/iSponsorBlockTV/constants.py similarity index 100% rename from iSponsorBlockTV/constants.py rename to src/iSponsorBlockTV/constants.py diff --git a/iSponsorBlockTV/dial_client.py b/src/iSponsorBlockTV/dial_client.py similarity index 100% rename from iSponsorBlockTV/dial_client.py rename to src/iSponsorBlockTV/dial_client.py diff --git a/iSponsorBlockTV/helpers.py b/src/iSponsorBlockTV/helpers.py similarity index 93% rename from iSponsorBlockTV/helpers.py rename to src/iSponsorBlockTV/helpers.py index 481e45d..713acaa 100644 --- a/iSponsorBlockTV/helpers.py +++ b/src/iSponsorBlockTV/helpers.py @@ -5,6 +5,8 @@ import sys import time +from appdirs import user_data_dir + from . import config_setup, main, setup_wizard @@ -102,8 +104,10 @@ def __eq__(self, other): 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="data", help="data directory") + 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") diff --git a/iSponsorBlockTV/macos_install.py b/src/iSponsorBlockTV/macos_install.py similarity index 100% rename from iSponsorBlockTV/macos_install.py rename to src/iSponsorBlockTV/macos_install.py diff --git a/iSponsorBlockTV/main.py b/src/iSponsorBlockTV/main.py similarity index 99% rename from iSponsorBlockTV/main.py rename to src/iSponsorBlockTV/main.py index bf848c5..bda1bd3 100644 --- a/iSponsorBlockTV/main.py +++ b/src/iSponsorBlockTV/main.py @@ -146,4 +146,4 @@ def main(config, debug): print("Keyboard interrupt detected, cancelling tasks and exiting...") loop.run_until_complete(finish(devices)) finally: - loop.run_until_complete(web_session.close()) + loop.run_until_complete(web_session.close()) \ No newline at end of file diff --git a/iSponsorBlockTV/setup-wizard-style.tcss b/src/iSponsorBlockTV/setup-wizard-style.tcss similarity index 100% rename from iSponsorBlockTV/setup-wizard-style.tcss rename to src/iSponsorBlockTV/setup-wizard-style.tcss diff --git a/iSponsorBlockTV/setup_wizard.py b/src/iSponsorBlockTV/setup_wizard.py similarity index 100% rename from iSponsorBlockTV/setup_wizard.py rename to src/iSponsorBlockTV/setup_wizard.py diff --git a/iSponsorBlockTV/ytlounge.py b/src/iSponsorBlockTV/ytlounge.py similarity index 100% rename from iSponsorBlockTV/ytlounge.py rename to src/iSponsorBlockTV/ytlounge.py diff --git a/main.py b/src/main.py similarity index 100% rename from main.py rename to src/main.py diff --git a/main_tui.py b/src/main_tui.py similarity index 100% rename from main_tui.py rename to src/main_tui.py