kaxil commented on code in PR #73477:
URL: https://github.com/apache/airflow/pull/73477#discussion_r4069688993


##########
devel-common/src/sphinx_exts/airflow_intersphinx.py:
##########
@@ -22,12 +22,54 @@
 from typing import TYPE_CHECKING, Any
 
 from provider_yaml_utils import load_package_data
+from sphinx.util.inventory import InventoryFile
 
 if TYPE_CHECKING:
     from sphinx.application import Sphinx
 
 AIRFLOW_ROOT_PATH = Path(os.path.abspath(__file__)).parents[3]
 GENERATED_PATH = AIRFLOW_ROOT_PATH / "generated"
+INVENTORY_FILENAME = "objects.inv"
+
+
+def _inventory_for(package_name: str, versioned: bool) -> Path:
+    """
+    Prefer an inventory written earlier in this run, fall back to the one 
fetched from the published docs.
+
+    The html builder writes its inventory at the root of the build directory; 
a spelling-only build
+    writes one into its own output directory (see 
``_dump_inventory_after_spelling_build``, the
+    directory name mirrors ``AirflowDocsBuilder.log_spelling_output_dir``).
+    """
+    build_dir = GENERATED_PATH / "_build" / "docs" / package_name / ("stable" 
if versioned else "")
+    built_this_run = (
+        build_dir / INVENTORY_FILENAME,
+        build_dir / f"output-spelling-results-{package_name}" / 
INVENTORY_FILENAME,
+    )
+    downloaded = GENERATED_PATH / "_inventory_cache" / package_name / 
INVENTORY_FILENAME
+    return next((inventory for inventory in built_this_run if 
inventory.exists()), downloaded)
+
+
+class _HtmlTargetUris:
+    """Gives inventory entries the URIs the html build would, so the file is 
an ordinary inventory."""
+
+    @staticmethod
+    def get_target_uri(docname: str, typ: str | None = None) -> str:
+        return f"{docname}.html"
+
+
+def _dump_inventory_after_spelling_build(app: Sphinx, exception: Exception | 
None) -> None:
+    """
+    Write ``objects.inv`` after a successful spelling build.
+
+    Cross-references are resolved by every builder, so a ``--spellcheck-only`` 
run of package B fails

Review Comment:
   I expected the same and tested it before answering, and it does not break: 
the inventory is written even when A fails on spelling. Under `-W`, Sphinx 8.1 
(and 9.x, same code) does not abort on the first warning; it counts warnings 
and sets a non-zero exit status at the end of the build ("build finished with 
problems, N warnings (with warnings treated as errors)"), so `build-finished` 
still fires with `exception=None` after a complete build and the inventory is 
complete. Only a build that crashed part-way skips the dump.
   
   Same reproduction as above plus a misspelled sentence in the ftp docs:
   
   ```
   apache-airflow-providers-ftp   : Finished spell-checking with errors      <- 
the 3 misspelled words
   apache-airflow-providers-sftp  : Finished spell-checking with errors      <- 
undefined label, first pass
   Packages to rebuild: ['apache-airflow-providers-sftp']
   apache-airflow-providers-sftp  : Finished spell-checking successfully     <- 
loaded ftp's fresh inventory
   No packages to retry. No more passes are needed.
   ```
   
   and the final summary lists only the three misspellings in ftp, nothing 
about the label. The sftp log shows which file it loaded: 
`.../apache-airflow-providers-ftp/stable/output-spelling-results-apache-airflow-providers-ftp/objects.inv`.
 I added this to the hook's docstring so it does not look like an accident.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to