From 2e21ecc3b8ad29307a5962e2c8f3dea4926ebee9 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Fri, 1 Jul 2022 11:35:08 +0200 Subject: [PATCH] Fix docs (#81) --- docs/conf.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/conf.py b/docs/conf.py index 8a3c94a..62154b7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,8 @@ import sys +from abc import ABC from datetime import datetime from pathlib import Path +from unittest.mock import MagicMock, patch try: @@ -9,8 +11,33 @@ from importlib_metadata import metadata +def mock_rpy2(): + # Can’t use autodoc_mock_imports as we import anndata2ri + patch('rpy2.situation.get_r_home', lambda: None).start() + sys.modules['rpy2.rinterface_lib'] = MagicMock() + submods = ['embedded', 'conversion', 'memorymanagement', 'sexp', 'bufferprotocol', 'callbacks', '_rinterface_capi'] + sys.modules.update({f'rpy2.rinterface_lib.{sub}': MagicMock() for sub in submods}) + sexp = sys.modules['rpy2.rinterface_lib'].sexp = sys.modules['rpy2.rinterface_lib.sexp'] + sexp.Sexp = type('Sexp', (MagicMock, ABC), dict(__module__='rpy2.rinterface_lib.sexp')) + sexp.SexpEnvironment = type('SexpEnvironment', (sexp.Sexp,), dict(__module__='rpy2.rinterface_lib.sexp')) + sexp.SexpVector = sexp.StrSexpVector = MagicMock + sexp.SexpVector.from_iterable = MagicMock() + + import rpy2.rinterface + import rpy2.rinterface_lib.sexp + + rpy2.rinterface_lib = sys.modules['rpy2.rinterface_lib'] + rpy2.rinterface._MissingArgType = object + rpy2.rinterface.initr_simple = lambda *_, **__: None + + assert rpy2.rinterface_lib.sexp is sexp + + HERE = Path(__file__).parent +mock_rpy2() + +# now we can anndata2ri and our extensions sys.path[:0] = [str(HERE.parent), str(HERE / 'ext')]