Skip to content

Commit

Permalink
Merge branch 'main' into set-output
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed May 24, 2023
2 parents 77b29ef + 915a4fe commit 56667a3
Show file tree
Hide file tree
Showing 1,454 changed files with 126,352 additions and 27,854 deletions.
5 changes: 4 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[report]
omit = */samples/*
omit =
*/samples/*
# Issue tracked in https://github.com/googleapis/google-api-python-client/issues/2132
describe.py
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
working-directory: ./scripts

- name: Create PR
uses: actions/github-script@v6.4.0
uses: actions/github-script@v6.4.1
with:
github-token: ${{secrets.YOSHI_CODE_BOT_TOKEN}}
script: |
Expand Down
209 changes: 209 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ The following libraries will be installed when you install the client library:
* [uritemplate](https://github.com/sigmavirus24/uritemplate)

For development you will also need the following libraries:
* [WebTest](http://webtest.pythonpaste.org/en/latest/index.html)
* [WebTest](https://pypi.org/project/WebTest/)
* [pyopenssl](https://pypi.python.org/pypi/pyOpenSSL)

## Contributing
Expand Down
45 changes: 35 additions & 10 deletions describe.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from googleapiclient.http import build_http

DISCOVERY_DOC_DIR = (
pathlib.Path(__file__).parent.resolve()
pathlib.Path(__file__).resolve().parent
/ "googleapiclient"
/ "discovery_cache"
/ "documents"
Expand Down Expand Up @@ -134,7 +134,7 @@
<code><a href="#$name">$name($params)</a></code></p>
<p class="firstline">$firstline</p>"""

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

DIRECTORY_URI = "https://www.googleapis.com/discovery/v1/apis"

Expand Down Expand Up @@ -356,7 +356,12 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS):


def document_collection_recursive(
resource, path, root_discovery, discovery, doc_destination_dir
resource,
path,
root_discovery,
discovery,
doc_destination_dir,
artifact_destination_dir=DISCOVERY_DOC_DIR,
):
html = document_collection(resource, path, root_discovery, discovery)

Expand All @@ -380,10 +385,13 @@ def document_collection_recursive(
root_discovery,
discovery["resources"].get(dname, {}),
doc_destination_dir,
artifact_destination_dir,
)


def document_api(name, version, uri, doc_destination_dir):
def document_api(
name, version, uri, doc_destination_dir, artifact_destination_dir=DISCOVERY_DOC_DIR
):
"""Document the given API.
Args:
Expand All @@ -392,6 +400,8 @@ def document_api(name, version, uri, doc_destination_dir):
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
artifacts should be saved.
"""
http = build_http()
resp, content = http.request(
Expand All @@ -405,7 +415,7 @@ def document_api(name, version, uri, doc_destination_dir):
discovery = json.loads(content)
service = build_from_document(discovery)
doc_name = "{}.{}.json".format(name, version)
discovery_file_path = DISCOVERY_DOC_DIR / doc_name
discovery_file_path = artifact_destination_dir / doc_name
revision = None

pathlib.Path(discovery_file_path).touch(exist_ok=True)
Expand Down Expand Up @@ -445,16 +455,21 @@ def document_api(name, version, uri, doc_destination_dir):
discovery,
discovery,
doc_destination_dir,
artifact_destination_dir,
)


def document_api_from_discovery_document(discovery_url, doc_destination_dir):
def document_api_from_discovery_document(
discovery_url, doc_destination_dir, artifact_destination_dir=DISCOVERY_DOC_DIR
):
"""Document the given API.
Args:
discovery_url (str): URI of discovery document.
doc_destination_dir (str): relative path where the reference
documentation should be saved.
artifact_destination_dir (str): relative path where the discovery
artifacts should be saved.
"""
http = build_http()
response, content = http.request(discovery_url)
Expand All @@ -471,16 +486,23 @@ def document_api_from_discovery_document(discovery_url, doc_destination_dir):
discovery,
discovery,
doc_destination_dir,
artifact_destination_dir,
)


def generate_all_api_documents(directory_uri=DIRECTORY_URI, doc_destination_dir=BASE):
def generate_all_api_documents(
directory_uri=DIRECTORY_URI,
doc_destination_dir=BASE,
artifact_destination_dir=DISCOVERY_DOC_DIR,
):
"""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
documentation should be saved.
artifact_destination_dir (str): relative path where the discovery
artifacts should be saved.
"""
api_directory = collections.defaultdict(list)
http = build_http()
Expand All @@ -493,6 +515,7 @@ def generate_all_api_documents(directory_uri=DIRECTORY_URI, doc_destination_dir=
api["version"],
api["discoveryRestUrl"],
doc_destination_dir,
artifact_destination_dir,
)
api_directory[api["name"]].append(api["version"])

Expand All @@ -513,7 +536,7 @@ def generate_all_api_documents(directory_uri=DIRECTORY_URI, doc_destination_dir=
)
markdown.append("\n")

with open(BASE / "index.md", "w") as f:
with open(doc_destination_dir / "index.md", "w") as f:
markdown = "\n".join(markdown)
f.write(markdown)

Expand All @@ -525,9 +548,11 @@ def generate_all_api_documents(directory_uri=DIRECTORY_URI, doc_destination_dir=
FLAGS = parser.parse_args(sys.argv[1:])
if FLAGS.discovery_uri:
document_api_from_discovery_document(
discovery_url=FLAGS.discovery_uri, doc_destination_dir=FLAGS.dest
discovery_url=FLAGS.discovery_uri,
doc_destination_dir=FLAGS.dest,
)
else:
generate_all_api_documents(
directory_uri=FLAGS.directory_uri, doc_destination_dir=FLAGS.dest
directory_uri=FLAGS.directory_uri,
doc_destination_dir=FLAGS.dest,
)

0 comments on commit 56667a3

Please sign in to comment.