Skip to content

Commit 5e938e5

Browse files
committed
Support including private modules with, aka files with "_" prefix.
Add private_modules arg
1 parent 502e069 commit 5e938e5

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ lazydocs [OPTIONS] PATHS...
177177
* `--watermark / --no-watermark`: If `True`, add a watermark with a timestamp to bottom of the markdown files. [default: True]
178178
* `--validate / --no-validate`: If `True`, validate the docstrings via pydocstyle. Requires pydocstyle to be installed. [default: False]
179179
* `--output-format TEXT`: The output format for the creation of the markdown files. This may be 'md' or 'mdx'. Defaults to md.
180+
* `--private-modules / --no-private-modules`: If `True`, includes modules with "_" prefix. [default: False]
180181
* `--install-completion`: Install completion for the current shell.
181182
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
182183
* `--help`: Show this message and exit.

src/lazydocs/_cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ def generate(
4545
output_format: Optional[str] = typer.Option(
4646
None,
4747
help="The output format for the creation of the markdown files. This may be 'md' or 'mdx'. Defaults to md.",
48-
)
49-
48+
),
49+
private_modules: bool = typer.Option(
50+
False,
51+
help="If `True`, all packages starting with `_` will be included.",
52+
),
5053
) -> None:
5154
"""Generates markdown documentation for your Python project based on Google-style docstrings."""
5255

@@ -61,6 +64,7 @@ def generate(
6164
overview_file=overview_file,
6265
watermark=watermark,
6366
validate=validate,
67+
private_modules=private_modules,
6468
)
6569
except Exception as ex:
6670
typer.echo(str(ex))

src/lazydocs/generation.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ def _is_object_ignored(obj: Any) -> bool:
313313
return False
314314

315315

316-
def _is_module_ignored(module_name: str, ignored_modules: List[str]) -> bool:
316+
def _is_module_ignored(module_name: str, ignored_modules: List[str], private_modules: bool = False) -> bool:
317317
"""Checks if a given module is ignored."""
318-
if module_name.split(".")[-1].startswith("_"):
318+
if module_name.split(".")[-1].startswith("_") and module_name[1] != "_" and not private_modules:
319319
return True
320320

321321
for ignored_module in ignored_modules:
@@ -1084,6 +1084,7 @@ def generate_docs(
10841084
overview_file: Optional[str] = None,
10851085
watermark: bool = True,
10861086
validate: bool = False,
1087+
private_modules: bool = False,
10871088
) -> None:
10881089
"""Generates markdown documentation for provided paths based on Google-style docstrings.
10891090
@@ -1098,6 +1099,7 @@ def generate_docs(
10981099
overview_file: Filename of overview file. If not provided, no overview file will be generated.
10991100
watermark: If `True`, add a watermark with a timestamp to bottom of the markdown files.
11001101
validate: If `True`, validate the docstrings via pydocstyle. Requires pydocstyle to be installed.
1102+
private_modules: If `True`, includes modules with `_` prefix.
11011103
"""
11021104
stdout_mode = output_path.lower() == "stdout"
11031105

@@ -1152,11 +1154,10 @@ def generate_docs(
11521154

11531155
# Generate one file for every discovered module
11541156
for loader, module_name, _ in pkgutil.walk_packages([path]):
1155-
if _is_module_ignored(module_name, ignored_modules):
1157+
if _is_module_ignored(module_name, ignored_modules, private_modules):
11561158
# Add module to ignore list, so submodule will also be ignored
11571159
ignored_modules.append(module_name)
11581160
continue
1159-
11601161
try:
11611162
try:
11621163
mod_spec = importlib.util.spec_from_loader(module_name, loader)
@@ -1236,7 +1237,7 @@ def generate_docs(
12361237
path=obj.__path__, # type: ignore
12371238
prefix=obj.__name__ + ".", # type: ignore
12381239
):
1239-
if _is_module_ignored(module_name, ignored_modules):
1240+
if _is_module_ignored(module_name, ignored_modules, private_modules):
12401241
# Add module to ignore list, so submodule will also be ignored
12411242
ignored_modules.append(module_name)
12421243
continue

0 commit comments

Comments
 (0)