From ceb54ec1d4bc924f4592478374296cfae09eb1ce Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Sat, 4 Mar 2023 10:06:25 -0800 Subject: [PATCH] Add PyPI Automation scripts and workflows (#2) * Add PyPI Automation scripts and workflows * Whitelist license_tests.yml for any ovos-skill-* package * Remove automation for unimplemented unit tests --- .github/workflows/auto_translate.yml | 52 +++++++++++++++++ .github/workflows/build_tests.yml | 44 +++++++++++++++ .github/workflows/dev2master.yml | 20 +++++++ .github/workflows/license_tests.yml | 44 +++++++++++++++ .github/workflows/publish_alpha.yml | 72 ++++++++++++++++++++++++ .github/workflows/publish_build.yml | 83 ++++++++++++++++++++++++++++ .github/workflows/publish_major.yml | 83 ++++++++++++++++++++++++++++ .github/workflows/publish_minor.yml | 83 ++++++++++++++++++++++++++++ scripts/bump_alpha.py | 18 ++++++ scripts/bump_build.py | 21 +++++++ scripts/bump_major.py | 27 +++++++++ scripts/bump_minor.py | 24 ++++++++ scripts/migrate_locale.py | 37 +++++++++++++ scripts/prepare_skillstore.py | 76 +++++++++++++++++++++++++ scripts/remove_alpha.py | 13 +++++ scripts/translate.py | 60 ++++++++++++++++++++ setup.py | 33 ++++++++--- version.py | 7 ++- 18 files changed, 788 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/auto_translate.yml create mode 100644 .github/workflows/build_tests.yml create mode 100644 .github/workflows/dev2master.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/migrate_locale.py create mode 100644 scripts/prepare_skillstore.py create mode 100644 scripts/remove_alpha.py create mode 100644 scripts/translate.py diff --git a/.github/workflows/auto_translate.yml b/.github/workflows/auto_translate.yml new file mode 100644 index 0000000..2945f94 --- /dev/null +++ b/.github/workflows/auto_translate.yml @@ -0,0 +1,52 @@ +name: Auto translate +on: + workflow_dispatch: + push: + branches: + - dev + +jobs: + translate: + 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 Translate Tools + run: | + pip install git+https://github.com/NeonGeckoCom/neon-lang-plugin-libretranslate + - name: Auto Translate + run: | + python scripts/translate.py + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Auto Translate + branch: dev + prepare_skillstore: + 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 OSM + run: | + pip install ovos-skills-manager~=0.0.10 + - name: Update Skill Store metadata + run: | + python scripts/prepare_skillstore.py + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Update skill store metadata + branch: dev diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml new file mode 100644 index 0000000..2d3f499 --- /dev/null +++ b/.github/workflows/build_tests.yml @@ -0,0 +1,44 @@ +name: Run Build Tests +on: + push: + branches: + - master + pull_request: + branches: + - dev + 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/license_tests.yml b/.github/workflows/license_tests.yml new file mode 100644 index 0000000..46c73f4 --- /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-).*' + 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..4de9b8d --- /dev/null +++ b/.github/workflows/publish_alpha.yml @@ -0,0 +1,72 @@ +# This workflow will generate a distribution and upload it to PyPI + +name: Publish Alpha Build ...aX +on: + push: + branches: + - dev + paths-ignore: + - 'skill_naptime/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 }} + id: changelog + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Prepare alpha version package + 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 + - name: Build Distribution Packages + run: | + python setup.py bdist_wheel + - name: Publish to Test PyPI + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{secrets.PYPI_TOKEN}} \ No newline at end of file diff --git a/.github/workflows/publish_build.yml b/.github/workflows/publish_build.yml new file mode 100644 index 0000000..65e168b --- /dev/null +++ b/.github/workflows/publish_build.yml @@ -0,0 +1,83 @@ +# 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: Install OSM + run: | + pip install ovos-skills-manager~=0.0.10 + - name: Remove alpha (declare stable) + run: | + VER=$(python setup.py --version) + python scripts/remove_alpha.py + - name: Prepare Skillstore metadata + run: | + python scripts/prepare_skillstore.py + python scripts/release_skillstore.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 + - 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 Test PyPI + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{secrets.PYPI_TOKEN}} \ No newline at end of file diff --git a/.github/workflows/publish_major.yml b/.github/workflows/publish_major.yml new file mode 100644 index 0000000..09121b4 --- /dev/null +++ b/.github/workflows/publish_major.yml @@ -0,0 +1,83 @@ +# 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: Install OSM + run: | + pip install ovos-skills-manager~=0.0.10 + - name: Remove alpha (declare stable) + run: | + VER=$(python setup.py --version) + python scripts/remove_alpha.py + - name: Prepare Skillstore metadata + run: | + python scripts/prepare_skillstore.py + python scripts/release_skillstore.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 + - 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 Test PyPI + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{secrets.PYPI_TOKEN}} \ No newline at end of file diff --git a/.github/workflows/publish_minor.yml b/.github/workflows/publish_minor.yml new file mode 100644 index 0000000..fe98511 --- /dev/null +++ b/.github/workflows/publish_minor.yml @@ -0,0 +1,83 @@ +# 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: Install OSM + run: | + pip install ovos-skills-manager~=0.0.10 + - name: Remove alpha (declare stable) + run: | + VER=$(python setup.py --version) + python scripts/remove_alpha.py + - name: Prepare Skillstore metadata + run: | + python scripts/prepare_skillstore.py + python scripts/release_skillstore.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 + - 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 Test PyPI + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{secrets.PYPI_TOKEN}} \ No newline at end of file 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/migrate_locale.py b/scripts/migrate_locale.py new file mode 100644 index 0000000..b1b02ef --- /dev/null +++ b/scripts/migrate_locale.py @@ -0,0 +1,37 @@ +import os +import shutil +from os.path import dirname, join, exists + +base_folder = dirname(dirname(__file__)) +res_folder = join(base_folder, "locale") +voc_folder = join(base_folder, "vocab") +dialog_folder = join(base_folder, "dialog") +regex_folder = join(base_folder, "regex") + +if exists(voc_folder): + for lang in os.listdir(voc_folder): + path = join(voc_folder, lang) + os.makedirs(join(res_folder, lang), exist_ok=True) + for f in os.listdir(path): + shutil.move(join(path, f), join(res_folder, lang, f)) + shutil.rmtree(path) + shutil.rmtree(voc_folder) + +if exists(dialog_folder): + for lang in os.listdir(dialog_folder): + path = join(dialog_folder, lang) + os.makedirs(join(res_folder, lang), exist_ok=True) + for f in os.listdir(path): + shutil.move(join(path, f), join(res_folder, lang, f)) + shutil.rmtree(path) + shutil.rmtree(dialog_folder) + + +if exists(regex_folder): + for lang in os.listdir(regex_folder): + path = join(regex_folder, lang) + os.makedirs(join(res_folder, lang), exist_ok=True) + for f in os.listdir(path): + shutil.move(join(path, f), join(res_folder, lang, f)) + shutil.rmtree(path) + shutil.rmtree(regex_folder) \ No newline at end of file diff --git a/scripts/prepare_skillstore.py b/scripts/prepare_skillstore.py new file mode 100644 index 0000000..411734c --- /dev/null +++ b/scripts/prepare_skillstore.py @@ -0,0 +1,76 @@ +from ovos_skills_manager import SkillEntry +from os.path import exists, join, dirname +from shutil import rmtree +import os +from os import makedirs +import json +from ovos_utils.bracket_expansion import expand_parentheses, expand_options + + +branch = "dev" +repo = "skill-ovos-date-time" +author = "OpenVoiceOS" + +url = f"https://github.com/{author}/{repo}@{branch}" + +skill = SkillEntry.from_github_url(url) +tmp_skills = "/tmp/osm_installed_skills" +skill_folder = f"{tmp_skills}/{skill.uuid}" + +base_dir = dirname(dirname(__file__)) +desktop_dir = join(base_dir, "res", "desktop") +android_ui = join(base_dir, "ui", "+android") +makedirs(desktop_dir, exist_ok=True) + +readme = join(base_dir, "README.md") +jsonf = join(desktop_dir, "skill.json") +desktopf = join(desktop_dir, f"{repo}.desktop") +skill_code = join(base_dir, "__init__.py") + +res_folder = join(base_dir, "locale", "en-us") + + +def read_samples(path): + samples = [] + with open(path) as fi: + for _ in fi.read().split("\n"): + if _ and not _.strip().startswith("#"): + samples += expand_options(_) + return samples + +samples = [] +for root, folders, files in os.walk(res_folder): + for f in files: + if f.endswith(".intent"): + samples += read_samples(join(root, f)) +skill._data["examples"] = list(set(samples)) + +has_android = exists(android_ui) +with open(skill_code) as f: + has_homescreen = f"{repo}.{author}.home" in f.read() + +if not exists(readme): + with open(readme, "w") as f: + f.write(skill.generate_readme()) + +if has_homescreen and not exists(desktopf): + with open(desktopf, "w") as f: + f.write(skill.desktop_file) + +if not exists(jsonf): + data = skill.json + with open(jsonf, "w") as f: + if not has_android or not has_homescreen: + data.pop("android") + if not has_homescreen: + data.pop("desktop") + data["desktopFile"] = False +else: + with open(jsonf) as f: + data = json.load(f) + +# set dev branch +data["branch"] = "dev" + +with open(jsonf, "w") as f: + json.dump(data, f, indent=4) 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/scripts/translate.py b/scripts/translate.py new file mode 100644 index 0000000..5835a6e --- /dev/null +++ b/scripts/translate.py @@ -0,0 +1,60 @@ +import os +from os.path import dirname, join, exists +from ovos_utils.bracket_expansion import expand_options +from libretranslate_neon_plugin import LibreTranslatePlugin + +tx = LibreTranslatePlugin(config={"libretranslate_host": "https://libretranslate.2022.us"}) + +src_lang = "en-us" +target_langs = ["es-es", "de-de", "fr-fr", "it-it", "pt-pt"] + +exts = [".voc", ".dialog", ".intent", ".entity"] +res_folder = join(dirname(dirname(__file__)), "locale") +target_langs = list(set(target_langs + os.listdir(res_folder))) + +src_files = {} +for root, dirs, files in os.walk(res_folder): + if src_lang not in root: + continue + for f in files: + if any(f.endswith(e) for e in exts): + src_files[f] = join(root, f) + +for lang in target_langs: + os.makedirs(join(res_folder, lang), exist_ok=True) + + for name, src in src_files.items(): + if name.endswith(".dialog"): + os.makedirs(join(res_folder, lang, "dialog"), exist_ok=True) + dst = join(res_folder, lang, "dialog", name) + elif name.endswith(".voc"): + os.makedirs(join(res_folder, lang, "vocab"), exist_ok=True) + dst = join(res_folder, lang, "vocab", name) + elif name.endswith(".rx"): + os.makedirs(join(res_folder, lang, "regex"), exist_ok=True) + dst = join(res_folder, lang, "regex", name) + elif name.endswith(".intent"): + os.makedirs(join(res_folder, lang, "intents"), exist_ok=True) + dst = join(res_folder, lang, "intents", name) + else: + dst = join(res_folder, lang, name) + if exists(dst): + continue + + tx_lines = [] + with open(src) as f: + lines = [l for l in f.read().split("\n") if l and not l.startswith("#")] + + for l in lines: + expanded = expand_options(l) + for l2 in expanded: + try: + translated = tx.translate(l2, target=lang, source=src_lang) + tx_lines.append(translated) + except: + continue + + with open(dst, "w") as f: + f.write(f"# auto translated from {src_lang} to {lang}\n") + for translated in set(tx_lines): + f.write(translated + "\n") diff --git a/setup.py b/setup.py index d173abc..890d0d9 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import os from setuptools import setup from os import walk, path @@ -30,18 +31,34 @@ def find_resource_files(): with open("README.md", "r") as f: long_description = f.read() -with open("./version.py", "r", encoding="utf-8") as v: - for line in v.readlines(): - if line.startswith("__version__"): - if '"' in line: - version = line.split('"')[1] - else: - version = line.split("'")[1] + +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 setup( name=PYPI_NAME, - version=version, + version=get_version(), long_description=long_description, url=URL, author=SKILL_AUTHOR, diff --git a/version.py b/version.py index d18f409..23532c1 100644 --- a/version.py +++ b/version.py @@ -1 +1,6 @@ -__version__ = '0.0.2' +# START_VERSION_BLOCK +VERSION_MAJOR = 0 +VERSION_MINOR = 0 +VERSION_BUILD = 3 +VERSION_ALPHA = 0 +# END_VERSION_BLOCK