jorisvandenbossche commented on code in PR #35907:
URL: https://github.com/apache/arrow/pull/35907#discussion_r1219574207


##########
docs/source/conf.py:
##########
@@ -38,15 +38,63 @@
 from unittest import mock
 from docutils.parsers.rst import Directive, directives
 
-import pyarrow
-
-
 sys.path.extend([
     os.path.join(os.path.dirname(__file__),
                  '..', '../..')
 
 ])
 
+# -- Customization --------------------------------------------------------
+
+try:
+    import pyarrow
+    exclude_patterns = []
+
+    # Conditional API doc generation
+
+    # Sphinx has two features for conditional inclusion:
+    # - The "only" directive
+    #   
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#including-content-based-on-tags
+    # - The "ifconfig" extension
+    #   https://www.sphinx-doc.org/en/master/usage/extensions/ifconfig.html
+    #
+    # Both have issues, but "ifconfig" seems to work in this setting.
+
+    try:
+        import pyarrow.cuda
+        cuda_enabled = True
+    except ImportError:
+        cuda_enabled = False
+        # Mock pyarrow.cuda to avoid autodoc warnings.
+        # XXX I can't get autodoc_mock_imports to work, so mock manually 
instead
+        # 
(https://github.com/sphinx-doc/sphinx/issues/2174#issuecomment-453177550)
+        pyarrow.cuda = sys.modules['pyarrow.cuda'] = mock.Mock()
+
+    try:
+        import pyarrow.flight
+        flight_enabled = True
+    except ImportError:
+        flight_enabled = False
+        pyarrow.flight = sys.modules['pyarrow.flight'] = mock.Mock()
+
+    try:
+        import pyarrow.orc
+        orc_enabled = True
+    except ImportError:
+        orc_enabled = False
+        pyarrow.orc = sys.modules['pyarrow.orc'] = mock.Mock()
+
+    try:
+        import pyarrow.parquet.encryption
+        parquet_encryption_enabled = True
+    except ImportError:
+        parquet_encryption_enabled = False
+        pyarrow.parquet.encryption = sys.modules['pyarrow.parquet.encryption'] 
= mock.Mock()
+except:

Review Comment:
   That might be specific to you local install (it's still finding the editable 
dev version?), so best to also include ImportError (if you are in an env 
without any pyarrow installed, it should give an ImportError)



-- 
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