~kf5jwc/garretts-plugin-google

4bbe877b810e52481bef73bd924b5f9cfbdc361e — Kyle Jones 2 years ago 0e07623
Move credentials file into a common module
M text_synthesizer_plugin_google/__init__.py => text_synthesizer_plugin_google/__init__.py +3 -3
@@ 2,18 2,18 @@

__version__ = "0.1.0"

import os as __os
from typing import BinaryIO as _BinaryIO
from os import environ as _environ

from text_synthesizer import Plugin as __plugin, Type as __Type

from .plugin_files import credentials_file as __credentials_file
from .google import synthesize_text as __synthesize
from .exception_handler import exception_catcher as __exception_catcher


# Load the credentials file into the env where TTS expects
_credentials_file = "GOOGLE_APPLICATION_CREDENTIALS"
__environ[_credentials_file] = __Type.plugin_file(_credentials_file)
__os.environ[__credentials_file] = str(__Type.plugin_file(__credentials_file))


# Standard

M text_synthesizer_plugin_google/exception_handler.py => text_synthesizer_plugin_google/exception_handler.py +7 -4
@@ 1,15 1,18 @@
from google.auth.exceptions import DefaultCredentialsError
from text_synthesizer import PluginFileMissing, PluginError

from . import _credentials_file
from .plugin_files import credentials_file


def exception_catcher(fn):
    def func(*args, **kwargs):
        try:
            fn(*args, **kwargs)
        except DefaultCredentialsError:
            raise PluginError("Valid credentials for Google services were not found!")
            raise PluginFileMissing(_credentials_file, "Please select your credentials file. You can find out how to acquire this file from https://developers.google.com/accounts/docs/application-default-credentials.")
            raise PluginFileMissing(
                credentials_file,
                "Valid credentials for Google services were not found!\n\nYou can find out how to acquire this file from https://developers.google.com/accounts/docs/application-default-credentials.",
                "Please select your credentials file.",
            )

    return func


A text_synthesizer_plugin_google/plugin_files.py => text_synthesizer_plugin_google/plugin_files.py +1 -0
@@ 0,0 1,1 @@
credentials_file = "GOOGLE_APPLICATION_CREDENTIALS"