| 68 | |
| 69 | |
| 70 | def serve_html_docs( |
| 71 | open_browser=False, # type: bool |
| 72 | config=HtmlDocsConfig(), # type: HtmlDocsConfig |
| 73 | ): |
| 74 | # type: (...) -> Union[LaunchResult, Error] |
| 75 | html_docs = docs.root(doc_type="html") |
| 76 | if not html_docs: |
| 77 | return Error( |
| 78 | dedent( |
| 79 | """\ |
| 80 | This Pex distribution does not include embedded docs. |
| 81 | |
| 82 | You can find the latest docs here: |
| 83 | HTML: https://docs.pex-tool.org |
| 84 | PDF: https://github.com/pex-tool/pex/releases/latest/download/pex.pdf |
| 85 | """ |
| 86 | ).rstrip() |
| 87 | ) |
| 88 | |
| 89 | try: |
| 90 | result = server.launch(html_docs, port=STANDARD_PORT) |
| 91 | except LaunchError: |
| 92 | try: |
| 93 | result = server.launch(html_docs, port=0) |
| 94 | except LaunchError as e: |
| 95 | with open(e.log) as fp: |
| 96 | for line in fp: |
| 97 | logger.log(logging.ERROR, line.rstrip()) |
| 98 | return Error("Failed to launch {server}.".format(server=server.name)) |
| 99 | |
| 100 | if open_browser: |
| 101 | try_(try_open(result.server_info.url, open_program=config.browser, suppress_stderr=True)) |
| 102 | |
| 103 | return result |