diff --git a/doc/source/conf.py b/doc/source/conf.py index a2fa7fe9b..b07f3da63 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -99,58 +99,8 @@ sys.modules["tensorflow"].VERSION = "9.9.9" sys.modules["tensorflow.keras.callbacks"] = ChildClassMock() sys.modules["pytorch_lightning"] = ChildClassMock() - -def import_or_mock(module): - try: - # Same as `import module` - __import__(module, globals(), locals(), [], 0) - except ImportError: - sys.modules[module] = ChildClassMock() - - -xgb_lgbm_modules = [ - "xgboost", "xgboost.core", "xgboost.callback", "xgboost.sklearn", - "xgboost_ray", "lightgbm.main", "lightgbm.callback", "lightgbm.compat", - "lightgbm_ray" -] -for module in xgb_lgbm_modules: - import_or_mock(module) - -# replace docstring refs in XGBoost documentation XGBoost-Ray inherits from -# if this is not done, an error during make will be thrown, as there is no -# such ref in ray docs -replaces_callback_api = [ - sys.modules["xgboost_ray"].RayXGBClassifier.fit, - sys.modules["xgboost_ray"].RayXGBRegressor.fit -] -for m in replaces_callback_api: - m.__doc__ = m.__doc__.replace(":ref:`callback_api`", "Callback API") - -# fix "more than one target found for cross-reference 'RayParams'" -# as both lightgbm-ray and xgboost-ray have classes with the same -# names, we need to refer to the explicitly in ray docs, otherwise -# make will throw an error -replaces_ray_params = [ - sys.modules["xgboost_ray"].train, sys.modules["xgboost_ray"].predict, - sys.modules["xgboost_ray"].RayXGBClassifier.fit, - sys.modules["xgboost_ray"].RayXGBClassifier.predict, - sys.modules["xgboost_ray"].RayXGBClassifier.predict_proba, - sys.modules["xgboost_ray"].RayXGBRegressor.fit, - sys.modules["xgboost_ray"].RayXGBRegressor.predict -] -for m in replaces_ray_params: - m.__doc__ = m.__doc__.replace("RayParams", "xgboost_ray.RayParams") - -replaces_ray_params = [ - sys.modules["lightgbm_ray"].train, sys.modules["lightgbm_ray"].predict, - sys.modules["lightgbm_ray"].RayLGBMClassifier.fit, - sys.modules["lightgbm_ray"].RayLGBMClassifier.predict, - sys.modules["lightgbm_ray"].RayLGBMClassifier.predict_proba, - sys.modules["lightgbm_ray"].RayLGBMRegressor.fit, - sys.modules["lightgbm_ray"].RayLGBMRegressor.predict -] -for m in replaces_ray_params: - m.__doc__ = m.__doc__.replace("RayParams", "lightgbm_ray.RayParams") +assert "ray" not in sys.modules, ( + "If ray is already imported, we will not render documentation correctly!") class SimpleClass(object): diff --git a/doc/source/lightgbm-ray.rst b/doc/source/lightgbm-ray.rst index 3c606a386..d7fb6c022 100644 --- a/doc/source/lightgbm-ray.rst +++ b/doc/source/lightgbm-ray.rst @@ -531,8 +531,8 @@ the `examples folder