Converts the RefenceResolver to json and writes it to the specified file. Args: filepath: The file path to write the json to.
(self, filepath)
| 233 | return cls(doc_index=doc_index, **json_dict) |
| 234 | |
| 235 | def to_json_file(self, filepath): |
| 236 | """Converts the RefenceResolver to json and writes it to the specified file. |
| 237 | |
| 238 | Args: |
| 239 | filepath: The file path to write the json to. |
| 240 | """ |
| 241 | try: |
| 242 | os.makedirs(os.path.dirname(filepath)) |
| 243 | except OSError: |
| 244 | pass |
| 245 | json_dict = {} |
| 246 | for key, value in self.__dict__.items(): |
| 247 | # Drop these two fields. `_doc_index` is not serializable. `_all_names` is |
| 248 | # generated by the constructor. |
| 249 | if key in ('_doc_index', '_all_names', |
| 250 | '_errors', 'current_doc_full_name'): |
| 251 | continue |
| 252 | |
| 253 | # Strip off any leading underscores on field names as these are not |
| 254 | # recognized by the constructor. |
| 255 | json_dict[key.lstrip('_')] = value |
| 256 | |
| 257 | with open(filepath, 'w') as f: |
| 258 | json.dump(json_dict, f, indent=2, sort_keys=True) |
| 259 | |
| 260 | def replace_references(self, string, relative_path_to_root): |
| 261 | """Replace "@{symbol}" references with links to symbol's documentation page. |