Submodules not showing up for (native) extension modules
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 146
- PR merge metrics
- No merged PRs in 30d
Description
When running pdoc on an extension modules (aka, a native "C" extensions), the extension module's submodules don't show up in the documentation even though <TAB>-autocomplete in a Python REPL can find the submodules. This seems to be because pdoc searches for submodules by inspecting the source directory, which isn't available for extension modules.
I've proposed PR #318 to fix this issue. The proposed solution works but I'm not sure if it is safe enough to remove the old "source directory traversal" method. I'd appreciate guidance on completing the PR.
Expected Behavior
Running pdoc on a native extension module should generate documentation for the entire extension module, including its submodules.
Actual Behavior
- With current master: only items in the top-level module appear in the documentation. Submodules don't show up in the documentation.
- With the proposed fix in #318: works as expected.
Steps to Reproduce
The following steps generate a minimalistic native extension module in Rust that exhibits the problem. The language shouldn't matter though.
- Install a rust toolchain, see https://rustup.rs
- Create the following directory structure:
pyext/
├── Cargo.toml
└── src/
└── lib.rs
with the following file contents:
Cargo.toml:
[package]
authors = ["Name <em@i.l>"]
edition = "2018"
name = "pyext"
version = "0.1.0"
[lib]
crate-type = ["cdylib"]
[dependencies]
pyo3 = {version = "0.13.2", features = ["extension-module"]}
src/lib.rs:
use pyo3::{prelude::*, wrap_pymodule};
/// Docstring of main module.
#[pymodule(pyext)]
fn init_main_module(_py: Python<'_>, module: &PyModule) -> PyResult<()> {
module.add_wrapped(wrap_pymodule!(submodule))?;
Ok(())
}
/// Docstring of submodule
#[pymodule(submodule)]
fn init_submodule(_py: Python<'_>, submodule: &PyModule) -> PyResult<()> {
submodule.add("variable", 42)?;
Ok(())
}
- Compile the extension module:
cargo build - Create a properly named symlink to the object file:
- on Linux:
ln -s target/debug/libpyext.so pyext.so - on Mac:
ln -s target/debug/libpyext.dylib pyext.so - on Windows: rename
target\debug\libpyext.dlltopyext.pyd
- on Linux:
- Start a Python REPL from the directory containing the
pyext.sofile and verify that the submodule exists and can be found by tab completion:
$ python
Python 3.6.10 (default, May 22 2020, 17:59:48)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyext
>>> pyext.<TAB> --> autocompletes to "pyext.submodule", proving that the submodule can be found
>>> pyext.submodule.variable
42
- Run
pdoc --html pyextfrom the same directory.- With the version at current master, the generated documentation leaves out the submodule.
- With the version proposed in #318, the generated documentation includes the submodule.
Additional info
- pdoc version: master and 0.9.2 don't work, the one from #318 works.
- tested on linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review PR #318 and the source-directory traversal used when pdoc --html pyext discovers modules; reproduce the behavior with the Rust/PyO3 extension described in the issue. Done means generated documentation includes the native extension's submodule, matching the result reported for PR #318.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100