From 640b2d9811e72082363dc520bda1a3bebb5363fb Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Thu, 23 Feb 2023 14:32:14 -0800 Subject: [PATCH] ovos-core 0.0.6 Compatibility, Automation (#1) * Resolve type warnings in skill Update Workshop dependency spec * Fix requirements parsing in setup.py Update URL and plugin to new owner * Update URL in setup.py * Update setup.py Add version.py Add GitHub automation and scripts * Add missing test files referenced in automation * Update package spec in license tests * Update ovos-core version used in install_tests.yml * Add OCP dependency * Update requirements.txt * Update MANIFEST.in --------- Co-authored-by: JarbasAI <33701864+JarbasAl@users.noreply.github.com> --- .github/workflows/build_tests.yml | 55 ++++++++++++++++++ .github/workflows/dev2master.yml | 20 +++++++ .github/workflows/install_tests.yml | 70 +++++++++++++++++++++++ .github/workflows/license_tests.yml | 44 +++++++++++++++ .github/workflows/publish_alpha.yml | 74 +++++++++++++++++++++++++ .github/workflows/publish_build.yml | 86 +++++++++++++++++++++++++++++ .github/workflows/publish_major.yml | 86 +++++++++++++++++++++++++++++ .github/workflows/publish_minor.yml | 86 +++++++++++++++++++++++++++++ MANIFEST.in | 6 +- __init__.py | 6 +- requirements.txt | 3 +- scripts/bump_alpha.py | 18 ++++++ scripts/bump_build.py | 21 +++++++ scripts/bump_major.py | 27 +++++++++ scripts/bump_minor.py | 24 ++++++++ scripts/remove_alpha.py | 13 +++++ setup.py | 86 ++++++++++++++++++++++++++--- test/osm_tests.py | 30 ++++++++++ test/plugin_tests.py | 13 +++++ version.py | 6 ++ 20 files changed, 760 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/build_tests.yml create mode 100644 .github/workflows/dev2master.yml create mode 100644 .github/workflows/install_tests.yml create mode 100644 .github/workflows/license_tests.yml create mode 100644 .github/workflows/publish_alpha.yml create mode 100644 .github/workflows/publish_build.yml create mode 100644 .github/workflows/publish_major.yml create mode 100644 .github/workflows/publish_minor.yml create mode 100644 scripts/bump_alpha.py create mode 100644 scripts/bump_build.py create mode 100644 scripts/bump_major.py create mode 100644 scripts/bump_minor.py create mode 100644 scripts/remove_alpha.py create mode 100644 test/osm_tests.py create mode 100644 test/plugin_tests.py create mode 100644 version.py diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml new file mode 100644 index 0000000..c35c736 --- /dev/null +++ b/.github/workflows/build_tests.yml @@ -0,0 +1,55 @@ +name: Run Build Tests +on: + push: + branches: + - master + pull_request: + branches: + - dev + paths-ignore: + - 'version.py' + - 'test/**' + - 'examples/**' + - '.github/**' + - '.gitignore' + - 'LICENSE' + - 'CHANGELOG.md' + - 'MANIFEST.in' + - 'readme.md' + - 'scripts/**' + workflow_dispatch: + +jobs: + build_tests: + strategy: + max-parallel: 2 + matrix: + python-version: [ 3.7, 3.8, 3.9, "3.10" ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install Build Tools + run: | + python -m pip install build wheel + - name: Install System Dependencies + run: | + sudo apt-get update + sudo apt install python3-dev swig libssl-dev + - name: Build Source Packages + run: | + python setup.py sdist + - name: Build Distribution Packages + run: | + python setup.py bdist_wheel + - name: Install skill + run: | + pip install . + - uses: pypa/gh-action-pip-audit@v1.0.0 + with: + # Ignore setuptools vulnerability we can't do much about + ignore-vulns: | + GHSA-r9hx-vwmv-q579 \ No newline at end of file diff --git a/.github/workflows/dev2master.yml b/.github/workflows/dev2master.yml new file mode 100644 index 0000000..cc76fee --- /dev/null +++ b/.github/workflows/dev2master.yml @@ -0,0 +1,20 @@ +# This workflow will generate a distribution and upload it to PyPI + +name: Push dev -> master +on: + workflow_dispatch: + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + ref: dev + - name: Push dev -> master + uses: ad-m/github-push-action@master + + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: master \ No newline at end of file diff --git a/.github/workflows/install_tests.yml b/.github/workflows/install_tests.yml new file mode 100644 index 0000000..a921221 --- /dev/null +++ b/.github/workflows/install_tests.yml @@ -0,0 +1,70 @@ +name: Run Install Tests +on: + push: + branches: + - master + pull_request: + branches: + - dev + paths-ignore: + - '.github/**' + - '.gitignore' + - 'LICENSE' + - 'CHANGELOG.md' + - 'MANIFEST.in' + - 'readme.md' + - 'scripts/**' + workflow_dispatch: + +jobs: + plugin_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install test dependencies + run: | + pip install pytest pytest-timeout pytest-cov + - name: Install ovos dependencies + run: | + pip install ovos-plugin-manager ovos-core[skills]~=0.0.6 + - name: Install package + run: | + pip install . + - name: Run Plugin tests + run: | + pytest test/plugin_tests.py + osm_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install ovos dependencies + run: | + pip install ovos-skills-manager~=0.0.10 + - name: Install test dependencies + run: | + pip install pytest pytest-timeout pytest-cov + - name: Install skill with osm + run: | + pytest test/osm_tests.py + msm_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install msm + run: | + pip install msm~=0.9.0 + - name: Install skill with msm + run: | + msm install https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }} diff --git a/.github/workflows/license_tests.yml b/.github/workflows/license_tests.yml new file mode 100644 index 0000000..a5c0ffb --- /dev/null +++ b/.github/workflows/license_tests.yml @@ -0,0 +1,44 @@ +name: Run License Tests +on: + push: + branches: + - master + pull_request: + branches: + - dev + workflow_dispatch: + +jobs: + license_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install Build Tools + run: | + python -m pip install build wheel + - name: Install System Dependencies + run: | + sudo apt-get update + sudo apt install python3-dev swig libssl-dev + - name: Install core repo + run: | + pip install . + - name: Get explicit and transitive dependencies + run: | + pip freeze > requirements-all.txt + - name: Check python + id: license_check_report + uses: pilosus/action-pip-license-checker@v0.5.0 + with: + requirements: 'requirements-all.txt' + fail: 'Copyleft,Other,Error' + fails-only: true + exclude: '^(tqdm|ovos-skill-somafm).*' + exclude-license: '^(Mozilla).*$' + - name: Print report + if: ${{ always() }} + run: echo "${{ steps.license_check_report.outputs.report }}" \ No newline at end of file diff --git a/.github/workflows/publish_alpha.yml b/.github/workflows/publish_alpha.yml new file mode 100644 index 0000000..1b2ec56 --- /dev/null +++ b/.github/workflows/publish_alpha.yml @@ -0,0 +1,74 @@ +# This workflow will generate a distribution and upload it to PyPI + +name: Publish Alpha Build ...aX +on: + push: + branches: + - dev + paths-ignore: + - 'version.py' + - 'test/**' + - 'examples/**' + - '.github/**' + - '.gitignore' + - 'LICENSE' + - 'CHANGELOG.md' + - 'MANIFEST.in' + - 'readme.md' + - 'scripts/**' + workflow_dispatch: + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: dev + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install Build Tools + run: | + python -m pip install build wheel + - name: Increment Version + run: | + VER=$(python setup.py --version) + python scripts/bump_alpha.py + - name: "Generate release changelog" + uses: heinrichreimer/github-changelog-generator-action@v2.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + maxIssues: 50 + id: changelog + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Increment Version + branch: dev + - name: version + run: echo "::set-output name=version::$(python setup.py --version)" + id: version + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: V${{ steps.version.outputs.version }} + release_name: Release ${{ steps.version.outputs.version }} + body: | + Changes in this Release + ${{ steps.changelog.outputs.changelog }} + draft: false + prerelease: true + commitish: dev + - name: Build Distribution Packages + run: | + python setup.py bdist_wheel + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{secrets.PYPI_TOKEN}} diff --git a/.github/workflows/publish_build.yml b/.github/workflows/publish_build.yml new file mode 100644 index 0000000..4baf4fc --- /dev/null +++ b/.github/workflows/publish_build.yml @@ -0,0 +1,86 @@ +# This workflow will generate a distribution and upload it to PyPI + +name: Publish Build Release ..X +on: + workflow_dispatch: + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: dev + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install Build Tools + run: | + python -m pip install build wheel + - name: Remove alpha (declare stable) + run: | + VER=$(python setup.py --version) + python scripts/remove_alpha.py + - name: "Generate release changelog" + uses: heinrichreimer/github-changelog-generator-action@v2.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + id: changelog + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Declare alpha stable + branch: dev + - name: Push dev -> master + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: master + force: true + - name: version + run: echo "::set-output name=version::$(python setup.py --version)" + id: version + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: V${{ steps.version.outputs.version }} + release_name: Release ${{ steps.version.outputs.version }} + body: | + Changes in this Release + ${{ steps.changelog.outputs.changelog }} + draft: false + prerelease: false + commitish: dev + - name: Build Distribution Packages + run: | + python setup.py bdist_wheel + - name: Prepare next Build version + run: echo "::set-output name=version::$(python setup.py --version)" + id: alpha + - name: Increment Version ${{ steps.alpha.outputs.version }}Alpha0 + run: | + VER=$(python setup.py --version) + python scripts/bump_build.py + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Prepare Next Version + branch: dev + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{secrets.PYPI_TOKEN}} + - name: Send message to Matrix bots channel + id: matrix-chat-message + uses: fadenb/matrix-chat-message@v0.0.6 + with: + homeserver: 'matrix.org' + token: ${{ secrets.MATRIX_TOKEN }} + channel: '!WjxEKjjINpyBRPFgxl:krbel.duckdns.org' + message: | + New skill-ovos-stop release! ${{ steps.version.outputs.version }} diff --git a/.github/workflows/publish_major.yml b/.github/workflows/publish_major.yml new file mode 100644 index 0000000..00407ff --- /dev/null +++ b/.github/workflows/publish_major.yml @@ -0,0 +1,86 @@ +# This workflow will generate a distribution and upload it to PyPI + +name: Publish Major Release X.0.0 +on: + workflow_dispatch: + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: dev + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install Build Tools + run: | + python -m pip install build wheel + - name: Remove alpha (declare stable) + run: | + VER=$(python setup.py --version) + python scripts/remove_alpha.py + - name: "Generate release changelog" + uses: heinrichreimer/github-changelog-generator-action@v2.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + id: changelog + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Declare alpha stable + branch: dev + - name: Push dev -> master + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: master + force: true + - name: version + run: echo "::set-output name=version::$(python setup.py --version)" + id: version + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: V${{ steps.version.outputs.version }} + release_name: Release ${{ steps.version.outputs.version }} + body: | + Changes in this Release + ${{ steps.changelog.outputs.changelog }} + draft: false + prerelease: false + commitish: master + - name: Build Distribution Packages + run: | + python setup.py bdist_wheel + - name: Prepare next Major version + run: echo "::set-output name=version::$(python setup.py --version)" + id: alpha + - name: Increment Version ${{ steps.alpha.outputs.version }}Alpha0 + run: | + VER=$(python setup.py --version) + python scripts/bump_major.py + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Prepare Next Version + branch: dev + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{secrets.PYPI_TOKEN}} + - name: Send message to Matrix bots channel + id: matrix-chat-message + uses: fadenb/matrix-chat-message@v0.0.6 + with: + homeserver: 'matrix.org' + token: ${{ secrets.MATRIX_TOKEN }} + channel: '!WjxEKjjINpyBRPFgxl:krbel.duckdns.org' + message: | + New skill-ovos-stop release! ${{ steps.version.outputs.version }} diff --git a/.github/workflows/publish_minor.yml b/.github/workflows/publish_minor.yml new file mode 100644 index 0000000..fae0299 --- /dev/null +++ b/.github/workflows/publish_minor.yml @@ -0,0 +1,86 @@ +# This workflow will generate a distribution and upload it to PyPI + +name: Publish Minor Release .X.0 +on: + workflow_dispatch: + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: dev + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install Build Tools + run: | + python -m pip install build wheel + - name: Remove alpha (declare stable) + run: | + VER=$(python setup.py --version) + python scripts/remove_alpha.py + - name: "Generate release changelog" + uses: heinrichreimer/github-changelog-generator-action@v2.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + id: changelog + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Declare alpha stable + branch: dev + - name: Push dev -> master + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: master + force: true + - name: version + run: echo "::set-output name=version::$(python setup.py --version)" + id: version + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: V${{ steps.version.outputs.version }} + release_name: Release ${{ steps.version.outputs.version }} + body: | + Changes in this Release + ${{ steps.changelog.outputs.changelog }} + draft: false + prerelease: false + commitish: master + - name: Build Distribution Packages + run: | + python setup.py bdist_wheel + - name: Prepare next Minor version + run: echo "::set-output name=version::$(python setup.py --version)" + id: alpha + - name: Increment Version ${{ steps.alpha.outputs.version }}Alpha0 + run: | + VER=$(python setup.py --version) + python scripts/bump_minor.py + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Prepare Next Version + branch: dev + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{secrets.PYPI_TOKEN}} + - name: Send message to Matrix bots channel + id: matrix-chat-message + uses: fadenb/matrix-chat-message@v0.0.6 + with: + homeserver: 'matrix.org' + token: ${{ secrets.MATRIX_TOKEN }} + channel: '!WjxEKjjINpyBRPFgxl:krbel.duckdns.org' + message: | + New skill-ovos-stop release! ${{ steps.version.outputs.version }} diff --git a/MANIFEST.in b/MANIFEST.in index 9c3f566..870b808 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,4 +2,8 @@ recursive-include dialog * recursive-include vocab * recursive-include locale * recursive-include res * -recursive-include ui * \ No newline at end of file +recursive-include ui * +include README.md +include requirements.txt +include CHANGELOG.md +include LICENSE diff --git a/__init__.py b/__init__.py index dbe5843..75b89cf 100755 --- a/__init__.py +++ b/__init__.py @@ -77,9 +77,9 @@ def search_somafm(self, phrase, media_type): phrase = self.remove_voc(phrase, "somafm") for ch in radiosoma.get_stations(): - score = base_score + \ - fuzzy_match(ch.title.lower(), phrase.lower()) * 100 - if score <= MatchConfidence.AVERAGE_LOW: + score = round(base_score + fuzzy_match(ch.title.lower(), + phrase.lower()) * 100) + if score <= MatchConfidence.AVERAGE_LOW.value: continue yield { "match_confidence": min(100, score), diff --git a/requirements.txt b/requirements.txt index 1bcfd7c..6d92168 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +ovos-plugin-common-play~=0.0, >=0.0.3 ovos-utils~=0.0, >=0.0.28a4 ovos_workshop~=0.0, >=0.0.11a4 -radiosoma \ No newline at end of file +radiosoma~=0.0, >=0.0.1 diff --git a/scripts/bump_alpha.py b/scripts/bump_alpha.py new file mode 100644 index 0000000..e465543 --- /dev/null +++ b/scripts/bump_alpha.py @@ -0,0 +1,18 @@ +import fileinput +from os.path import join, dirname + + +version_file = join(dirname(dirname(__file__)), "version.py") +version_var_name = "VERSION_ALPHA" + +with open(version_file, "r", encoding="utf-8") as v: + for line in v.readlines(): + if line.startswith(version_var_name): + version = int(line.split("=")[-1]) + new_version = int(version) + 1 + +for line in fileinput.input(version_file, inplace=True): + if line.startswith(version_var_name): + print(f"{version_var_name} = {new_version}") + else: + print(line.rstrip('\n')) diff --git a/scripts/bump_build.py b/scripts/bump_build.py new file mode 100644 index 0000000..61099f8 --- /dev/null +++ b/scripts/bump_build.py @@ -0,0 +1,21 @@ +import fileinput +from os.path import join, dirname + + +version_file = join(dirname(dirname(__file__)), "version.py") +version_var_name = "VERSION_BUILD" +alpha_var_name = "VERSION_ALPHA" + +with open(version_file, "r", encoding="utf-8") as v: + for line in v.readlines(): + if line.startswith(version_var_name): + version = int(line.split("=")[-1]) + new_version = int(version) + 1 + +for line in fileinput.input(version_file, inplace=True): + if line.startswith(version_var_name): + print(f"{version_var_name} = {new_version}") + elif line.startswith(alpha_var_name): + print(f"{alpha_var_name} = 0") + else: + print(line.rstrip('\n')) diff --git a/scripts/bump_major.py b/scripts/bump_major.py new file mode 100644 index 0000000..2610fbb --- /dev/null +++ b/scripts/bump_major.py @@ -0,0 +1,27 @@ +import fileinput +from os.path import join, dirname + + +version_file = join(dirname(dirname(__file__)), "version.py") +version_var_name = "VERSION_MAJOR" +minor_var_name = "VERSION_MINOR" +build_var_name = "VERSION_BUILD" +alpha_var_name = "VERSION_ALPHA" + +with open(version_file, "r", encoding="utf-8") as v: + for line in v.readlines(): + if line.startswith(version_var_name): + version = int(line.split("=")[-1]) + new_version = int(version) + 1 + +for line in fileinput.input(version_file, inplace=True): + if line.startswith(version_var_name): + print(f"{version_var_name} = {new_version}") + elif line.startswith(minor_var_name): + print(f"{minor_var_name} = 0") + elif line.startswith(build_var_name): + print(f"{build_var_name} = 0") + elif line.startswith(alpha_var_name): + print(f"{alpha_var_name} = 0") + else: + print(line.rstrip('\n')) diff --git a/scripts/bump_minor.py b/scripts/bump_minor.py new file mode 100644 index 0000000..86dfd9d --- /dev/null +++ b/scripts/bump_minor.py @@ -0,0 +1,24 @@ +import fileinput +from os.path import join, dirname + + +version_file = join(dirname(dirname(__file__)), "version.py") +version_var_name = "VERSION_MINOR" +build_var_name = "VERSION_BUILD" +alpha_var_name = "VERSION_ALPHA" + +with open(version_file, "r", encoding="utf-8") as v: + for line in v.readlines(): + if line.startswith(version_var_name): + version = int(line.split("=")[-1]) + new_version = int(version) + 1 + +for line in fileinput.input(version_file, inplace=True): + if line.startswith(version_var_name): + print(f"{version_var_name} = {new_version}") + elif line.startswith(build_var_name): + print(f"{build_var_name} = 0") + elif line.startswith(alpha_var_name): + print(f"{alpha_var_name} = 0") + else: + print(line.rstrip('\n')) diff --git a/scripts/remove_alpha.py b/scripts/remove_alpha.py new file mode 100644 index 0000000..fca7342 --- /dev/null +++ b/scripts/remove_alpha.py @@ -0,0 +1,13 @@ +import fileinput +from os.path import join, dirname + + +version_file = join(dirname(dirname(__file__)), "version.py") + +alpha_var_name = "VERSION_ALPHA" + +for line in fileinput.input(version_file, inplace=True): + if line.startswith(alpha_var_name): + print(f"{alpha_var_name} = 0") + else: + print(line.rstrip('\n')) diff --git a/setup.py b/setup.py index af67210..d903e6a 100755 --- a/setup.py +++ b/setup.py @@ -1,23 +1,91 @@ #!/usr/bin/env python3 +import os + from setuptools import setup +from os import path, walk + +URL = "https://github.com/OpenVoiceOS/skill-ovos-somafm" +SKILL_CLAZZ = "SomaFMSkill" # needs to match __init__.py class name +PYPI_NAME = "ovos-skill-somafm" # pip install PYPI_NAME + + +# below derived from github url to ensure standard skill_id +SKILL_AUTHOR, SKILL_NAME = URL.split(".com/")[-1].split("/") +SKILL_PKG = SKILL_NAME.lower().replace('-', '_') +PLUGIN_ENTRY_POINT = f'{SKILL_NAME.lower()}.{SKILL_AUTHOR.lower()}={SKILL_PKG}:{SKILL_CLAZZ}' + + +def get_requirements(requirements_filename: str): + requirements_file = path.join(path.abspath(path.dirname(__file__)), + requirements_filename) + with open(requirements_file, 'r', encoding='utf-8') as r: + requirements = r.readlines() + requirements = [r.strip() for r in requirements if r.strip() + and not r.strip().startswith("#")] + if 'MYCROFT_LOOSE_REQUIREMENTS' in os.environ: + print('USING LOOSE REQUIREMENTS!') + requirements = [r.replace('==', '>=').replace('~=', '>=') for r in requirements] + return requirements + + +def find_resource_files(): + resource_base_dirs = ("locale", "ui", "vocab", "dialog", "regex", "skill") + base_dir = path.dirname(__file__) + package_data = ["*.json"] + for res in resource_base_dirs: + if path.isdir(path.join(base_dir, res)): + for (directory, _, files) in walk(path.join(base_dir, res)): + if files: + package_data.append( + path.join(directory.replace(base_dir, "").lstrip('/'), + '*')) + return package_data + + +with open("README.md", "r") as f: + long_description = f.read() + + +def get_version(): + """ Find the version of this skill""" + version_file = os.path.join(os.path.dirname(__file__), 'version.py') + major, minor, build, alpha = (None, None, None, None) + with open(version_file) as f: + for line in f: + if 'VERSION_MAJOR' in line: + major = line.split('=')[1].strip() + elif 'VERSION_MINOR' in line: + minor = line.split('=')[1].strip() + elif 'VERSION_BUILD' in line: + build = line.split('=')[1].strip() + elif 'VERSION_ALPHA' in line: + alpha = line.split('=')[1].strip() + + if ((major and minor and build and alpha) or + '# END_VERSION_BLOCK' in line): + break + version = f"{major}.{minor}.{build}" + if int(alpha): + version += f"a{alpha}" + return version -# skill_id=package_name:SkillClass -PLUGIN_ENTRY_POINT = 'skill-somafm.jarbasai=skill_somafm:SomaFMSkill' setup( # this is the package name that goes on pip - name='ovos-skill-somafm', - version='0.0.1', + name=PYPI_NAME, + version=get_version(), description='ovos somafm skill plugin', - url='https://github.com/JarbasSkills/skill-somafm', + url=URL, author='JarbasAi', author_email='jarbasai@mailfence.com', license='Apache-2.0', - package_dir={"skill_somafm": ""}, - package_data={'skill_somafm': ['locale/*', 'ui/*', 'res/*']}, - packages=['skill_somafm'], + package_dir={SKILL_PKG: ""}, + package_data={SKILL_PKG: find_resource_files()}, + packages=[SKILL_PKG], + long_description=long_description, + long_description_content_type="text/markdown", include_package_data=True, - install_requires=["ovos_workshop~=0.0.5a1", "radiosoma"], + install_requires=get_requirements("requirements.txt"), keywords='ovos skill plugin', entry_points={'ovos.plugin.skill': PLUGIN_ENTRY_POINT} ) diff --git a/test/osm_tests.py b/test/osm_tests.py new file mode 100644 index 0000000..fe02af9 --- /dev/null +++ b/test/osm_tests.py @@ -0,0 +1,30 @@ +# write your first unittest! +import unittest +from os.path import exists +from shutil import rmtree + +from ovos_skills_manager import SkillEntry + +branch = "dev" +url = f"https://github.com/OpenVoiceOS/skill-ovos-somafm@{branch}" + + +class TestOSM(unittest.TestCase): + @classmethod + def setUpClass(self): + self.skill_id = "skill-ovos-somafm.openvoiceos" + + def test_osm_install(self): + skill = SkillEntry.from_github_url(url) + tmp_skills = "/tmp/osm_installed_skills" + skill_folder = f"{tmp_skills}/{skill.uuid}" + + if exists(skill_folder): + rmtree(skill_folder) + + updated = skill.install(folder=tmp_skills, default_branch=branch) + self.assertEqual(updated, True) + self.assertTrue(exists(skill_folder)) + + updated = skill.install(folder=tmp_skills, default_branch=branch) + self.assertEqual(updated, False) diff --git a/test/plugin_tests.py b/test/plugin_tests.py new file mode 100644 index 0000000..5ed9760 --- /dev/null +++ b/test/plugin_tests.py @@ -0,0 +1,13 @@ +import unittest +from ovos_plugin_manager.skills import find_skill_plugins + + +class TestPlugin(unittest.TestCase): + @classmethod + def setUpClass(self): + self.skill_id = "skill-ovos-somafm.openvoiceos" + + def test_find_plugin(self): + plugins = find_skill_plugins() + self.assertIn(self.skill_id, list(plugins)) + diff --git a/version.py b/version.py new file mode 100644 index 0000000..76c4342 --- /dev/null +++ b/version.py @@ -0,0 +1,6 @@ +# START_VERSION_BLOCK +VERSION_MAJOR = 0 +VERSION_MINOR = 0 +VERSION_BUILD = 1 +VERSION_ALPHA = 0 +# END_VERSION_BLOCK