Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ on:
- cron: '0 7 * * 2'
workflow_dispatch:

permissions:
contents: read

jobs:
build:
name: Update Discovery Artifacts PR
Expand All @@ -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 .
Expand All @@ -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
Expand All @@ -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}"
3 changes: 2 additions & 1 deletion googleapiclient/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"):
Expand Down
2 changes: 1 addition & 1 deletion googleapiclient/mimeparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "*"
Expand Down
4 changes: 2 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -31,7 +31,7 @@
"setup.py",
]

DEFAULT_PYTHON_VERSION = "3.10"
DEFAULT_PYTHON_VERSION = "3.14"

test_dependencies = [
"django>=2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions samples/compute/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pandas==2.2.2
pandas==3.0.5
116 changes: 63 additions & 53 deletions scripts/updatediscoveryartifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Loading