Skip to content

Commit

Permalink
a mod's __file__ is None. (PaddlePaddle#4043)
Browse files Browse the repository at this point in the history
* a mod's __file__ is None.

```
Traceback (most recent call last):
  File "./gen_doc.py", line 1270, in <module>
    set_source_code_attrs()
  File "./gen_doc.py", line 180, in set_source_code_attrs
    parse_module_file(obj)
  File "./gen_doc.py", line 234, in parse_module_file
    if os.path.splitext(src_file)[1].lower() == '.py':
  File "/usr/lib/python3.8/posixpath.py", line 118, in splitext
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
```

* skip the mod when its __file__ is None

* if statement wrong

* hasattr raise an expection
  • Loading branch information
wadefelix authored Nov 5, 2021
1 parent 7f194c6 commit 39a5e76
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions docs/api/gen_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,23 @@ def process_module(m, attr="__all__"):
if inspect.isclass(api_info['object']):
for name, value in inspect.getmembers(api_info['object']):
if (not name.startswith("_")):
method_full_name = full_name + '.' + name # value.__name__
if name and value and isinstance(value, property):
method_api_info = insert_api_into_dict(
method_full_name, 'class_property')
if method_api_info is not None:
api_counter += 1
elif hasattr(value, '__name__'):
method_api_info = insert_api_into_dict(
method_full_name, 'class_method')
if method_api_info is not None:
api_counter += 1
try:
method_full_name = full_name + '.' + name # value.__name__
if name and value and isinstance(value,
property):
method_api_info = insert_api_into_dict(
method_full_name, 'class_property')
if method_api_info is not None:
api_counter += 1
elif hasattr(value, '__name__'):
method_api_info = insert_api_into_dict(
method_full_name, 'class_method')
if method_api_info is not None:
api_counter += 1
except ValueError as e:
logger.error(
'ValueError when processing %s: %s',
method_full_name, str(e))
return api_counter


Expand Down Expand Up @@ -226,9 +232,14 @@ def parse_module_file(mod):
if hasattr(mod, '__name__') and hasattr(mod, '__file__'):
src_file = mod.__file__
mod_name = mod.__name__
if not (isinstance(src_file, str) and isinstance(src_file, str)):
logger.error('%s: mod_name=%s, src_file=%s',
str(mod), mod_name, src_file)
return
logger.debug("parsing %s:%s", mod_name, src_file)
if len(mod_name) >= 6 and mod_name[:6] == 'paddle':
if os.path.splitext(src_file)[1].lower() == '.py':
fn_splited = os.path.splitext(src_file)
if len(fn_splited) > 1 and fn_splited[1].lower() == '.py':
mod_ast = ast.parse(open(src_file, "r").read())
for node in mod_ast.body:
short_names = []
Expand Down

0 comments on commit 39a5e76

Please sign in to comment.