Commit Graph

21 Commits

Author SHA1 Message Date
Omar Sandoval
c801e5e9b1 drgndoc: format __init__() signature separately from class
Having the signature in the class line is awkward, especially when
__init__() is overloaded. Instead, document __init__() separately, but
refer to it by the name of the class. There might still be a better way
to represent this, but this is at least better than before.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-12-14 12:29:17 -08:00
Omar Sandoval
d7c7094992 drgndoc: fix unnecessary parentheses around tuple subscripts on Python 3.9
Python 3.9 stopped emitting ast.Index nodes, which broke skipping
parentheses around tuples when they're used as subscripts (e.g., for
generic type annotations). Fix it by removing ast.Index nodes in the
pretransformation step on old versions and then handling the new layout
where the ast.Tuple node is directly in ast.Subscript.slice. While we're
here, make sure that we don't skip the parentheses for an empty tuple in
a subscript.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-12-14 12:29:17 -08:00
Omar Sandoval
36068a0ea8 Fix trailing commas for Black v20.8b1
Black was recently changed to treat a trailing comma as an indicator to
put each item/argument on its own line. We have a bunch of places where
something previously had to be split into multiple lines, then was
edited to fit on one line, but Black kept the trailing comma. Now this
update wants to unnecessarily split it back up. For now, let's get rid
of these commas. Hopefully in the future Black has a way to opt out of
this.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-27 11:31:29 -07:00
Omar Sandoval
b0f9403ebf drgndoc: directly use name passed as argument to drgndoc directive
E.g., drgndoc:: foo.bar() should emit py:method:: foo.bar() regardless
of a previous py:module directive.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-26 16:56:28 -07:00
Omar Sandoval
93e33513da drgndoc: bring back :exclude:
It's still useful to have an escape hatch for names we don't want
documented.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-26 16:36:55 -07:00
Omar Sandoval
4e770fb18a Format imports with isort
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-20 16:55:07 -07:00
Omar Sandoval
e4a2676cac drgndoc: support @typing.overload()
One of the blockers for adding type annotations to helpers is that some
helpers need to be overloaded, but drgndoc doesn't support that. This
adds support. Each function now tracks all of its overloaded signature,
each of which may be documented separately. The formatted output (for
functions/methods and classes with __init__()) combines all of the
documented overloads.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-20 11:21:29 -07:00
Omar Sandoval
64a04a6c4f drgndoc: include attributes based on presence of docstring
We can get rid of the :include: and :exclude: options by deciding solely
based on whether a node has a docstring. Empty docstrings can be used to
indicate nodes that should be included with no additional content. The
__init__() method must now also have a docstring in order to be
documented. Additionally, the directives are now fully formatted by the
Formatter rather than being split between the Formatter and
DrgnDocDirective.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-20 11:21:29 -07:00
Omar Sandoval
f41cc7fb48 drgndoc: recursively document names imported with alias
The helpers implemented in C have Python wrappers only for the purpose
of documentation. This is because drgndoc ignores all imports when
recursively documenting attributes. However, mypy uses the convention
that aliased imports (i.e., import ... as ... or from ... import ... as
...) are considered re-exported, so we can follow that convention and
include aliased imports. (mypy also considered attributes in __all__ as
re-exported, so we should probably follow that in the future, too, but
for now aliased imports are enough). This lets us get rid of the Python
wrappers.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-20 11:21:29 -07:00
Omar Sandoval
192d35c609 drgndoc: support relative imports
Mainly for completeness, as I don't really like using them in my own
projects.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-20 11:21:29 -07:00
Omar Sandoval
a270525f8b drgndoc: save all modules and classes traversed to resolve name
This will be used to support relative imports.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-20 11:21:29 -07:00
Omar Sandoval
4a3b8fb8e6 drgndoc: fix mypy --strict errors
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-20 11:21:29 -07:00
Omar Sandoval
2345325ac1 drgndoc: handle implicit classmethods
The __init_subclass__ and __class_getitem__ methods are always class
methods even if not decorated as such, so format them accordingly.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-11 23:18:42 -07:00
Omar Sandoval
b8aa2dcfc5 drgndoc: format None, True, and False as roles
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-11 22:51:56 -07:00
Omar Sandoval
8b264f8823 Update copyright headers to Facebook and add missing headers
drgn was originally my side project, but for awhile now it's also been
my work project. Update the copyright headers to reflect this, and add a
copyright header to various files that were missing it.
2020-05-15 15:13:02 -07:00
Omar Sandoval
02743b2da7 drgndoc: don't add :rtype: if function doesn't have docstring 2020-04-27 17:08:02 -07:00
Omar Sandoval
a070f1ca14 drgndoc: visit submodules in deterministic order
parse_package() visits submodules in whatever order they're returned by
the filesystem, which is arbitrary. Let's sort them so we always visit
them in the same order.
2020-04-21 10:44:52 -07:00
Omar Sandoval
8be7ae5299 drgndoc: handle forward references
String annotations (i.e., forward references) need to be parsed into an
ast node. Do it as a transformation step immediately after parsing the
source. We can also squash the constant node transformation into this
one.
2020-02-26 16:50:52 -08:00
Omar Sandoval
80c9fb35ff Add type hint stubs and generate documentation from them
I've been wanting to add type hints for the _drgn C extension for
awhile. The main blocker was that there is a large overlap between the
documentation (in docs/api_reference.rst) and the stub file, and I
really didn't want to duplicate the information. Therefore, it was a
requirement that the the documentation could be generated from the stub
file, or vice versa. Unfortunately, none of the existing tools that I
could find supported this very well. So, I bit the bullet and wrote my
own Sphinx extension that uses the stub file as the source of truth (and
subsumes my old autopackage extension and gen_docstrings script).

The stub file is probably incomplete/inaccurate in places, but this
should be a good starting point to improve on.

Closes #22.
2020-02-25 13:39:06 -08:00
Omar Sandoval
660276a0b8 Format Python code with Black
I'm not a fan of 100% of the Black coding style, but I've spent too much
time manually formatting Python code, so let's just pull the trigger.
2020-01-14 11:51:58 -08:00
Omar Sandoval
393a1f3149 Document with Sphinx
drgn has pretty thorough in-program documentation, but it doesn't have a
nice overview or introduction to the basic concepts. This commit adds
that using Sphinx. In order to avoid documenting everything in two
places, the libdrgn bindings have their docstrings generated from the
API documentation. The alternative would be to use Sphinx's autodoc
extension, but that's not as flexible and would also require building
the extension to build the docs. The documentation for the helpers is
generated using autodoc and a small custom extension.
2019-04-11 12:48:15 -07:00