Skip to content

Commit

Permalink
Doc: Allow building documentation even without a compiled extension
Browse files Browse the repository at this point in the history
This involves a fake _ldap module and carefully bootstrapping
ldap.__init__ (which imports * from _ldap).
  • Loading branch information
Petr Viktorin committed Nov 27, 2017
1 parent 1bb84f6 commit e34bd6b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@
# serve to show the default value.

import sys
import os

# If your extensions are in another directory, add it here.
#sys.path.append('some/directory')
_doc_dir = os.path.dirname(__file__)
sys.path.append(_doc_dir)
sys.path.append(os.path.join(_doc_dir, '../Lib/'))
sys.path.insert(0, os.path.join(_doc_dir, '../Lib/ldap'))

# Import fake `_ldap` module
import fake_ldap_module_for_documentation

# General configuration
# ---------------------
Expand Down
30 changes: 30 additions & 0 deletions Doc/fake_ldap_module_for_documentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
A module that mocks `_ldap` for the purposes of generating documentation
This module provides placeholders for the contents of `_ldap`, making it
possible to generate documentation even _ldap is not compiled.
It should also make the documentation independent of which features are
available in the system OpenLDAP library.
The overly long module name will show up in AttributeError messages,
hinting that this is not the actual _ldap.
See https://www.python-ldap.org/ for details.
"""

import sys

# Cause `import _ldap` to import this module instead of the actual `_ldap`.
sys.modules['_ldap'] = sys.modules[__name__]

from constants import CONSTANTS
from pkginfo import __version__

for constant in CONSTANTS:
globals()[constant.name] = constant

def get_option(num):
pass

class LDAPError:
pass
3 changes: 3 additions & 0 deletions Lib/ldap/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"""

# This module cannot import anything from ldap.
# When building documentation, it is used to initialize ldap.__init__.

from __future__ import print_function

class Constant(object):
Expand Down

0 comments on commit e34bd6b

Please sign in to comment.