|
382 | 382 | napoleon_use_ivar = False
|
383 | 383 | napoleon_use_param = True
|
384 | 384 | napoleon_use_rtype = True
|
| 385 | + |
| 386 | + |
| 387 | +def adopt_members_reexported_from_private_modules(public_module: str): |
| 388 | + """Remaps the module items that come from internal modules. |
| 389 | +
|
| 390 | + A public module might be exporting items that are imported from private modules. |
| 391 | + This function changes the `__module__` of such items to the public module. |
| 392 | +
|
| 393 | + Example: |
| 394 | + `package/public.py`: |
| 395 | +
|
| 396 | + ``` |
| 397 | + from package._private import _PrivateClass as PublicClass |
| 398 | + __all__ = ["PublicClass"] |
| 399 | + ``` |
| 400 | +
|
| 401 | + Calling this function on the `package.public` module will change: |
| 402 | + ``` |
| 403 | + package._private._PrivateClass.__name__ = "PublicClass" |
| 404 | + package._private._PrivateClass.__module__ = "package.public" |
| 405 | + ``` |
| 406 | + """ |
| 407 | + for name, cls in public_module.__dict__.items(): |
| 408 | + if name in public_module.__all__: |
| 409 | + if "._" in cls.__module__: |
| 410 | + cls.__name__ = name |
| 411 | + cls.__module__ = public_module.__name__ |
| 412 | + |
| 413 | + |
| 414 | +def setup(*args, **kwargs): |
| 415 | + # 1. Giving pretty module names to the GA and preview classes |
| 416 | + # 2. Giving pretty class names to the preview classes |
| 417 | + # 3. Making Sphinx automodule render the class members instead of |
| 418 | + # dismissing the exported private classes as "Alias of". |
| 419 | + from vertexai import language_models |
| 420 | + from vertexai import vision_models |
| 421 | + from vertexai.preview import ( |
| 422 | + language_models as preview_language_models, |
| 423 | + ) |
| 424 | + from vertexai.preview import ( |
| 425 | + vision_models as preview_vision_models, |
| 426 | + ) |
| 427 | + |
| 428 | + # There are many possible ways to select which classes to fix. |
| 429 | + # We select the publicly exported members that have an internal module ("*._*"). |
| 430 | + |
| 431 | + # Setting the modules of the GA classes |
| 432 | + adopt_members_reexported_from_private_modules(language_models) |
| 433 | + adopt_members_reexported_from_private_modules(vision_models) |
| 434 | + |
| 435 | + # Setting the modules of the public preview classes |
| 436 | + # Selecting the members that still have an internal module after the GA fixes. |
| 437 | + adopt_members_reexported_from_private_modules(preview_language_models) |
| 438 | + adopt_members_reexported_from_private_modules(preview_vision_models) |
0 commit comments