Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config handling bugfix and logging/formatting changes (#10) #11

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions .github/workflows/build_tests.yml

This file was deleted.

32 changes: 4 additions & 28 deletions .github/workflows/license_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,10 @@ name: Run License Tests
on:
push:
workflow_dispatch:
pull_request:
branches:
- master

jobs:
license_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- 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: Install licheck
run: |
pip install git+https://github.com/NeonJarbas/lichecker
- name: Install test dependencies
run: |
pip install pytest pytest-timeout pytest-cov
- name: Test Licenses
run: |
pytest tests/license_tests.py
uses: neongeckocom/.github/.github/workflows/license_tests.yml@master
28 changes: 28 additions & 0 deletions .github/workflows/propose_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Propose Stable Release
on:
workflow_dispatch:
inputs:
release_type:
type: choice
description: Release Type
options:
- patch
- minor
- major
jobs:
update_version:
uses: neongeckocom/.github/.github/workflows/propose_semver_release.yml@master
with:
branch: dev
release_type: ${{ inputs.release_type }}
update_changelog: True
version_file: "version.py"
pull_changes:
uses: neongeckocom/.github/.github/workflows/pull_master.yml@master
needs: update_version
with:
pr_reviewer: neonreviewers
pr_assignee: ${{ github.actor }}
pr_draft: false
pr_title: ${{ needs.update_version.outputs.version }}
pr_body: ${{ needs.update_version.outputs.changelog }}
35 changes: 5 additions & 30 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
# This workflow will generate a release distribution and upload it to PyPI

name: Publish Build and GitHub Release
on:
push:
branches:
- master

jobs:
tag_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Version
run: |
VERSION=$(python setup.py --version)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- uses: ncipollo/release-action@v1
with:
token: ${{secrets.GITHUB_TOKEN}}
tag: ${{env.VERSION}}
build_and_publish:
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: Build Distribution Packages
run: |
python setup.py bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{secrets.PYPI_TOKEN}}
build_and_publish_pypi_and_release:
uses: neongeckocom/.github/.github/workflows/publish_stable_release.yml@master
secrets: inherit
37 changes: 9 additions & 28 deletions .github/workflows/publish_test_build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This workflow will generate a distribution and upload it to PyPI

name: Publish Alpha Build
on:
push:
Expand All @@ -7,31 +9,10 @@ on:
- 'version.py'

jobs:
build_and_publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- 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 version_bump.py
- name: Push Version Change
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Increment Version
- name: Build Distribution Packages
run: |
python setup.py bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{secrets.PYPI_TOKEN}}
publish_alpha_release:
uses: neongeckocom/.github/.github/workflows/publish_alpha_release.yml@master
secrets: inherit
with:
version_file: "version.py"
setup_py: "setup.py"
publish_prerelease: true
19 changes: 0 additions & 19 deletions .github/workflows/pull_master.yml

This file was deleted.

16 changes: 2 additions & 14 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@ on:
workflow_dispatch:

jobs:
build_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: Build Distribution Packages
run: |
python setup.py bdist_wheel
py_build_tests:
uses: neongeckocom/.github/.github/workflows/python_build_tests.yml@master
unit_tests:
strategy:
matrix:
Expand Down
63 changes: 48 additions & 15 deletions neon_utterance_translator_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,76 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from ovos_plugin_manager.language import OVOSLangDetectionFactory, OVOSLangTranslationFactory
from typing import Optional, List
from ovos_config import Configuration
from ovos_plugin_manager.language import (OVOSLangDetectionFactory,
OVOSLangTranslationFactory)
from ovos_utils.log import LOG

from neon_transformers import UtteranceTransformer
from neon_transformers.tasks import UtteranceTask


class UtteranceTranslator(UtteranceTransformer):
task = UtteranceTask.TRANSLATION

def __init__(self, name="utterance_translator", config=None, priority=5):
def __init__(self, name: str = "neon_utterance_translator_plugin",
config: Optional[dict] = None, priority: int = 5):
"""
Create an Utterance Transformer to handle translating inputs.
@param name: name of the transformer; used to determine default config
@param config: optional dict config for this plugin
@param priority: priority value for this plugin (1-100 with lower values
taking priority over higher values)
"""
super().__init__(name, priority, config)
self.language_config = self.config.get("language") or {}
self.supported_langs = self.language_config.get('supported_langs') or ['en']
self.internal_lang = self.language_config.get("internal") or 'en-us' or self.supported_langs[0]
self.lang_detector = OVOSLangDetectionFactory.create()
self.translator = OVOSLangTranslationFactory.create()
self.language_config = Configuration().get("language")
self.supported_langs = self.language_config.get('supported_langs') or \
['en']
self.internal_lang = self.language_config.get("internal") or \
self.supported_langs[0]
LOG.debug("Initializing translator")
self.translator = OVOSLangTranslationFactory.create(
self.language_config)
if self.config.get("enable_detector", True):
self.lang_detector = OVOSLangDetectionFactory.create(
self.language_config)
else:
self.lang_detector = None
LOG.info("Detection module disabled in configuration")

