anntzer / defopt

Effortless argument parser
https://pypi.org/project/defopt/
MIT License
214 stars 11 forks source link

NotImplementedError: <class 'defopt._parse_docstring.<locals>.Visitor'> visiting unknown node type: definition_list #122

Open nh13 opened 1 year ago

nh13 commented 1 year ago

defopt 6.4.0

import defopt

def main(*, arg: int) -> None:
    """Short tool description

    longer description

    Args:
        arg: description

    Output Format 1:
        - detail 1
        - detail 2:
            - sub-detail 2.2
        - detail 3
    """
    pass

if __name__ == '__main__':
    defopt.run(main)
anntzer commented 1 year ago

I don't mind adding support for definition_lists (or rather taking a PR that does so), but I suspect what you really want to write here is

import defopt

def main(*, arg: int) -> None:
    """Short tool description

    longer description

    Args:
        arg: description

    Output Format 2:

    - detail 1

    - detail 2

        - sub-detail 2.2

    - detail 3
    """
    pass

if __name__ == '__main__':
    defopt.run(main)

which I agree is a lot of whitespace, but that's rst's syntax (AFAICT) and I'm not going to change that here.

Now the above form does run into the error you reported at #123 and https://github.com/anntzer/defopt/issues/123#issuecomment-1579273595 does help, but the output's whitespace is pretty messed up so I'd much prefer a solution that yields better whitespace.

nh13 commented 1 year ago

@anntzer I'll add it my list to make a PR for definition_list. Perhaps we can add to the docs that the description should be in RST. Are there other formats (e.g. github-flavored markdown, others)?

anntzer commented 1 year ago

Oops, I realize the requirement for rst is not documented anywhere, indeed (I guess this is implied by the statement "Docstrings can use the standard Sphinx-style ... or Google- and Numpy-style docstrings (see examples/styles.py), which are converted using Napoleon [1]." at the top of features.rst). I added that information explicitly to the docstring of run().

Adding support for markdown likely means plugging something like myst-parser (as I'll likely not want to get away from using docutils as core), which may require some work.