From 9381ef2dcbc0a8d8e66e0aaf6ee81f206a70ace5 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 13 Nov 2023 14:22:07 -0800 Subject: [PATCH 1/3] chore: move grpc, proto-plus and protobuff packages to extras --- setup.py | 10 +++++----- tests/unit/test_legacy_types.py | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 4e87b3b84..4504ecd5a 100644 --- a/setup.py +++ b/setup.py @@ -29,20 +29,16 @@ # 'Development Status :: 5 - Production/Stable' release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "grpcio >= 1.47.0, < 2.0dev", # https://github.com/googleapis/python-bigquery/issues/1262 - "grpcio >= 1.49.1, < 2.0dev; python_version>='3.11'", # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0", - "proto-plus >= 1.15.0, <2.0.0dev", + "google-api-core >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0", # NOTE: Maintainers, please do not require google-cloud-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 "google-cloud-core >= 1.6.0, <3.0.0dev", "google-resumable-media >= 0.6.0, < 3.0dev", "packaging >= 20.0.0", - "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", # For the legacy proto-based types. "python-dateutil >= 2.7.2, <3.0dev", "requests >= 2.21.0, < 3.0.0dev", ] @@ -82,6 +78,10 @@ "opentelemetry-sdk >= 1.1.0", "opentelemetry-instrumentation >= 0.20b0", ], + "bigquery_v2": [ + "proto-plus >= 1.15.0, <2.0.0dev", + "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", # For the legacy proto-based types. + ] } all_extras = [] diff --git a/tests/unit/test_legacy_types.py b/tests/unit/test_legacy_types.py index 3f51cc511..8314e0b41 100644 --- a/tests/unit/test_legacy_types.py +++ b/tests/unit/test_legacy_types.py @@ -13,9 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +import pytest + import warnings +try: + import proto # type: ignore +except ImportError: # pragma: NO COVER + proto = None +@pytest.mark.skipif(proto is None, reason="proto is not installed") def test_importing_legacy_types_emits_warning(): with warnings.catch_warnings(record=True) as warned: from google.cloud.bigquery_v2 import types # noqa: F401 From 25549caa4768f762c50c74e209e2d2e371cb9745 Mon Sep 17 00:00:00 2001 From: kiraksi Date: Mon, 13 Nov 2023 14:29:10 -0800 Subject: [PATCH 2/3] formatted with black --- setup.py | 2 +- tests/unit/test_legacy_types.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4504ecd5a..ead602e12 100644 --- a/setup.py +++ b/setup.py @@ -81,7 +81,7 @@ "bigquery_v2": [ "proto-plus >= 1.15.0, <2.0.0dev", "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", # For the legacy proto-based types. - ] + ], } all_extras = [] diff --git a/tests/unit/test_legacy_types.py b/tests/unit/test_legacy_types.py index 8314e0b41..3431074fd 100644 --- a/tests/unit/test_legacy_types.py +++ b/tests/unit/test_legacy_types.py @@ -22,6 +22,7 @@ except ImportError: # pragma: NO COVER proto = None + @pytest.mark.skipif(proto is None, reason="proto is not installed") def test_importing_legacy_types_emits_warning(): with warnings.catch_warnings(record=True) as warned: From 87e117bda08f47657e1b821e716b7b532455879a Mon Sep 17 00:00:00 2001 From: Chalmer Lowe Date: Thu, 16 Nov 2023 13:29:19 -0500 Subject: [PATCH 3/3] feat: add `job_timeout_ms` to job configuration classes (#1675) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: adds new property and tests * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * updates docs to correct a sphinx failure * Updates formatting * Update tests/system/test_query.py * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update google/cloud/bigquery/job/base.py * updates one test and uses int_or_none * Update tests/system/test_query.py testing something. * Update tests/system/test_query.py * testing coverage feature * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * minor edits * tweaks to noxfile for testing purposes * add new test to base as experiment * adds a test, updates import statements * add another test * edit to tests * formatting fixes * update noxfile to correct debug code * removes unneeded comments. --------- Co-authored-by: Owl Bot --- google/cloud/bigquery/job/base.py | 32 +++++++++++++++++++++++++++++++ noxfile.py | 7 ++++++- tests/unit/job/test_base.py | 15 +++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/google/cloud/bigquery/job/base.py b/google/cloud/bigquery/job/base.py index a6267be41..78df9142f 100644 --- a/google/cloud/bigquery/job/base.py +++ b/google/cloud/bigquery/job/base.py @@ -26,6 +26,7 @@ from google.cloud.bigquery import _helpers from google.cloud.bigquery.retry import DEFAULT_RETRY +from google.cloud.bigquery._helpers import _int_or_none if typing.TYPE_CHECKING: # pragma: NO COVER from google.api_core import retry as retries @@ -171,6 +172,37 @@ def __setattr__(self, name, value): ) super(_JobConfig, self).__setattr__(name, value) + @property + def job_timeout_ms(self): + """Optional parameter. Job timeout in milliseconds. If this time limit is exceeded, BigQuery might attempt to stop the job. + https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfiguration.FIELDS.job_timeout_ms + e.g. + + job_config = bigquery.QueryJobConfig( job_timeout_ms = 5000 ) + or + job_config.job_timeout_ms = 5000 + + Raises: + ValueError: If ``value`` type is invalid. + """ + + # None as this is an optional parameter. + if self._properties.get("jobTimeoutMs"): + return self._properties["jobTimeoutMs"] + return None + + @job_timeout_ms.setter + def job_timeout_ms(self, value): + try: + value = _int_or_none(value) + except ValueError as err: + raise ValueError("Pass an int for jobTimeoutMs, e.g. 5000").with_traceback( + err.__traceback__ + ) + + """ Docs indicate a string is expected by the API """ + self._properties["jobTimeoutMs"] = str(value) + @property def labels(self): """Dict[str, str]: Labels for the job. diff --git a/noxfile.py b/noxfile.py index 703e36cbb..7cf5f6021 100644 --- a/noxfile.py +++ b/noxfile.py @@ -193,7 +193,12 @@ def system(session): session.install("-e", f".{extras}", "-c", constraints_path) # Run py.test against the system tests. - session.run("py.test", "--quiet", os.path.join("tests", "system"), *session.posargs) + session.run( + "py.test", + "--quiet", + os.path.join("tests", "system"), + *session.posargs, + ) @nox.session(python=DEFAULT_PYTHON_VERSION) diff --git a/tests/unit/job/test_base.py b/tests/unit/job/test_base.py index a662e92d4..5635d0e32 100644 --- a/tests/unit/job/test_base.py +++ b/tests/unit/job/test_base.py @@ -1228,3 +1228,18 @@ def test_labels_setter(self): job_config = self._make_one() job_config.labels = labels self.assertEqual(job_config._properties["labels"], labels) + + def test_job_timeout_ms_raises_valueerror(self): + # Confirm that attempting to set a non-integer values will raise an Error. + with pytest.raises(ValueError): + job_config = self._make_one() + job_config.job_timeout_ms = "WillRaiseError" + + def test_job_timeout_ms(self): + # Confirm that default status is None. + job_config = self._make_one() + assert job_config.job_timeout_ms is None + + # Confirm that integers get converted to strings. + job_config.job_timeout_ms = 5000 + assert job_config.job_timeout_ms == "5000" # int is converted to string