Skip to content

Commit

Permalink
build: fetch discovery artifacts from discovery-artifact-manager (#2443)
Browse files Browse the repository at this point in the history
* build: fetch discovery artifacts from discovery-artifact-manager

* remove comment

* restore behavior

* clean up

* clean up

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* address review feedback

* address review feedback

* address review feedback

* clean up

* Add comment

* Address review feedback

* clean up

* Address review feedback

* Address review feedback

* clean up

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* clean up

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
parthea and gcf-owl-bot[bot] authored Jul 17, 2024
1 parent 0cb7266 commit 29b4a11
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
37 changes: 23 additions & 14 deletions describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@

BASE = pathlib.Path(__file__).resolve().parent / "docs" / "dyn"

DIRECTORY_URI = "https://www.googleapis.com/discovery/v1/apis"
# Obtain the discovery index and artifacts from googleapis/discovery-artifact-manager
DIRECTORY_URI = "https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries/index.json"
DISCOVERY_URI_TEMPLATE = "https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries/{api}.{apiVersion}.json"

parser = argparse.ArgumentParser(description=__doc__)

parser.add_argument(
"--discovery_uri_template",
default=DISCOVERY_URI,
default=DISCOVERY_URI_TEMPLATE,
help="URI Template for discovery.",
)

Expand Down Expand Up @@ -390,7 +392,11 @@ def document_collection_recursive(


def document_api(
name, version, uri, doc_destination_dir, artifact_destination_dir=DISCOVERY_DOC_DIR
name,
version,
uri,
doc_destination_dir,
artifact_destination_dir=DISCOVERY_DOC_DIR,
):
"""Document the given API.
Expand All @@ -400,16 +406,11 @@ def document_api(
uri (str): URI of the API's discovery document
doc_destination_dir (str): relative path where the reference
documentation should be saved.
artifact_destination_dir (str): relative path where the discovery
artifact_destination_dir (Optional[str]): relative path where the discovery
artifacts should be saved.
"""
http = build_http()
resp, content = http.request(
uri
or uritemplate.expand(
FLAGS.discovery_uri_template, {"api": name, "apiVersion": version}
)
)
resp, content = http.request(uri)

if resp.status == 200:
discovery = json.loads(content)
Expand Down Expand Up @@ -494,26 +495,33 @@ def generate_all_api_documents(
directory_uri=DIRECTORY_URI,
doc_destination_dir=BASE,
artifact_destination_dir=DISCOVERY_DOC_DIR,
discovery_uri_template=DISCOVERY_URI_TEMPLATE,
):
"""Retrieve discovery artifacts and fetch reference documentations
for all apis listed in the public discovery directory.
args:
directory_uri (str): uri of the public discovery directory.
doc_destination_dir (str): relative path where the reference
directory_uri (Optional[str]): uri of the public discovery directory.
doc_destination_dir (Optional[str]): relative path where the reference
documentation should be saved.
artifact_destination_dir (str): relative path where the discovery
artifact_destination_dir (Optional[str]): relative path where the discovery
artifacts should be saved.
discovery_uri_template (Optional[str]): URI template of the API's discovery
document.
"""
api_directory = collections.defaultdict(list)
http = build_http()
resp, content = http.request(directory_uri)
if resp.status == 200:
directory = json.loads(content)["items"]
for api in directory:
uri = uritemplate.expand(
discovery_uri_template or api["discoveryRestUrl"],
{"api": api["name"], "apiVersion": api["version"]},
)
document_api(
api["name"],
api["version"],
api["discoveryRestUrl"],
uri,
doc_destination_dir,
artifact_destination_dir,
)
Expand Down Expand Up @@ -555,4 +563,5 @@ def generate_all_api_documents(
generate_all_api_documents(
directory_uri=FLAGS.directory_uri,
doc_destination_dir=FLAGS.dest,
discovery_uri_template=FLAGS.discovery_uri_template,
)
3 changes: 2 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,14 @@ def scripts(session):
session.install("-r", "scripts/requirements.txt")

# Run py.test against the unit tests.
# TODO(https://github.com/googleapis/google-api-python-client/issues/2132): Add tests for describe.py
session.run(
"py.test",
"--quiet",
"--cov=scripts",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=91",
"--cov-fail-under=90",
"scripts",
*session.posargs,
)

0 comments on commit 29b4a11

Please sign in to comment.