From d52f48e7ee6bc9c1f6f264bef53ff1ba99c5a29c Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Wed, 26 Aug 2026 09:42:37 -0400 Subject: [PATCH 1/2] ci: update Python runtime to 3.14 in GHA workflow --- .github/workflows/main.yml | 32 ++++++-- googleapiclient/discovery.py | 3 +- googleapiclient/mimeparse.py | 2 +- noxfile.py | 4 +- samples/compute/requirements.txt | 6 +- scripts/requirements.txt | 2 +- scripts/updatediscoveryartifacts.py | 116 +++++++++++++++------------- tests/test_model.py | 2 +- 8 files changed, 98 insertions(+), 69 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 17f90ba000c..4b95d520f1b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,12 +16,16 @@ name: A workflow for updating discovery artifacts # Controls when the action will run. on: + pull_request: schedule: # * is a special character in YAML so you have to quote this string # Run this Github Action every Tuesday at 7 AM UTC - cron: '0 7 * * 2' workflow_dispatch: +permissions: + contents: read + jobs: build: name: Update Discovery Artifacts PR @@ -40,24 +44,35 @@ jobs: GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }} - name: Check out main branch - uses: actions/checkout@v4 + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: ref: refs/heads/main repository: 'yoshi-code-bot/google-api-python-client' token: ${{secrets.YOSHI_CODE_BOT_TOKEN}} + persist-credentials: false + fetch-depth: 0 - name: Create branch run: | - git checkout -b update-discovery-artifacts-${{ steps.date.outputs.current_date }} + git checkout -b update-discovery-artifacts-${STEPS_DATE_OUTPUTS_CURRENT_DATE} + env: + STEPS_DATE_OUTPUTS_CURRENT_DATE: ${{ steps.date.outputs.current_date }} - - name: Set up Python 3.9 - uses: actions/setup-python@v5 + - name: Set up Python 3.14 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 with: - python-version: 3.9 + python-version: 3.14 - name: Install google-api-python-client run: pip3 install -e . + # Checkout requirements.txt from the PR branch on the main repository + - name: Checkout requirements.txt from PR branch + if: github.event_name == 'pull_request' + run: | + git fetch https://github.com/googleapis/google-api-python-client.git refs/pull/${{ github.event.pull_request.number }}/head:pr-branch + git checkout pr-branch -- scripts/ + - name: Install script dependencies run: pip3 install -r requirements.txt working-directory: ./scripts @@ -78,7 +93,9 @@ jobs: working-directory: ./scripts - name: Push changes - run: git push -u origin update-discovery-artifacts-${{ steps.date.outputs.current_date }} + run: git push -u origin update-discovery-artifacts-${STEPS_DATE_OUTPUTS_CURRENT_DATE} + env: + STEPS_DATE_OUTPUTS_CURRENT_DATE: ${{ steps.date.outputs.current_date }} - name: Prepare summary for PR Body id: pr_body @@ -96,5 +113,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }} PR_TITLE: "chore: Update discovery artifacts" + STEPS_PR_BODY_OUTPUTS_CHANGE_SUMMARY: ${{ steps.pr_body.outputs.change_summary }} run: | - gh pr create -R "googleapis/google-api-python-client" -B "main" --title "$PR_TITLE" --body "${{ steps.pr_body.outputs.change_summary }}" + gh pr create -R "googleapis/google-api-python-client" -B "main" --title "$PR_TITLE" --body "${STEPS_PR_BODY_OUTPUTS_CHANGE_SUMMARY}" diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py index e1f7ee48df9..16e02bb4ac9 100644 --- a/googleapiclient/discovery.py +++ b/googleapiclient/discovery.py @@ -142,6 +142,7 @@ def __init__(self): # Library-specific reserved words beyond Python keywords. RESERVED_WORDS = frozenset(["body"]) + # patch _write_lines to avoid munging '\r' into '\n' # ( https://bugs.python.org/issue18886 https://bugs.python.org/issue19003 ) class _BytesGenerator(BytesGenerator): @@ -1325,7 +1326,7 @@ def method(self, **kwargs): enumDesc = paramdesc.get("enumDescriptions", []) if enum and enumDesc: docs.append(" Allowed values\n") - for (name, desc) in zip(enum, enumDesc): + for name, desc in zip(enum, enumDesc): docs.append(" %s - %s\n" % (name, desc)) if "response" in methodDesc: if methodName.endswith("_media"): diff --git a/googleapiclient/mimeparse.py b/googleapiclient/mimeparse.py index d3dedee9c53..d8c4808ba74 100644 --- a/googleapiclient/mimeparse.py +++ b/googleapiclient/mimeparse.py @@ -95,7 +95,7 @@ def fitness_and_quality_parsed(mime_type, parsed_ranges): best_fitness = -1 best_fit_q = 0 (target_type, target_subtype, target_params) = parse_media_range(mime_type) - for (type, subtype, params) in parsed_ranges: + for type, subtype, params in parsed_ranges: type_match = type == target_type or type == "*" or target_type == "*" subtype_match = ( subtype == target_subtype or subtype == "*" or target_subtype == "*" diff --git a/noxfile.py b/noxfile.py index 5869a83136a..fbde0222441 100644 --- a/noxfile.py +++ b/noxfile.py @@ -17,7 +17,7 @@ import nox -BLACK_VERSION = "black==22.3.0" +BLACK_VERSION = "black==23.7.0" ISORT_VERSION = "isort==5.10.1" BLACK_PATHS = [ "apiclient", @@ -31,7 +31,7 @@ "setup.py", ] -DEFAULT_PYTHON_VERSION = "3.10" +DEFAULT_PYTHON_VERSION = "3.14" test_dependencies = [ "django>=2.0.0", diff --git a/samples/compute/requirements.txt b/samples/compute/requirements.txt index 8d5f648576f..8e346f93af9 100644 --- a/samples/compute/requirements.txt +++ b/samples/compute/requirements.txt @@ -1,3 +1,3 @@ -google-api-python-client==2.134.0 -google-auth==2.30.0 -google-auth-httplib2==0.2.0 +google-api-python-client==2.199.0 +google-auth==2.57.0 +google-auth-httplib2==0.4.2 diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 4b2e332e243..f2918d21c9d 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -1 +1 @@ -pandas==2.2.2 +pandas==3.0.5 diff --git a/scripts/updatediscoveryartifacts.py b/scripts/updatediscoveryartifacts.py index fd663480b74..ceb4e96bba8 100644 --- a/scripts/updatediscoveryartifacts.py +++ b/scripts/updatediscoveryartifacts.py @@ -29,56 +29,66 @@ REFERENCE_DOC_DIR = SCRIPTS_DIR / ".." / "docs" / "dyn" TEMP_DIR = SCRIPTS_DIR / "temp" -# Clear discovery documents and reference documents directory -shutil.rmtree(DISCOVERY_DOC_DIR, ignore_errors=True) -shutil.rmtree(REFERENCE_DOC_DIR, ignore_errors=True) - -# Clear temporary directory -shutil.rmtree(TEMP_DIR, ignore_errors=True) - -# Check out a fresh copy -subprocess.call(["git", "checkout", DISCOVERY_DOC_DIR]) -subprocess.call(["git", "checkout", REFERENCE_DOC_DIR]) - -# Snapshot current discovery artifacts to a temporary directory -with tempfile.TemporaryDirectory() as current_discovery_doc_dir: - shutil.copytree(DISCOVERY_DOC_DIR, current_discovery_doc_dir, dirs_exist_ok=True) - - # Download discovery artifacts and generate documentation - describe.generate_all_api_documents( - doc_destination_dir=REFERENCE_DOC_DIR, - artifact_destination_dir=DISCOVERY_DOC_DIR, - ) - - # Get a list of files changed using `git diff` - git_diff_output = subprocess.check_output( - [ - "git", - "diff", - "origin/main", - "--name-only", - "--", - DISCOVERY_DOC_DIR / "*.json", - REFERENCE_DOC_DIR / "*.html", - REFERENCE_DOC_DIR / "*.md", - ], - universal_newlines=True, - ) - - # Create lists of the changed files - all_changed_files = [ - pathlib.Path(file_name).name for file_name in git_diff_output.split("\n") - ] - json_changed_files = [file for file in all_changed_files if file.endswith(".json")] - - # Create temporary directory - pathlib.Path(TEMP_DIR).mkdir() - - # Analyze the changes in discovery artifacts using the changesummary module - changesummary.ChangeSummary( - DISCOVERY_DOC_DIR, current_discovery_doc_dir, TEMP_DIR, json_changed_files - ).detect_discovery_changes() - - # Write a list of the files changed to a file called `changed files` which will be used in the `createcommits.sh` script. - with open(TEMP_DIR / "changed_files", "w") as f: - f.writelines("\n".join(all_changed_files)) + +def main(): + # Clear discovery documents and reference documents directory + shutil.rmtree(DISCOVERY_DOC_DIR, ignore_errors=True) + shutil.rmtree(REFERENCE_DOC_DIR, ignore_errors=True) + + # Clear temporary directory + shutil.rmtree(TEMP_DIR, ignore_errors=True) + + # Check out a fresh copy + subprocess.call(["git", "checkout", DISCOVERY_DOC_DIR]) + subprocess.call(["git", "checkout", REFERENCE_DOC_DIR]) + + # Snapshot current discovery artifacts to a temporary directory + with tempfile.TemporaryDirectory() as current_discovery_doc_dir: + shutil.copytree( + DISCOVERY_DOC_DIR, current_discovery_doc_dir, dirs_exist_ok=True + ) + + # Download discovery artifacts and generate documentation + describe.generate_all_api_documents( + doc_destination_dir=REFERENCE_DOC_DIR, + artifact_destination_dir=DISCOVERY_DOC_DIR, + ) + + # Get a list of files changed using `git diff` + git_diff_output = subprocess.check_output( + [ + "git", + "diff", + "origin/main", + "--name-only", + "--", + DISCOVERY_DOC_DIR / "*.json", + REFERENCE_DOC_DIR / "*.html", + REFERENCE_DOC_DIR / "*.md", + ], + universal_newlines=True, + ) + + # Create lists of the changed files + all_changed_files = [ + pathlib.Path(file_name).name for file_name in git_diff_output.split("\n") + ] + json_changed_files = [ + file for file in all_changed_files if file.endswith(".json") + ] + + # Create temporary directory + pathlib.Path(TEMP_DIR).mkdir() + + # Analyze the changes in discovery artifacts using the changesummary module + changesummary.ChangeSummary( + DISCOVERY_DOC_DIR, current_discovery_doc_dir, TEMP_DIR, json_changed_files + ).detect_discovery_changes() + + # Write a list of the files changed to a file called `changed files` which will be used in the `createcommits.sh` script. + with open(TEMP_DIR / "changed_files", "w") as f: + f.writelines("\n".join(all_changed_files)) + + +if __name__ == "__main__": + main() diff --git a/tests/test_model.py b/tests/test_model.py index cd868c47ba5..b1e596d8da0 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -64,7 +64,7 @@ class TestPatch(unittest.TestCase): def test_patch(self): - for (msg, orig, mod, expected_patch) in TEST_CASES: + for msg, orig, mod, expected_patch in TEST_CASES: self.assertEqual(expected_patch, makepatch(orig, mod), msg=msg) From 4948824e1e0d7c12a33ae7df34597dc0852df5db Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Wed, 26 Aug 2026 17:30:03 +0000 Subject: [PATCH 2/2] revert changes used only for testing --- .github/workflows/main.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4b95d520f1b..f78a7d40dbd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,6 @@ name: A workflow for updating discovery artifacts # Controls when the action will run. on: - pull_request: schedule: # * is a special character in YAML so you have to quote this string # Run this Github Action every Tuesday at 7 AM UTC @@ -66,13 +65,6 @@ jobs: - name: Install google-api-python-client run: pip3 install -e . - # Checkout requirements.txt from the PR branch on the main repository - - name: Checkout requirements.txt from PR branch - if: github.event_name == 'pull_request' - run: | - git fetch https://github.com/googleapis/google-api-python-client.git refs/pull/${{ github.event.pull_request.number }}/head:pr-branch - git checkout pr-branch -- scripts/ - - name: Install script dependencies run: pip3 install -r requirements.txt working-directory: ./scripts