Is there a way to parse docstrings in Cython (.pyx) files ?
See original GitHub issueI have a Cython module that I can import this way : import cython_module
.
Its source code is in a cython_module.pyx file, at the same level of other .py files that already work well with mkdocstrings:
.
├── cython_module.pyx
├── predict.py
├── setup.py
└── etc
This cython module contains a class with a docstring:
cdef class Model:
"""
This is the lower-level class used for inference, it stores the model in an optimized way and features a predict method.
Attributes:
trees : The array of trees composing the model.
nb_trees : The number of trees in the model.
"""
cdef Tree* trees
cdef uint16_t nb_trees
When specifying a ::: cython_module
in one of the .md files, I get this warning: WARNING - mkdocstrings.handlers.python: Couldn't read source for 'cython_module': source code not available
, and in the generated doc, the only thing showed after “cython_module” is the class name (“Model”), but no docstring, nor attributes.
Is there a way to generate documentation from docstrings in Cython files/modules ?
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:17 (15 by maintainers)
Top Results From Across the Web
Is there a way to parse docstrings in Cython (.pyx) files ? #221
A typical workflow for building docs for a Cython project is to install it (e.g. pip install . ), then run the doc...
Read more >Cython: Autogen docs with either Sphinx or Doxygen *without ...
What you are asking for is not possible with Sphinx, which does not parse .py or .pyx files directly. Autodoc imports Python modules....
Read more >Source Files and Compilation - Cython's Documentation
There are two ways of compiling from the command line. The cython command takes a .py or .pyx file and compiles it into...
Read more >[Cython] code documentation tool
Hi Can anybody recommend a code documentation tool which works good with cython. I tried doxygen but I'm rather disappointed. I see the...
Read more >How to extract docstrings from Python files with ast
What is ast? ... To parse a statement with ast, we can pass the code as a string to the function ast.parse ....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks good to me. Works on the Cython projects I can’t share, as well as Numpy, Pandas, and more. Great work!
This is indeed what I want to do: compile the code into an AST to re-use the utilities I’ve written for visiting ASTs. But for this, I actually need the string representation of these actual Python objects 😄 Anyway, I think I’ll simply go with
annotation.__name__
for builtin types, andrepr(annotation)
for the rest, at least for now. Thanks for sharing ideas 🙂And yes, I just read all the discussions around PEP 563 and PEP 649. If PEP 563 is deprecated, we’ll have to deal with actual Python objects for annotations anyway 🙂 But it won’t impact plain-text modules since I can parse them and play with their AST. It only impacts compiled modules which can only be inspected, so we should be totally fine.