diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 0546e1d814..f5c036fe95 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4,4 +4,5 @@ # For syntax help see: # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax -* @googleapis/actools-python @googleapis/yoshi-python +* @googleapis/actools-python @googleapis/yoshi-python @lukesneeringer +*.yaml @googleapis/actools @googleapis/yoshi-python @googleapis/actools-python @lukesneeringer diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 00d9c8e1f6..30ca3f5c8f 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -11,15 +11,25 @@ branchProtectionRules: - 'conventionalcommits.org' - 'docs' - 'mypy' - - 'showcase' - - 'showcase-mtls' - - 'showcase-unit' - - 'showcase-unit-alternative-templates' - - 'showcase-unit-add-iam-methods' + - 'showcase (showcase)' + - 'showcase (showcase_alternative_templates)' + - 'showcase-mtls (showcase_mtls)' + - 'showcase-mtls (showcase_mtls_alternative_templates)' - 'showcase-mypy' - - 'showcase-mypy-alternative-templates' - - 'unit' + - 'showcase-mypy (_alternative_templates)' + - 'showcase-unit (3.6)' + - 'showcase-unit (3.7)' + - 'showcase-unit (3.7, _alternative_templates)' + - 'showcase-unit (3.8)' + - 'showcase-unit (3.8, _alternative_templates)' + - 'showcase-unit (3.9)' + - 'showcase-unit (3.9, _alternative_templates)' + - 'showcase-unit-add-iam-methods' - 'style-check' + - 'unit (3.6)' + - 'unit (3.7)' + - 'unit (3.8)' + - 'unit (3.9)' requiredApprovingReviewCount: 1 requiresCodeOwnerReviews: true requiresStrictStatusChecks: true diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5e9f063479..dae6d0bd54 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -13,6 +13,10 @@ jobs: docs: runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v2 @@ -25,6 +29,10 @@ jobs: mypy: runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v2 @@ -73,6 +81,10 @@ jobs: target: [showcase, showcase_alternative_templates] runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v2 @@ -109,6 +121,10 @@ jobs: target: [showcase_mtls, showcase_mtls_alternative_templates] runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - name: Setup temp directory run: | @@ -159,35 +175,16 @@ jobs: strategy: matrix: python: [3.6, 3.7, 3.8, 3.9] + variant: ['', _alternative_templates] + exclude: + - python: 3.6 + variant: _alternative_templates runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v2 + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.7.0 with: - python-version: ${{ matrix.python }} - - name: Install system dependencies. - run: | - sudo apt-get update - sudo apt-get install -y curl pandoc unzip gcc - - name: Install protoc 3.12.1. - run: | - sudo mkdir -p /usr/src/protoc/ - sudo chown -R ${USER} /usr/src/ - curl --location https://github.com/google/protobuf/releases/download/v3.12.1/protoc-3.12.1-linux-x86_64.zip --output /usr/src/protoc/protoc-3.12.1.zip - cd /usr/src/protoc/ - unzip protoc-3.12.1.zip - sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc - - name: Install nox. - run: python -m pip install nox - - name: Run unit tests. - run: nox -s showcase_unit-${{ matrix.python }} - showcase-unit-alternative-templates: - strategy: - matrix: - python: [3.7, 3.8, 3.9] - runs-on: ubuntu-latest - steps: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v2 @@ -208,10 +205,14 @@ jobs: - name: Install nox. run: python -m pip install nox - name: Run unit tests. - run: nox -s showcase_unit_alternative_templates-${{ matrix.python }} + run: nox -s showcase_unit${{ matrix.variant }}-${{ matrix.python }} showcase-unit-add-iam-methods: runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v2 @@ -232,34 +233,17 @@ jobs: - name: Install nox. run: python -m pip install nox - name: Run unit tests. - run: nox -s showcase_unit_add_iam_methods-3.8 + run: nox -s showcase_unit_add_iam_methods showcase-mypy: runs-on: ubuntu-latest + strategy: + matrix: + variant: ['', _alternative_templates] steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.8 - uses: actions/setup-python@v2 + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.7.0 with: - python-version: 3.8 - - name: Install system dependencies. - run: | - sudo apt-get update - sudo apt-get install -y curl pandoc unzip gcc - - name: Install protoc 3.12.1. - run: | - sudo mkdir -p /usr/src/protoc/ - sudo chown -R ${USER} /usr/src/ - curl --location https://github.com/google/protobuf/releases/download/v3.12.1/protoc-3.12.1-linux-x86_64.zip --output /usr/src/protoc/protoc-3.12.1.zip - cd /usr/src/protoc/ - unzip protoc-3.12.1.zip - sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc - - name: Install nox. - run: python -m pip install nox - - name: Typecheck the generated output. - run: nox -s showcase_mypy - showcase-mypy-alternative-templates: - runs-on: ubuntu-latest - steps: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v2 @@ -280,13 +264,17 @@ jobs: - name: Install nox. run: python -m pip install nox - name: Typecheck the generated output. - run: nox -s showcase_mypy_alternative_templates + run: nox -s showcase_mypy${{ matrix.variant }} unit: strategy: matrix: python: [3.6, 3.7, 3.8, 3.9] runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v2 @@ -308,6 +296,10 @@ jobs: style-check: runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.7.0 + with: + access_token: ${{ github.token }} - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c92f6855e..79dcfdedde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [0.40.10](https://www.github.com/googleapis/gapic-generator-python/compare/v0.40.9...v0.40.10) (2021-02-17) + + +### Bug Fixes + +* ignore unknown fields returned from server for REST ([#777](https://www.github.com/googleapis/gapic-generator-python/issues/777)) ([a70b078](https://www.github.com/googleapis/gapic-generator-python/commit/a70b0787f7e3d40642a4f68574f0cc493cc4e054)) + ### [0.40.9](https://www.github.com/googleapis/gapic-generator-python/compare/v0.40.8...v0.40.9) (2021-02-10) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 index f6e380d067..c0e2c9a6ac 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 @@ -48,8 +48,36 @@ class {{ service.async_client_name }}: parse_common_{{ resource_msg.message_type.resource_type|snake_case }}_path = staticmethod({{ service.client_name }}.parse_common_{{ resource_msg.message_type.resource_type|snake_case }}_path) {% endfor %} - from_service_account_info = {{ service.client_name }}.from_service_account_info - from_service_account_file = {{ service.client_name }}.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + {{ service.async_client_name }}: The constructed client. + """ + return {{ service.client_name }}.from_service_account_info.__func__({{ service.async_client_name }}, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + {{ service.async_client_name }}: The constructed client. + """ + return {{ service.client_name }}.from_service_account_file.__func__({{ service.async_client_name }}, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 index 1341571e48..bb6acbadd6 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 @@ -207,7 +207,10 @@ class {{ service.name }}RestTransport({{ service.name }}Transport): {%- if not method.void %} # Return the response - return {{ method.output.ident }}.from_json(response.content) + return {{ method.output.ident }}.from_json( + response.content, + ignore_unknown_fields=True + ) {%- endif %} {%- endif %} {%- endfor %} diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index e03331c680..14a7f03f75 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -77,13 +77,20 @@ def test__get_default_mtls_endpoint(): assert {{ service.client_name }}._get_default_mtls_endpoint(non_googleapi) == non_googleapi -def test_{{ service.client_name|snake_case }}_from_service_account_info(): +@pytest.mark.parametrize("client_class", [ + {{ service.client_name }}, + {%- if 'grpc' in opts.transport %} + {{ service.async_client_name }}, + {%- endif %} +]) +def test_{{ service.client_name|snake_case }}_from_service_account_info(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} - client = {{ service.client_name }}.from_service_account_info(info) + client = client_class.from_service_account_info(info) assert client.transport._credentials == creds + assert isinstance(client, client_class) {% if service.host %}assert client.transport._host == '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}'{% endif %} @@ -100,9 +107,11 @@ def test_{{ service.client_name|snake_case }}_from_service_account_file(client_c factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) {% if service.host %}assert client.transport._host == '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}'{% endif %}