Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling static methods as :func: targets #112

Open
dwysocki opened this issue Jun 21, 2019 · 0 comments
Open

Handling static methods as :func: targets #112

dwysocki opened this issue Jun 21, 2019 · 0 comments

Comments

@dwysocki
Copy link

I have a project with a number of command line tools implemented as static methods and class methods. It seems, however, not possible to tell sphinx-argparse how to access these parsers.

Simplified example:

If we have a module cli.py

import argparse

class Foo(object):
    @staticmethod
    def make_parser():
        parser = argparse.ArgumentParser()
        parser.add_argument("test")
        return parser

    @classmethod
    def main(cls):
        parser = cls.make_parser()
        args = parser.parse_args()
        print(args.test)

None of the ways I think could generate documentation for this seem to work.

One way:

Test Command
============

.. argparse::
    :module: cli
    :func: Foo.make_parser
    :prog: command_name

produces the error:

/path/to/file.rst:4: WARNING: Module "cli" has no attribute "Foo.make_parser"
Incorrect argparse :module: or :func: values?

Another way:

Test Command
============

.. argparse::
    :ref: cli.Foo.make_parser
    :prog: command_name

produces the error

/path/to/file.rst:4: WARNING: Failed to import "make_parser" from "cli.Foo".
No module named 'cli.foo'; 'cli' is not a package

Would it be possible to make this work somehow? Perhaps an additional directive is needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant