Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-35906: [Docs] Enable building the documentation without having pyarrow installed #35907

Merged
merged 6 commits into from
Jun 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 63 additions & 52 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
AlenkaF marked this conversation as resolved.
Show resolved Hide resolved
exclude_patterns = ['python']
cuda_enabled = False
flight_enabled = False

# Suppresses all warnings printed when sphinx is traversing the code (e.g.
# deprecation warnings)
warnings.filterwarnings("ignore", category=FutureWarning, message=".*pyarrow.*")
Expand Down Expand Up @@ -158,11 +206,18 @@
# built documents.
#
# The short X.Y version.
version = os.environ.get('ARROW_DOCS_VERSION',
pyarrow.__version__)
try:
version = os.environ.get('ARROW_DOCS_VERSION',
pyarrow.__version__)
AlenkaF marked this conversation as resolved.
Show resolved Hide resolved
except:
version = '0.0.0-local-docs-build'

# The full version, including alpha/beta/rc tags.
release = os.environ.get('ARROW_DOCS_VERSION',
pyarrow.__version__)
try:
release = os.environ.get('ARROW_DOCS_VERSION',
pyarrow.__version__)
except:
release = '0.0.0-local-docs-build'

if "+" in release:
release = release.split(".dev")[0] + " (dev)"
Expand All @@ -186,7 +241,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = exclude_patterns + ['_build', 'Thumbs.db', '.DS_Store']

# The reST default role (used for this markup: `text`) to use for all
# documents.
Expand Down Expand Up @@ -474,50 +529,6 @@
# texinfo_no_detailmenu = False


# -- Customization --------------------------------------------------------

# 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()


def setup(app):
# Use a config value to indicate whether CUDA API docs can be generated.
# This will also rebuild appropriately when the value changes.
Expand Down
Loading