diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 17f90ba000c..f78a7d40dbd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,6 +22,9 @@ on: - cron: '0 7 * * 2' workflow_dispatch: +permissions: + contents: read + jobs: build: name: Update Discovery Artifacts PR @@ -40,20 +43,24 @@ 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 . @@ -78,7 +85,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 +105,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)