From 1c043a0a83a610cadea7835224eddbd065b997b6 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Thu, 13 Jul 2017 13:57:34 -0700 Subject: [PATCH 1/4] Translate GA. This commit does two things: * Moves the library proper into a versioned namespace. * Removes the BASE/NMT enum; the API producers want this to be a plain string. And then it flips the version number to 1.0. --- translate/google/cloud/translate.py | 25 +++++++++++++++++++ .../{translate => translate_v2}/__init__.py | 9 ++++--- .../{translate => translate_v2}/_http.py | 2 +- .../{translate => translate_v2}/client.py | 6 ++--- translate/setup.py | 4 +-- translate/tests/system.py | 2 +- translate/tests/unit/test__http.py | 4 +-- translate/tests/unit/test_client.py | 11 ++++---- 8 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 translate/google/cloud/translate.py rename translate/google/cloud/{translate => translate_v2}/__init__.py (79%) rename translate/google/cloud/{translate => translate_v2}/_http.py (96%) rename translate/google/cloud/{translate => translate_v2}/client.py (98%) diff --git a/translate/google/cloud/translate.py b/translate/google/cloud/translate.py new file mode 100644 index 000000000000..82d4fb12e060 --- /dev/null +++ b/translate/google/cloud/translate.py @@ -0,0 +1,25 @@ +# Copyright 2017 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Google Cloud Translation API wrapper.""" + + +from google.cloud.translate_v2 import __version__ +from google.cloud.translate_v2.client import Client + + +__all__ = ( + '__version__', + 'Client', +) diff --git a/translate/google/cloud/translate/__init__.py b/translate/google/cloud/translate_v2/__init__.py similarity index 79% rename from translate/google/cloud/translate/__init__.py rename to translate/google/cloud/translate_v2/__init__.py index bf20faa86bdf..11b762101cf7 100644 --- a/translate/google/cloud/translate/__init__.py +++ b/translate/google/cloud/translate_v2/__init__.py @@ -18,9 +18,10 @@ from pkg_resources import get_distribution __version__ = get_distribution('google-cloud-translate').version -from google.cloud.translate.client import BASE -from google.cloud.translate.client import Client -from google.cloud.translate.client import NMT +from google.cloud.translate_v2.client import Client -__all__ = ['__version__', 'BASE', 'Client', 'NMT'] +__all__ = ( + '__version__', + 'Client', +) diff --git a/translate/google/cloud/translate/_http.py b/translate/google/cloud/translate_v2/_http.py similarity index 96% rename from translate/google/cloud/translate/_http.py rename to translate/google/cloud/translate_v2/_http.py index 0c404f2a4a3b..dedb17ec9e14 100644 --- a/translate/google/cloud/translate/_http.py +++ b/translate/google/cloud/translate_v2/_http.py @@ -16,7 +16,7 @@ from google.cloud import _http -from google.cloud.translate import __version__ +from google.cloud.translate_v2 import __version__ _CLIENT_INFO = _http.CLIENT_INFO_TEMPLATE.format(__version__) diff --git a/translate/google/cloud/translate/client.py b/translate/google/cloud/translate_v2/client.py similarity index 98% rename from translate/google/cloud/translate/client.py rename to translate/google/cloud/translate_v2/client.py index 9acd7d65cc47..d72993f0fffd 100644 --- a/translate/google/cloud/translate/client.py +++ b/translate/google/cloud/translate_v2/client.py @@ -20,7 +20,7 @@ from google.cloud._helpers import _to_bytes from google.cloud.client import Client as BaseClient -from google.cloud.translate._http import Connection +from google.cloud.translate_v2._http import Connection ENGLISH_ISO_639 = 'en' @@ -189,8 +189,8 @@ def translate(self, values, target_language=None, format_=None, in the query. :type model: str - :param model: (Optional) The model used to translate the text. The - only accepted values are :attr:`BASE` and :attr:`NMT`. + :param model: (Optional) The model used to translate the text, such + as ``'base'`` or ``'nmt'``. :rtype: str or list :returns: A list of dictionaries for each queried value. Each diff --git a/translate/setup.py b/translate/setup.py index edfaf5cbdc96..12934c6b4e96 100644 --- a/translate/setup.py +++ b/translate/setup.py @@ -35,7 +35,7 @@ 'include_package_data': True, 'zip_safe': False, 'classifiers': [ - 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', @@ -56,7 +56,7 @@ setup( name='google-cloud-translate', - version='0.25.0', + version='1.0.0', description='Python Client for Google Cloud Translation API', long_description=README, namespace_packages=[ diff --git a/translate/tests/system.py b/translate/tests/system.py index e4b971e238f0..7403ed3c0510 100644 --- a/translate/tests/system.py +++ b/translate/tests/system.py @@ -56,7 +56,7 @@ def test_translate(self): values = ['hvala ti', 'dankon', 'Me llamo Jeff', 'My name is Jeff'] translations = Config.CLIENT.translate( - values, target_language='de', model=translate.NMT) + values, target_language='de', model='nmt') self.assertEqual(len(values), len(translations)) self.assertEqual( diff --git a/translate/tests/unit/test__http.py b/translate/tests/unit/test__http.py index 1d7f7b4c6c18..2dc6b015d6de 100644 --- a/translate/tests/unit/test__http.py +++ b/translate/tests/unit/test__http.py @@ -21,7 +21,7 @@ class TestConnection(unittest.TestCase): @staticmethod def _get_target_class(): - from google.cloud.translate._http import Connection + from google.cloud.translate_v2._http import Connection return Connection @@ -57,7 +57,7 @@ def test_build_api_url_w_extra_query_params(self): def test_extra_headers(self): from google.cloud import _http as base_http - from google.cloud.translate import _http as MUT + from google.cloud.translate_v2 import _http as MUT http = mock.Mock(spec=['request']) response = mock.Mock(status=200, spec=['status']) diff --git a/translate/tests/unit/test_client.py b/translate/tests/unit/test_client.py index d2c26cec96c4..18c19c436e45 100644 --- a/translate/tests/unit/test_client.py +++ b/translate/tests/unit/test_client.py @@ -19,16 +19,15 @@ class TestClient(unittest.TestCase): @staticmethod def _get_target_class(): - from google.cloud.translate.client import Client - + from google.cloud.translate import Client return Client def _make_one(self, *args, **kw): return self._get_target_class()(*args, **kw) def test_constructor(self): - from google.cloud.translate._http import Connection - from google.cloud.translate.client import ENGLISH_ISO_639 + from google.cloud.translate_v2._http import Connection + from google.cloud.translate_v2.client import ENGLISH_ISO_639 http = object() client = self._make_one(_http=http) @@ -38,7 +37,7 @@ def test_constructor(self): self.assertEqual(client.target_language, ENGLISH_ISO_639) def test_constructor_non_default(self): - from google.cloud.translate._http import Connection + from google.cloud.translate_v2._http import Connection http = object() target = 'es' @@ -49,7 +48,7 @@ def test_constructor_non_default(self): self.assertEqual(client.target_language, target) def test_get_languages(self): - from google.cloud.translate.client import ENGLISH_ISO_639 + from google.cloud.translate_v2.client import ENGLISH_ISO_639 client = self._make_one(_http=object()) supported = [ From 95e5581351a34ecad1e08464b0d035b7f3b70cfd Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Thu, 13 Jul 2017 14:40:20 -0700 Subject: [PATCH 2/4] Restore the BASE and NMT constants at google.cloud.translate. --- translate/google/cloud/translate.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/translate/google/cloud/translate.py b/translate/google/cloud/translate.py index 82d4fb12e060..9a24ceebcd10 100644 --- a/translate/google/cloud/translate.py +++ b/translate/google/cloud/translate.py @@ -18,8 +18,15 @@ from google.cloud.translate_v2 import __version__ from google.cloud.translate_v2.client import Client +# These constants are essentially deprecated; strings should be used instead. +# They are imported here for backwards compatibility. +from google.cloud.translate_v2.client import BASE +from google.cloud.translate_v2.client import NMT + __all__ = ( '__version__', + 'BASE', 'Client', + 'NMT', ) From 2cebc8bcf3587839bcee03df674121688aa51e01 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Fri, 21 Jul 2017 07:59:51 -0700 Subject: [PATCH 3/4] Update README --- README.rst | 2 +- pubsub/nox.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 9b3d9f0db64e..3de445aba762 100644 --- a/README.rst +++ b/README.rst @@ -20,6 +20,7 @@ The following client libraries have **GA** support: - `Google Cloud Datastore`_ (`Datastore README`_) - `Stackdriver Logging`_ (`Logging README`_) - `Google Cloud Storage`_ (`Storage README`_) +- `Google Cloud Translation`_ (`Translation README`_) **GA** (general availability) indicates that the client library for a particular service is stable, and that the code surface will not change in @@ -33,7 +34,6 @@ The following client libraries have **beta** support: - `Google BigQuery`_ (`BigQuery README`_) - `Google Cloud Vision`_ (`Vision README`_) - `Google Cloud Natural Language`_ (`Natural Language README`_) -- `Google Cloud Translation`_ (`Translation README`_) - `Google Cloud Video Intelligence`_ (`Video Intelligence README`_) **Beta** indicates that the client library for a particular service is diff --git a/pubsub/nox.py b/pubsub/nox.py index 4bcecafe66b4..de3f46991481 100644 --- a/pubsub/nox.py +++ b/pubsub/nox.py @@ -34,14 +34,15 @@ def unit_tests(session, python_version): session.virtualenv_dirname = 'unit-' + python_version # Install all test dependencies, then install this package in-place. - session.install('mock', 'pytest', 'pytest-cov', *LOCAL_DEPS) + session.install('mock', 'pytest', 'pytest-cov', 'pytest-timeout', + *LOCAL_DEPS) session.install('-e', '.') # Run py.test against the unit tests. session.run('py.test', '--quiet', - '--cov=google.cloud.pubsub', '--cov=tests.unit', '--cov-append', - '--cov-config=.coveragerc', '--cov-report=', '--cov-fail-under=97', - 'tests/unit', + '--cov=google.cloud.pubsub_v1', '--cov=google.cloud-pubsub', + '--cov=tests.unit', '--cov-append', '--cov-config=.coveragerc', + '--cov-report=', '--cov-fail-under=97', '--timeout=5', 'tests/unit', ) @@ -112,5 +113,6 @@ def cover(session): """ session.interpreter = 'python3.6' session.install('coverage', 'pytest-cov') - session.run('coverage', 'report', '--show-missing', '--fail-under=100') + session.run('coverage', 'html', success_codes=[0, 2]) + # session.run('coverage', 'report', '--show-missing', '--fail-under=100') session.run('coverage', 'erase') From d1d29763683d1e7c096ff564bba4b66265c7c8b9 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Fri, 21 Jul 2017 08:03:32 -0700 Subject: [PATCH 4/4] Removing pubsub/nox.py local changes that I accidentally staged. --- pubsub/nox.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pubsub/nox.py b/pubsub/nox.py index de3f46991481..4bcecafe66b4 100644 --- a/pubsub/nox.py +++ b/pubsub/nox.py @@ -34,15 +34,14 @@ def unit_tests(session, python_version): session.virtualenv_dirname = 'unit-' + python_version # Install all test dependencies, then install this package in-place. - session.install('mock', 'pytest', 'pytest-cov', 'pytest-timeout', - *LOCAL_DEPS) + session.install('mock', 'pytest', 'pytest-cov', *LOCAL_DEPS) session.install('-e', '.') # Run py.test against the unit tests. session.run('py.test', '--quiet', - '--cov=google.cloud.pubsub_v1', '--cov=google.cloud-pubsub', - '--cov=tests.unit', '--cov-append', '--cov-config=.coveragerc', - '--cov-report=', '--cov-fail-under=97', '--timeout=5', 'tests/unit', + '--cov=google.cloud.pubsub', '--cov=tests.unit', '--cov-append', + '--cov-config=.coveragerc', '--cov-report=', '--cov-fail-under=97', + 'tests/unit', ) @@ -113,6 +112,5 @@ def cover(session): """ session.interpreter = 'python3.6' session.install('coverage', 'pytest-cov') - session.run('coverage', 'html', success_codes=[0, 2]) - # session.run('coverage', 'report', '--show-missing', '--fail-under=100') + session.run('coverage', 'report', '--show-missing', '--fail-under=100') session.run('coverage', 'erase')