How to ignore module imports #263
-
currently generating for one module like this context = Context(directory=root_dir)
loader = PythonLoader(search_path=['gqlauth'], modules=['decorators'])
renderer = MarkdownRenderer(render_module_header=False,)
loader.init(context)
renderer.init(context)
header = """
# Decorates
---
"""
modules = loader.load()
with open(root_dir / 'docs' / 'decorators.md', 'w+') as f:
f.write(header + renderer.render_to_string(modules)) this is the result: I want only the functions or classes how do i remove the import statements? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
Hi @nrbnlulu have you found a solution? I have the same problem |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late reply. Since you're using the API directly rather than the command line, it appears you are missing what the filter that is usually applied by default. modules = loader.load()
processor = FilterProcessor()
processor.process(modules)
# ... The default configuration of the processor will remove API objects that have no docstrings and no child elements (so your class that has no docstring but has a method with a docstring will be kept). |
Beta Was this translation helpful? Give feedback.
-
FWIW, I tackled this by subclassing class MayimFilter(FilterProcessor):
def _match(self, obj: docspec.ApiObject) -> bool:
result = super()._match(obj)
if result:
result = self._additional(obj)
return result
def _additional(self, obj: docspec.ApiObject) -> bool:
if isinstance(obj, docspec.Indirection) and not obj.target.startswith(
"."
):
return False
elif isinstance(obj, docspec.Variable) and obj.name.isupper():
return False
elif obj.name.startswith("_") and obj.name not in WHITELIST:
return False
return True
...
MayimFilter(
documented_only=False,
do_not_filter_modules=False,
skip_empty_modules=True,
).process(modules, resolver) https://github.com/ahopkins/mayim/blob/main/build_api_docs.py#L207 |
Beta Was this translation helpful? Give feedback.
-
I am having the same issue, using the docusaurus renderer and the CLI... any idea how to fix this? EditI managed to solve by doing the same thing as @lucacorbucci |
Beta Was this translation helpful? Give feedback.
Sorry for the late reply.
Since you're using the API directly rather than the command line, it appears you are missing what the filter that is usually applied by default.
The default configuration of the processor will remove API objects that have no docstrings and no child elements (so your class that has no docstring but has a method with a docstring will be kept).