From 468c93e600f824878715fd9af67a8a2b3df2c505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 28 Jun 2022 22:39:51 +0200 Subject: [PATCH 01/14] Adjust to enum changes in Python 3.11.0b3 There are two changes: Changes in the actual code: - _member_names changed from a list to a dict in https://github.com/python/cpython/pull/28907 - we instance-check and remove by list-specific or dict-specific way Change in the tests only: - accessing other enum members via instance attributes is no longer possible - we access them via the class instead - we leave the original test in a try-except block Some of the Python enum changes might get reverted, see https://github.com/python/cpython/issues/93910 But the fix is backwards compatible. Fixes https://github.com/googleapis/proto-plus-python/issues/326 --- proto/enums.py | 7 +++++-- tests/test_enum_total_ordering.py | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/proto/enums.py b/proto/enums.py index 6f13d32e..6207ad7d 100644 --- a/proto/enums.py +++ b/proto/enums.py @@ -58,8 +58,11 @@ def __new__(mcls, name, bases, attrs): # In 3.7 onwards, we can define an _ignore_ attribute and do some # mucking around with that. if pb_options in attrs._member_names: - idx = attrs._member_names.index(pb_options) - attrs._member_names.pop(idx) + if isinstance(attrs._member_names, list): + idx = attrs._member_names.index(pb_options) + attrs._member_names.pop(idx) + else: # Python 3.11.0b3 + del attrs._member_names[pb_options] # Make the descriptor. enum_desc = descriptor_pb2.EnumDescriptorProto( diff --git a/tests/test_enum_total_ordering.py b/tests/test_enum_total_ordering.py index ad7a3691..584a1831 100644 --- a/tests/test_enum_total_ordering.py +++ b/tests/test_enum_total_ordering.py @@ -49,7 +49,11 @@ def test_total_ordering_w_other_enum_type(): for item in enums_test.OtherEnum: assert not to_compare == item - assert to_compare.SOME_VALUE != item + assert type(to_compare).SOME_VALUE != item + try: + assert to_compare.SOME_VALUE != item + except AttributeError: # Python 3.11.0b3 + pass with pytest.raises(TypeError): assert not to_compare < item with pytest.raises(TypeError): From b20166208800b9df5d3ccacf00a0a0e1d9c56531 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 2 Jul 2022 16:25:47 +0000 Subject: [PATCH 02/14] ci: unit test session with python 3.11.0-beta.3 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eff0c8ff..20999f57 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -46,7 +46,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python: ['3.6', '3.7', '3.8', '3.9', '3.10'] + python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11.0-beta.3'] variant: ['', 'cpp', 'upb'] steps: - name: Cancel Previous Runs From c7371b44385823773ec21c1d1cbc2a5279384f75 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 2 Jul 2022 16:31:53 +0000 Subject: [PATCH 03/14] ci: add python v3.11.0-beta.3 to noxfile.py --- noxfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/noxfile.py b/noxfile.py index 0e65692e..9e27f61c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -23,6 +23,7 @@ PYTHON_VERSIONS = [ + "3.11.0-beta.3", "3.6", "3.7", "3.8", From 7672b52577640f98386820634c37520cd160108c Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 2 Jul 2022 17:59:07 +0000 Subject: [PATCH 04/14] another attempt to get python 3.11.0b3 working in github actions --- .github/workflows/tests.yml | 12 +++++++++--- noxfile.py | 7 +++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 20999f57..284382f3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -61,16 +61,22 @@ jobs: - name: Install nox run: | pip install nox + # Trim the Python version string + - name: Trim python version + run: | + PYTHON_VERSION_TRIMMED=${{ matrix.python }} + PYTHON_VERSION_TRIMMED=$(echo $PYTHON_VERSION_TRIMMED | cut -c1-4) + echo "PYTHON_VERSION_TRIMMED=$PYTHON_VERSION_TRIMMED" >> $GITHUB_ENV - name: Run unit tests env: - COVERAGE_FILE: .coverage-${{ matrix.variant }}-${{ matrix.python }} + COVERAGE_FILE: .coverage-${{ matrix.variant }}-${{ env.PYTHON_VERSION_TRIMMED }} run: | - nox -s unit${{ matrix.variant }}-${{ matrix.python }} + nox -s unit${{ matrix.variant }}-${{ env.PYTHON_VERSION_TRIMMED }} - name: Upload coverage results uses: actions/upload-artifact@v3 with: name: coverage-artifacts - path: .coverage-${{ matrix.variant }}-${{ matrix.python }} + path: .coverage-${{ matrix.variant }}-${{ env.PYTHON_VERSION_TRIMMED }} cover: runs-on: ubuntu-latest needs: diff --git a/noxfile.py b/noxfile.py index 9e27f61c..2ecbaa38 100644 --- a/noxfile.py +++ b/noxfile.py @@ -23,14 +23,17 @@ PYTHON_VERSIONS = [ - "3.11.0-beta.3", "3.6", "3.7", "3.8", "3.9", "3.10", + "3.11", ] +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + @nox.session(python=PYTHON_VERSIONS) def unit(session, proto="python"): @@ -76,7 +79,7 @@ def unitupb(session): # Just use the most recent version for docs -@nox.session(python=PYTHON_VERSIONS[-1]) +@nox.session(python=PYTHON_VERSIONS[-2]) def docs(session): """Build the docs.""" From 280f9d20d67cc8eff33c04316506e2db305bb615 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 2 Jul 2022 18:01:05 +0000 Subject: [PATCH 05/14] ci: use python 3.8 for docs check --- noxfile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index 2ecbaa38..d964ec6b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -78,8 +78,7 @@ def unitupb(session): return unit(session, proto="upb") -# Just use the most recent version for docs -@nox.session(python=PYTHON_VERSIONS[-2]) +@nox.session(python="3.8") def docs(session): """Build the docs.""" From 9f56d97686fbe4113907bb01f8f2070ef1905757 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 2 Jul 2022 18:29:30 +0000 Subject: [PATCH 06/14] ci: fix docs build --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 4c77371e..aeaf3bed 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -64,7 +64,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. From 20acd089630588d296eaadb5131790e7ec6e80ca Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 5 Jan 2023 22:43:26 +0000 Subject: [PATCH 07/14] fix ci --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cdf1f1b3..38192e92 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,10 +39,10 @@ jobs: - name: Build the documentation. run: nox -s docs unit: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: - python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11.0-beta.3'] + python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11'] variant: ['', 'cpp', 'upb'] steps: - uses: actions/checkout@v2 From f635f9c7919244dc8218474d1d2452f5f3f20780 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 5 Jan 2023 22:46:04 +0000 Subject: [PATCH 08/14] mark python 3.11 tests as required --- .github/sync-repo-settings.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index dc6350a8..06c4136b 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -16,6 +16,8 @@ branchProtectionRules: - 'unit (3.9)' - 'unit (3.10, cpp)' - 'unit (3.10)' + - 'unit (3.11, cpp)' + - 'unit (3.11)' - cover - OwlBot Post Processor - 'cla/google' From a1331bb2f6238e022d45a38beb96d26d4df13548 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 5 Jan 2023 22:46:53 +0000 Subject: [PATCH 09/14] add python 3.11 to setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index a1d51f7d..ef2de312 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,7 @@ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Topic :: Software Development :: Code Generators", "Topic :: Software Development :: Libraries :: Python Modules", ], From 1728f4819354f7d59e999ec40f18e9a498cb2fd3 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 5 Jan 2023 22:55:07 +0000 Subject: [PATCH 10/14] fix docs build --- .github/workflows/tests.yml | 4 ++-- noxfile.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 38192e92..0daa0dbf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,10 +30,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up Python 3.8 + - name: Set up Python 3.9 uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.9" - name: Install nox. run: python -m pip install nox - name: Build the documentation. diff --git a/noxfile.py b/noxfile.py index 88825c99..1fd23f44 100644 --- a/noxfile.py +++ b/noxfile.py @@ -78,7 +78,7 @@ def unitupb(session): return unit(session, proto="upb") -@nox.session(python="3.8") +@nox.session(python="3.9") def docs(session): """Build the docs.""" From 880a952e4d083e2aa7820aba5cd6cb89574597a0 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 5 Jan 2023 22:59:32 +0000 Subject: [PATCH 11/14] remove python 3.11 test for unitcpp --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 1fd23f44..e271fa87 100644 --- a/noxfile.py +++ b/noxfile.py @@ -68,7 +68,7 @@ def unit(session, proto="python"): # Check if protobuf has released wheels for new python versions # https://pypi.org/project/protobuf/#files # This list will generally be shorter than 'unit' -@nox.session(python=PYTHON_VERSIONS) +@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"]) def unitcpp(session): return unit(session, proto="cpp") From 85b92fe57ca03020106d7e5790b63c6f79bfa805 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 5 Jan 2023 23:01:37 +0000 Subject: [PATCH 12/14] remove python 3.11 test for unitcpp --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0daa0dbf..a81e33e5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,6 +44,9 @@ jobs: matrix: python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11'] variant: ['', 'cpp', 'upb'] + exclude: + - option: "cpp" + python: 3.11 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python }} From 2b25b4f341f01bd262970048e6311c4f77898e7e Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 5 Jan 2023 23:10:03 +0000 Subject: [PATCH 13/14] remove python 3.11 test for unitcpp --- .github/sync-repo-settings.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 06c4136b..57b398e0 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -16,7 +16,6 @@ branchProtectionRules: - 'unit (3.9)' - 'unit (3.10, cpp)' - 'unit (3.10)' - - 'unit (3.11, cpp)' - 'unit (3.11)' - cover - OwlBot Post Processor From 8ee3eed5ceb1715c96ca6a45b8cc103cd7f58f8a Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 5 Jan 2023 23:13:26 +0000 Subject: [PATCH 14/14] attempt to fix exclude in github action --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a81e33e5..1e8f9636 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,7 +45,7 @@ jobs: python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11'] variant: ['', 'cpp', 'upb'] exclude: - - option: "cpp" + - variant: "cpp" python: 3.11 steps: - uses: actions/checkout@v2