def transform(self, utterances, context=None):
def transform(self, utterances: List[str], context: Optional[dict] = None) \
-> (List[str], dict):
"""
Transform and get context for input utterances.
@param utterances: List of string utterances to evaluate
@param context: Optional dict context associated with utterances
@returns: list of transformed utterances, dict calculated context
"""
metadata = []
was_translated = False
for idx, ut in enumerate(utterances):
try:
original = ut
detected_lang = self.lang_detector.detect(original)
if context != None and context.get('lang') != '':
if self.lang_detector:
detected_lang = self.lang_detector.detect(original)
else:
detected_lang = context.get('lang',
self.internal_lang).split('-',
1)[0]
if context and context.get('lang'):
lang = context.get('lang')
if detected_lang != lang.split('-', 1)[0]:
LOG.warning(f"Specified lang: {lang} but detected {detected_lang}")
LOG.warning(f"Specified lang: {lang} but detected "
f"{detected_lang}")
else:
LOG.debug(f"Detected language: {detected_lang}")
else:
LOG.warning(f"No lang provided but detected {detected_lang}")
LOG.warning(f"No lang provided. Detected {detected_lang}")
lang = detected_lang
if lang.split('-', 1)[0] not in self.supported_langs:
LOG.warning(f"There is no: {lang} in supported languages. "
f"Utterance will be translated to {self.internal_lang}")
LOG.warning(f"There is no: {lang} in supported languages "
f"{self.supported_langs}. Utterance will be "
f"translated to {self.internal_lang}")
utterances[idx] = self.translator.translate(
original,
self.internal_lang,
Expand Down
6 changes: 3 additions & 3 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
neon_transformers~=0.1
ovos_plugin_manager~=0.0,>=0.0.17
ovos_utils~=0.0,>=0.0.22
neon_utils>=0.17.3,<2.0.0
ovos_plugin_manager~=0.0.17
ovos_utils~=0.0.22
neon_utils~=1.0
3 changes: 2 additions & 1 deletion requirements/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest
neon-lang-plugin-libretranslate
neon-lang-plugin-libretranslate
ovos-bus-client
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
from os import path, getenv

PLUGIN_ENTRY_POINT = 'utterance_translator_plug = neon_utterance_plugin_translator:UtteranceTranslator'
BASE_PATH = path.abspath(path.dirname(__file__))


def get_requirements(requirements_filename: str):
requirements_file = path.join(path.abspath(path.dirname(__file__)), "requirements", requirements_filename)
requirements_file = path.join(BASE_PATH, "requirements", 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("#")]
Expand All @@ -49,10 +51,11 @@ def get_requirements(requirements_filename: str):
requirements[i] = r.replace("github.com", f"{getenv('GITHUB_TOKEN')}@github.com")
return requirements

with open("README.md", "r") as f:

with open(path.join(BASE_PATH, "README.md"), "r") as f:
long_description = f.read()

with open("./version.py", "r", encoding="utf-8") as v:
with open(path.join(BASE_PATH, "version.py"), "r", encoding="utf-8") as v:
for line in v.readlines():
if line.startswith("__version__"):
if '"' in line:
Expand All @@ -65,11 +68,14 @@ def get_requirements(requirements_filename: str):
name='neon_utterance_translator_plugin',
version=version,
description='A utterance parser/classifier/transformer plugin for ovos/neon/mycroft',
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/NeonGeckoCom/neon_utterance_translator_plugin',
author='Neongecko',
author_email='[email protected]',
license='bsd3',
packages=['neon_utterance_translator_plugin'],
install_requires=get_requirements("requirements.txt"),
zip_safe=True,
keywords='mycroft plugin utterance parser/classifier/transformer',
entry_points={'neon.plugin.text': PLUGIN_ENTRY_POINT}
Expand Down
Loading
Loading