1# Copyright 2020 The OpenFermion Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""Tool to generate external api_docs for OF (Shameless copy from TFQ).""" 16 17import os 18 19from absl import app 20from absl import flags 21from tensorflow_docs.api_generator import doc_controls 22from tensorflow_docs.api_generator import generate_lib 23from tensorflow_docs.api_generator import public_api 24 25import openfermion 26 27flags.DEFINE_string("output_dir", "/tmp/openfermion_api", 28 "Where to output the docs") 29 30flags.DEFINE_string("code_url_prefix", 31 ("https://github.com/quantumlib/OpenFermion/tree/master/src" 32 "openfermion"), "The url prefix for links to code.") 33 34flags.DEFINE_bool("search_hints", True, 35 "Include metadata search hints in the generated files") 36 37flags.DEFINE_string("site_path", "quark/openfermion/api_docs/python", 38 "Path prefix in the _toc.yaml") 39 40FLAGS = flags.FLAGS 41 42 43def main(unused_argv): 44 45 doc_generator = generate_lib.DocGenerator( 46 root_title="OpenFermion", 47 py_modules=[("openfermion", openfermion)], 48 base_dir=os.path.dirname(openfermion.__file__), 49 code_url_prefix=FLAGS.code_url_prefix, 50 search_hints=FLAGS.search_hints, 51 site_path=FLAGS.site_path, 52 callbacks=[public_api.local_definitions_filter], 53 private_map={ 54 # Module paths to skip when crawling source code. 55 # Example: 56 # "cirq.google.engine.client.quantum.QuantumEngineServiceClient": 57 # ["enums"] 58 }) 59 60 doc_generator.build(output_dir=FLAGS.output_dir) 61 62 63if __name__ == "__main__": 64 app.run(main) 65