Skip to content

Commit 7a55a96

Browse files
committed
add .pre-commit-config.yaml and docs/conf.py to owlbot excludes
1 parent a7aff2c commit 7a55a96

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ repos:
2626
hooks:
2727
- id: black
2828
- repo: https://github.com/pycqa/flake8
29-
rev: 3.9.2
29+
rev: 6.1.0
3030
hooks:
3131
- id: flake8

docs/conf.py

+54
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,57 @@
382382
napoleon_use_ivar = False
383383
napoleon_use_param = True
384384
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)

owlbot.py

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
".kokoro/samples",
8383
"noxfile.py",
8484
"testing",
85+
".pre-commit-config.yaml",
86+
"docs/conf.py",
8587
],
8688
)
8789
has_generator_updates = True

0 commit comments

Comments
 (0)