Skip to content

Commit d8d3094

Browse files
committed
Added feature for user override of url line anchor notation (#74)
1 parent 6ce29fa commit d8d3094

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ lazydocs [OPTIONS] PATHS...
171171

172172
* `--output-path TEXT`: The output path for the creation of the markdown files. Set this to `stdout` to print all markdown to stdout. [default: ./docs/]
173173
* `--src-base-url TEXT`: The base repo link used as prefix for all source links. Should also include the branch name.
174+
* `--url-line-prefix TEXT`: Line prefix for git repository line url anchors #{prefix}line. If None provided, defaults to Github style notation.
174175
* `--overview-file TEXT`: Filename of overview file. If not provided, no API overview file will be generated.
175176
* `--remove-package-prefix / --no-remove-package-prefix`: If `True`, the package prefix will be removed from all functions and methods. [default: True]
176177
* `--ignored-modules TEXT`: A list of modules that should be ignored. [default: ]

src/lazydocs/_cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def generate(
5454
False,
5555
help="Include table of contents in module file. Defaults to False.",
5656
),
57+
url_line_prefix: Optional[str] = typer.Option(
58+
None,
59+
help="Line prefix for git repository line url anchors #{prefix}line. If none provided, defaults to Github style notation.",
60+
),
5761
) -> None:
5862
"""Generates markdown documentation for your Python project based on Google-style docstrings."""
5963

@@ -70,6 +74,7 @@ def generate(
7074
validate=validate,
7175
private_modules=private_modules,
7276
include_toc=toc,
77+
url_line_prefix=url_line_prefix,
7378
)
7479
except Exception as ex:
7580
typer.echo(str(ex))

src/lazydocs/generation.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ def __init__(
624624
src_root_path: Optional[str] = None,
625625
src_base_url: Optional[str] = None,
626626
remove_package_prefix: bool = False,
627+
url_line_prefix: Optional[str] = None,
627628
):
628629
"""Initializes the markdown API generator.
629630
@@ -632,10 +633,12 @@ def __init__(
632633
src_base_url: The base github link. Should include branch name.
633634
All source links are generated with this prefix.
634635
remove_package_prefix: If `True`, the package prefix will be removed from all functions and methods.
636+
url_line_prefix: Line prefix for git repository line url anchors. Default: None - github "L".
635637
"""
636638
self.src_root_path = src_root_path
637639
self.src_base_url = src_base_url
638640
self.remove_package_prefix = remove_package_prefix
641+
self.url_line_prefix = url_line_prefix
639642

640643
self.generated_objects: List[Dict] = []
641644

@@ -677,7 +680,13 @@ def _get_src_path(self, obj: Any, append_base: bool = True) -> str:
677680
relative_path = os.path.relpath(path, src_root_path)
678681

679682
lineno = _get_line_no(obj)
680-
lineno_hashtag = "" if lineno is None else "#L{}".format(lineno)
683+
if self.url_line_prefix is None:
684+
lineno_hashtag = "" if lineno is None else "#L{}".format(lineno)
685+
else:
686+
lineno_hashtag = "" if lineno is None else "#{}{}".format(
687+
self.url_line_prefix,
688+
lineno
689+
)
681690

682691
# add line hash
683692
relative_path = relative_path + lineno_hashtag
@@ -1118,6 +1127,7 @@ def generate_docs(
11181127
validate: bool = False,
11191128
private_modules: bool = False,
11201129
include_toc: bool = False,
1130+
url_line_prefix: Optional[str] = None,
11211131
) -> None:
11221132
"""Generates markdown documentation for provided paths based on Google-style docstrings.
11231133
@@ -1133,6 +1143,7 @@ def generate_docs(
11331143
watermark: If `True`, add a watermark with a timestamp to bottom of the markdown files.
11341144
validate: If `True`, validate the docstrings via pydocstyle. Requires pydocstyle to be installed.
11351145
private_modules: If `True`, includes modules with `_` prefix.
1146+
url_line_prefix: Line prefix for git repository line url anchors. Default: None - github "L".
11361147
"""
11371148
stdout_mode = output_path.lower() == "stdout"
11381149

@@ -1173,6 +1184,7 @@ def generate_docs(
11731184
src_root_path=src_root_path,
11741185
src_base_url=src_base_url,
11751186
remove_package_prefix=remove_package_prefix,
1187+
url_line_prefix=url_line_prefix,
11761188
)
11771189

11781190
pydocstyle_cmd = "pydocstyle --convention=google --add-ignore=D100,D101,D102,D103,D104,D105,D107,D202"

0 commit comments

Comments
 (0)