38
38
from googleapiclient .http import build_http
39
39
40
40
DISCOVERY_DOC_DIR = (
41
- pathlib .Path (__file__ ).parent . resolve ()
41
+ pathlib .Path (__file__ ).resolve (). parent
42
42
/ "googleapiclient"
43
43
/ "discovery_cache"
44
44
/ "documents"
134
134
<code><a href="#$name">$name($params)</a></code></p>
135
135
<p class="firstline">$firstline</p>"""
136
136
137
- BASE = pathlib .Path (__file__ ).parent . resolve () / "docs" / "dyn"
137
+ BASE = pathlib .Path (__file__ ).resolve (). parent / "docs" / "dyn"
138
138
139
139
DIRECTORY_URI = "https://www.googleapis.com/discovery/v1/apis"
140
140
@@ -356,7 +356,12 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS):
356
356
357
357
358
358
def document_collection_recursive (
359
- resource , path , root_discovery , discovery , doc_destination_dir
359
+ resource ,
360
+ path ,
361
+ root_discovery ,
362
+ discovery ,
363
+ doc_destination_dir ,
364
+ artifact_destination_dir = DISCOVERY_DOC_DIR ,
360
365
):
361
366
html = document_collection (resource , path , root_discovery , discovery )
362
367
@@ -380,10 +385,13 @@ def document_collection_recursive(
380
385
root_discovery ,
381
386
discovery ["resources" ].get (dname , {}),
382
387
doc_destination_dir ,
388
+ artifact_destination_dir ,
383
389
)
384
390
385
391
386
- def document_api (name , version , uri , doc_destination_dir ):
392
+ def document_api (
393
+ name , version , uri , doc_destination_dir , artifact_destination_dir = DISCOVERY_DOC_DIR
394
+ ):
387
395
"""Document the given API.
388
396
389
397
Args:
@@ -392,6 +400,8 @@ def document_api(name, version, uri, doc_destination_dir):
392
400
uri (str): URI of the API's discovery document
393
401
doc_destination_dir (str): relative path where the reference
394
402
documentation should be saved.
403
+ artifact_destination_dir (str): relative path where the discovery
404
+ artifacts should be saved.
395
405
"""
396
406
http = build_http ()
397
407
resp , content = http .request (
@@ -405,7 +415,7 @@ def document_api(name, version, uri, doc_destination_dir):
405
415
discovery = json .loads (content )
406
416
service = build_from_document (discovery )
407
417
doc_name = "{}.{}.json" .format (name , version )
408
- discovery_file_path = DISCOVERY_DOC_DIR / doc_name
418
+ discovery_file_path = artifact_destination_dir / doc_name
409
419
revision = None
410
420
411
421
pathlib .Path (discovery_file_path ).touch (exist_ok = True )
@@ -445,16 +455,21 @@ def document_api(name, version, uri, doc_destination_dir):
445
455
discovery ,
446
456
discovery ,
447
457
doc_destination_dir ,
458
+ artifact_destination_dir ,
448
459
)
449
460
450
461
451
- def document_api_from_discovery_document (discovery_url , doc_destination_dir ):
462
+ def document_api_from_discovery_document (
463
+ discovery_url , doc_destination_dir , artifact_destination_dir = DISCOVERY_DOC_DIR
464
+ ):
452
465
"""Document the given API.
453
466
454
467
Args:
455
468
discovery_url (str): URI of discovery document.
456
469
doc_destination_dir (str): relative path where the reference
457
470
documentation should be saved.
471
+ artifact_destination_dir (str): relative path where the discovery
472
+ artifacts should be saved.
458
473
"""
459
474
http = build_http ()
460
475
response , content = http .request (discovery_url )
@@ -471,16 +486,23 @@ def document_api_from_discovery_document(discovery_url, doc_destination_dir):
471
486
discovery ,
472
487
discovery ,
473
488
doc_destination_dir ,
489
+ artifact_destination_dir ,
474
490
)
475
491
476
492
477
- def generate_all_api_documents (directory_uri = DIRECTORY_URI , doc_destination_dir = BASE ):
493
+ def generate_all_api_documents (
494
+ directory_uri = DIRECTORY_URI ,
495
+ doc_destination_dir = BASE ,
496
+ artifact_destination_dir = DISCOVERY_DOC_DIR ,
497
+ ):
478
498
"""Retrieve discovery artifacts and fetch reference documentations
479
499
for all apis listed in the public discovery directory.
480
500
args:
481
501
directory_uri (str): uri of the public discovery directory.
482
502
doc_destination_dir (str): relative path where the reference
483
503
documentation should be saved.
504
+ artifact_destination_dir (str): relative path where the discovery
505
+ artifacts should be saved.
484
506
"""
485
507
api_directory = collections .defaultdict (list )
486
508
http = build_http ()
@@ -493,6 +515,7 @@ def generate_all_api_documents(directory_uri=DIRECTORY_URI, doc_destination_dir=
493
515
api ["version" ],
494
516
api ["discoveryRestUrl" ],
495
517
doc_destination_dir ,
518
+ artifact_destination_dir ,
496
519
)
497
520
api_directory [api ["name" ]].append (api ["version" ])
498
521
@@ -513,7 +536,7 @@ def generate_all_api_documents(directory_uri=DIRECTORY_URI, doc_destination_dir=
513
536
)
514
537
markdown .append ("\n " )
515
538
516
- with open (BASE / "index.md" , "w" ) as f :
539
+ with open (doc_destination_dir / "index.md" , "w" ) as f :
517
540
markdown = "\n " .join (markdown )
518
541
f .write (markdown )
519
542
@@ -525,9 +548,11 @@ def generate_all_api_documents(directory_uri=DIRECTORY_URI, doc_destination_dir=
525
548
FLAGS = parser .parse_args (sys .argv [1 :])
526
549
if FLAGS .discovery_uri :
527
550
document_api_from_discovery_document (
528
- discovery_url = FLAGS .discovery_uri , doc_destination_dir = FLAGS .dest
551
+ discovery_url = FLAGS .discovery_uri ,
552
+ doc_destination_dir = FLAGS .dest ,
529
553
)
530
554
else :
531
555
generate_all_api_documents (
532
- directory_uri = FLAGS .directory_uri , doc_destination_dir = FLAGS .dest
556
+ directory_uri = FLAGS .directory_uri ,
557
+ doc_destination_dir = FLAGS .dest ,
533
558
)
0 commit comments