sphinx-doc / sphinx-doc/sphinx
deepcopy fails to copy custom node attributes from document tree in nodes.py:inline_all_toctrees
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
I've been working on an extension to add an rst directive that lets me specify a path to a csv file and a caption, then generates an HTML or LaTeX table from that directive.
when the visit_csv_table_node_html method is called (for HTML/EPUB), I am able to access all of the attributes I added to CSVTableNode. The generated HTML looks correct in both output formats.
when the visit_csv_table_node_latex method is called, an AttributeError is raised when I try to access node.data_path.
I traced this down with the debugger to the inline_all_toctrees routine in sphinx/util/nodes.py where the doctree is going through a deepcopy (https://github.com/sphinx-doc/sphinx/blob/master/sphinx/util/nodes.py#L468). Before this copy operation, I am able to access the data_path attribute in the doctree. After this copy, I get an attribute error:
commenting out that line seems to have resolved my issue and I can now generate PDF files (with correct output from what I can tell). Could this be user error on my part, or is there something wrong with the implementation of deepcopy for the nodes.document type?
as a note, the actual table generation code for HTML/LaTeX hasn't been implemented yet - I was working on the plumbing when I found this, hence the very simple elements being added to the "body" object.
index.rst:
conf.py:
csv_table.py (my extension):
How to Reproduce
- run the sphinxdoc/sphinx-latexpdf image
- using my index.rst, conf.py, and csv_table.py build the project with
make latex/make html
Environment Information
Using the official sphinx-latex image from dockerhub:
docker.io/sphinxdoc/sphinx-latexpdf:latest
Image ID: a0591e845b10
Sphinx extensions
Additional context
No response
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
Start with the attached index.rst, conf.py, and csv_table.py files, then reproduce the HTML and LaTeX builds using the sphinxdoc/sphinx-latexpdf image. Read sphinx/util/nodes.py at inline_all_toctrees and inspect the deepcopy of the document; done means the custom node's data_path remains available during LaTeX processing without breaking the existing HTML output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100