Skip to content

Commit 80a1050

Browse files
authored
fix docs hyperlinks (#133)
1 parent 68ac169 commit 80a1050

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ __pycache__/
77
/build/
88
/dist/
99
/docs/build/
10+
/docs/contributing.md
1011

1112
# Unit test / coverage reports
1213
/.coverage*

docs/pydoc-markdown.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ processors:
55
- type: filter
66
- type: pydoc_markdown_shtab.ShtabProcessor
77
- type: crossref
8+
hooks:
9+
pre-render:
10+
- sed 's#](./#](https://github.com/iterative/shtab/tree/main/#g' ../CONTRIBUTING.md > contributing.md
811
renderer:
912
type: mkdocs
1013
markdown:
@@ -37,7 +40,7 @@ renderer:
3740
href: https://github.com/iterative/shtab/issues?q=
3841
- title: Contributing
3942
name: contributing
40-
source: ../CONTRIBUTING.md
43+
source: contributing.md
4144
- title: Licence
4245
name: licence
4346
source: ../LICENCE

docs/pydoc_markdown_shtab.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ def _process(self, node):
88
if not getattr(node, "docstring", None):
99
return super()._process(node)
1010
# convert parameter lists to markdown list
11-
node.docstring.content = re.sub(
12-
r"^(\w+)\s{2,}(:.*?)$",
13-
r"* __\1__*\2* ",
14-
node.docstring.content,
15-
flags=re.M,
16-
)
11+
node.docstring.content = re.sub(r"^(\w+)(:.*?)$", r"* __\1__\2", node.docstring.content,
12+
flags=re.M)
13+
# fix code cross-references
14+
node.docstring.content = re.sub(r"<../(\S+)>",
15+
r"[\1](https://github.com/iterative/shtab/tree/main/\1)",
16+
node.docstring.content, flags=re.M)
1717
return super()._process(node)

shtab/__init__.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -755,14 +755,15 @@ def recurse_parser(cparser, positional_idx, requirements=None):
755755
def complete(parser: ArgumentParser, shell: str = "bash", root_prefix: Opt[str] = None,
756756
preamble: Union[str, Dict] = "", choice_functions: Opt[Any] = None) -> str:
757757
"""
758-
parser : argparse.ArgumentParser
759-
shell : str (bash/zsh)
760-
root_prefix : str or `None`
758+
shell:
759+
bash/zsh/tcsh
760+
root_prefix:
761761
prefix for shell functions to avoid clashes (default: "_{parser.prog}")
762-
preamble : dict or str
762+
preamble:
763763
mapping shell to text to prepend to generated script
764764
(e.g. `{"bash": "_myprog_custom_function(){ echo hello }"}`)
765-
choice_functions : deprecated
765+
choice_functions:
766+
*deprecated*
766767
767768
N.B. `parser.add_argument().complete = ...` can be used to define custom
768769
completions (e.g. filenames). See <../examples/pathcomplete.py>.
@@ -778,7 +779,7 @@ def complete(parser: ArgumentParser, shell: str = "bash", root_prefix: Opt[str]
778779
)
779780

780781

781-
def completion_action(parent=None, preamble=""):
782+
def completion_action(parent: Opt[ArgumentParser] = None, preamble: Union[str, Dict] = ""):
782783
class PrintCompletionAction(_ShtabPrintCompletionAction):
783784
def __call__(self, parser, namespace, values, option_string=None):
784785
print(complete(parent or parser, values, preamble=preamble))
@@ -788,19 +789,17 @@ def __call__(self, parser, namespace, values, option_string=None):
788789

789790

790791
def add_argument_to(
791-
parser,
792-
option_string="--print-completion",
793-
help="print shell completion script",
794-
parent=None,
795-
preamble="",
792+
parser: ArgumentParser,
793+
option_string: Union[str, List[str]] = "--print-completion",
794+
help: str = "print shell completion script",
795+
parent: Opt[ArgumentParser] = None,
796+
preamble: Union[str, Dict] = "",
796797
):
797798
"""
798-
parser : argparse.ArgumentParser
799-
option_string : str or list[str]
799+
option_string:
800800
iff positional (no `-` prefix) then `parser` is assumed to actually be
801801
a subparser (subcommand mode)
802-
help : str
803-
parent : argparse.ArgumentParser
802+
parent:
804803
required in subcommand mode
805804
"""
806805
if isinstance(option_string, str):

0 commit comments

Comments
 (0)