Skip to content

Commit

Permalink
Optimum fixes (#149)
Browse files Browse the repository at this point in the history
* Find object in namespace packages

* Fixes that work

* Quality
  • Loading branch information
sgugger authored Mar 21, 2022
1 parent a1b0e76 commit 6f68918
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/doc_builder/autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.


import importlib
import inspect
import json
import re
Expand All @@ -34,8 +34,17 @@ def find_object_in_package(object_name, package):
if path_splits[0] == package.__name__:
path_splits = path_splits[1:]
module = package
for split in path_splits:
module = getattr(module, split, None)
for idx, split in enumerate(path_splits):
submodule = getattr(module, split, None)
# `split` could be the name of a package if `package` is a namespace package, in which case it doesn't appear
# as an attribute if the submodule was not imported before
if submodule is None and idx == 0:
try:
importlib.import_module(f"{package.__name__}.{split}")
submodule = getattr(module, split, None)
except ImportError:
pass
module = submodule
if module is None:
return
return module
Expand Down

0 comments on commit 6f68918

Please sign in to comment.