From 1d76b57d1f218f7885f85dc7c052bad1ad3857ac Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 23 Mar 2021 12:53:30 -0700 Subject: [PATCH 1/3] docs: update python contributing guide (#147) Adds details about blacken, updates version for system tests, and shows how to pass through pytest arguments. Source-Author: Chris Cotter Source-Date: Mon Feb 8 17:13:36 2021 -0500 Source-Repo: googleapis/synthtool Source-Sha: 4679e7e415221f03ff2a71e3ffad75b9ec41d87e Source-Link: https://github.com/googleapis/synthtool/commit/4679e7e415221f03ff2a71e3ffad75b9ec41d87e --- CONTRIBUTING.rst | 22 ++++++++++++++++++---- synth.metadata | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 643fbdbb..11161502 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -70,9 +70,14 @@ We use `nox `__ to instrument our tests. - To test your changes, run unit tests with ``nox``:: $ nox -s unit-2.7 - $ nox -s unit-3.7 + $ nox -s unit-3.8 $ ... +- Args to pytest can be passed through the nox command separated by a `--`. For + example, to run a single test:: + + $ nox -s unit-3.8 -- -k + .. note:: The unit tests and system tests are described in the @@ -93,8 +98,12 @@ On Debian/Ubuntu:: ************ Coding Style ************ +- We use the automatic code formatter ``black``. You can run it using + the nox session ``blacken``. This will eliminate many lint errors. Run via:: + + $ nox -s blacken -- PEP8 compliance, with exceptions defined in the linter configuration. +- PEP8 compliance is required, with exceptions defined in the linter configuration. If you have ``nox`` installed, you can test that you have not introduced any non-compliant code via:: @@ -133,13 +142,18 @@ Running System Tests - To run system tests, you can execute:: - $ nox -s system-3.7 + # Run all system tests + $ nox -s system-3.8 $ nox -s system-2.7 + # Run a single system test + $ nox -s system-3.8 -- -k + + .. note:: System tests are only configured to run under Python 2.7 and - Python 3.7. For expediency, we do not run them in older versions + Python 3.8. For expediency, we do not run them in older versions of Python 3. This alone will not run the tests. You'll need to change some local diff --git a/synth.metadata b/synth.metadata index fec849e7..cf254e75 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,14 +4,14 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-api-core.git", - "sha": "94c76e0873e5b2f42331d5b1ad286c1e63b61395" + "sha": "7273090a011c8b840d2e90e29dda3fc8f0eed792" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "33366574ffb9e11737b3547eb6f020ecae0536e8" + "sha": "4679e7e415221f03ff2a71e3ffad75b9ec41d87e" } } ], From 9eaa7868164a7e98792de24d2be97f79fba22322 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Date: Thu, 25 Mar 2021 05:50:03 -0600 Subject: [PATCH 2/3] fix: skip empty policy bindings in `len()` and `iter()` (#159) Exclude empty policy bindings (bindings with no members) in `Policy.__iter__()` and `Policy.__len__()` Follow up to #155 --- google/api_core/iam.py | 10 +++++++--- tests/unit/test_iam.py | 10 +++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/google/api_core/iam.py b/google/api_core/iam.py index d83cbf35..c498c685 100644 --- a/google/api_core/iam.py +++ b/google/api_core/iam.py @@ -125,18 +125,22 @@ def __init__(self, etag=None, version=None): def __iter__(self): self.__check_version__() - return (binding["role"] for binding in self._bindings) + # Exclude bindings with no members + return (binding["role"] for binding in self._bindings if binding["members"]) def __len__(self): self.__check_version__() - return len(self._bindings) + # Exclude bindings with no members + return len(list(self.__iter__())) def __getitem__(self, key): self.__check_version__() for b in self._bindings: if b["role"] == key: return b["members"] - # binding does not yet exist, create one + # If the binding does not yet exist, create one + # NOTE: This will create bindings with no members + # which are ignored by __iter__ and __len__ new_binding = {"role": key, "members": set()} self._bindings.append(new_binding) return new_binding["members"] diff --git a/tests/unit/test_iam.py b/tests/unit/test_iam.py index f9771f0f..0da9b231 100644 --- a/tests/unit/test_iam.py +++ b/tests/unit/test_iam.py @@ -32,11 +32,11 @@ def test_ctor_defaults(self): policy = self._make_one() assert policy.etag is None assert policy.version is None - assert len(policy) == 0 - assert dict(policy) == {} assert policy.owners == empty assert policy.editors == empty assert policy.viewers == empty + assert len(policy) == 0 + assert dict(policy) == {} def test_ctor_explicit(self): VERSION = 1 @@ -45,11 +45,11 @@ def test_ctor_explicit(self): policy = self._make_one(ETAG, VERSION) assert policy.etag == ETAG assert policy.version == VERSION - assert len(policy) == 0 - assert dict(policy) == {} assert policy.owners == empty assert policy.editors == empty assert policy.viewers == empty + assert len(policy) == 0 + assert dict(policy) == {} def test___getitem___miss(self): policy = self._make_one() @@ -301,10 +301,10 @@ def test_from_api_repr_only_etag(self): policy = klass.from_api_repr(RESOURCE) assert policy.etag == "ACAB" assert policy.version is None - assert dict(policy) == {} assert policy.owners == empty assert policy.editors == empty assert policy.viewers == empty + assert dict(policy) == {} def test_from_api_repr_complete(self): from google.api_core.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE From a5b175ffb5123e103a057cf46bac7aa726f8fc80 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 29 Mar 2021 13:33:14 -0600 Subject: [PATCH 3/3] chore: release 1.26.3 (#158) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 12 ++++++++++++ google/api_core/version.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65cbeeff..9700ca71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ [1]: https://pypi.org/project/google-api-core/#history +### [1.26.3](https://www.github.com/googleapis/python-api-core/compare/v1.26.2...v1.26.3) (2021-03-25) + + +### Bug Fixes + +* skip empty policy bindings in `len()` and `iter()` ([#159](https://www.github.com/googleapis/python-api-core/issues/159)) ([9eaa786](https://www.github.com/googleapis/python-api-core/commit/9eaa7868164a7e98792de24d2be97f79fba22322)) + + +### Documentation + +* update python contributing guide ([#147](https://www.github.com/googleapis/python-api-core/issues/147)) ([1d76b57](https://www.github.com/googleapis/python-api-core/commit/1d76b57d1f218f7885f85dc7c052bad1ad3857ac)) + ### [1.26.2](https://www.github.com/googleapis/python-api-core/compare/v1.26.1...v1.26.2) (2021-03-23) diff --git a/google/api_core/version.py b/google/api_core/version.py index 3c06c88d..829945c4 100644 --- a/google/api_core/version.py +++ b/google/api_core/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.26.2" +__version__ = "1.26.3"