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

Only create a target for object descriptions #10478

Merged
merged 32 commits into from Jul 28, 2023

Conversation

latosha-maltba
Copy link
Contributor

@latosha-maltba latosha-maltba commented May 27, 2022

Subject: Only create a target for object descriptions

Feature or Bugfix

  • Feature

Purpose

Adding feature for #9662 (ability to only create a target for a domain description).
Thanks again to @jakobandersen for the inspiration.

This is #9675 repurposed and rebased onto the current 5.x. In the hope that it now gets more traction.

Open Tasks:

  • Bikeshedding: should the parameter be named :hidden:, :targetonly:, :your-favorite-word-here:, ...
  • If this implementation gets an approval, I'll add the documentation for the parameter before merging.

Relates

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a lot of tests -- for the new transform and for the behaviour x each domain.

A

sphinx/directives/__init__.py Outdated Show resolved Hide resolved
sphinx/directives/__init__.py Outdated Show resolved Hide resolved
sphinx/directives/__init__.py Outdated Show resolved Hide resolved
sphinx/domains/javascript.py Outdated Show resolved Hide resolved
@AA-Turner AA-Turner added the type:enhancement enhance or introduce a new feature label May 27, 2022
@AA-Turner
Copy link
Member

You also need to fix the existing test failures.

A

@latosha-maltba latosha-maltba force-pushed the object_description_run_5.x branch 5 times, most recently from fa8ec4a to 800231b Compare May 29, 2022 12:38
@latosha-maltba
Copy link
Contributor Author

So, I added documentation and unit tests.

I'm still not quiet happy with the naming of the option: :hidden: doesn't seem to grasp it, :notypesetting: seems more precise but is IMHO clumsy. Better :nocontent: however, the object description is build form signature+content, so this is misleading and there is a term missing for the union of both signature and content. Maybe :astarget:? (:onlytarget: omits that we are also creating an index entry not only a target.) For the consistency with :noindex: and :noindexentry I tend to lean to a :noXXX: word but that is not required. Naming is hard, so thoughts are welcome.

Copy link
Contributor

@jakobandersen jakobandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I like notypesetting as it conveys exactly what it is doing, and it is in line with noindex and noindexentry.

sphinx/domains/cpp.py Outdated Show resolved Hide resolved
doc/usage/restructuredtext/domains.rst Outdated Show resolved Hide resolved
@latosha-maltba latosha-maltba force-pushed the object_description_run_5.x branch 3 times, most recently from eaaf978 to e23f883 Compare June 4, 2022 05:15
Add option :hidden: to ObjectDescription.  Currently, this option has no
effect except being stored as attribute in the resulting node.
Do not produce any output only a target node if option :hidden: is
given.  In this case all nodes representing this ObjectDescription are
replaced by a single target where the target gets assigned all ids of
the replaced nodes.
Record the source information (class attributes source and line) when
replacing an object description node with a target node.
The collect_ids() function uses the its second parameter ``ids:
List[str]`` as in- and output parameter and always returns None.
Rewrite the function to become pure and side effect free: return the
list of ids as the return value not as an output parameter.
replace_node_with_target() does not access the self-instance.  Thus,
declare it as a static method.
Move the collect_ids() method from inside the replace_node_with_target()
into the class scope (as static method) since it does not need the
closure of the surrounding replace_node_with_target() method.  This also
gives a potential speed boost.
Inline the one-line method replace_node_with_target() into its only call
site.  Since there are no call sites left, remove the method afterwards.
Instead of overriding the `option_spec` variable copy the `option_spec`
of the superclass and update it.  This way changes in the superclass
propagate to its children.  This is in line how other classes use
"`option_spec`-inheritance".
The alias objects override the run() method and thus do not support
``:notypesetting:`` option.
Correct node order generated by the .. js:module:: directive:  When
generating an index entry, the index node must come before the target
node.
Correct node order generated by the .. py:module:: directive:  When
generating an index entry, the index node must come before the target
node.
It might be that a object description has no ids associated with it,
e.g. if the option :noindex: is passed.  In this case we would replace
the object description node with a target node, which has no ids.  This
breaks docutils assumption about a target node and leads not errors.
Therefore, do only create a target node if we have ids to work with.
An index directive creates a index node followed by a target node.  Two
consecutive index directives::

.. index:: first
.. index:: second

create index, target, index, target, i.e. a mixture.  The interspersed
index nodes prevent other transformations, e.g. PropagateTargets to
properly work on the target nodes.

Apply a transformation which reorders mixed and consecutive index and
target nodes such that first all index nodes are before all target
nodes:

Given the following document as input:

    <document>
        <target ids="id1" ...>
        <index entries="...1...">
        <target ids="id2" ...>
        <target ids="id3" ...>
        <index entries="...2...">
        <target ids="id4" ...>

The transformed result will be:

    <document>
        <index entries="...1...">
        <index entries="...2...">
        <target ids="id1" ...>
        <target ids="id2" ...>
        <target ids="id3" ...>
        <target ids="id4" ...>
@latosha-maltba
Copy link
Contributor Author

latosha-maltba commented Jun 4, 2022

  • Rebased this on newest 5.x so I can add a CHANGES entry without conflicts.
  • Addressed the two issues raised by @jakobandersen

Thanks for all the feedback!

@AA-Turner Once this is merged #9671 can be closed as this is an alternative attempt/proof-of-concept to solving this.

@latosha-maltba
Copy link
Contributor Author

Is there anything that prevents this from being merged or what else can I do to facilitate the adoption of this?

@AA-Turner AA-Turner changed the base branch from 5.x to master October 16, 2022 15:28
@latosha-maltba
Copy link
Contributor Author

@AA-Turner, @tk0miya anything preventing this from being merged?

@AA-Turner AA-Turner added this to the some future version milestone Apr 29, 2023
# Conflicts:
#	doc/usage/restructuredtext/domains.rst
#	sphinx/directives/__init__.py
#	sphinx/domains/c.py
#	sphinx/domains/cpp.py
#	sphinx/domains/javascript.py
#	sphinx/domains/python.py
#	sphinx/transforms/__init__.py
@AA-Turner AA-Turner self-requested a review July 28, 2023 18:38
@AA-Turner AA-Turner merged commit 97d2c5d into sphinx-doc:master Jul 28, 2023
25 of 27 checks passed
@AA-Turner AA-Turner modified the milestones: some future version, 7.2.0 Aug 11, 2023
AA-Turner added a commit to AA-Turner/sphinx that referenced this pull request Aug 26, 2023
This resolves a regression introduced in sphinx-docGH-10478
(commit 97d2c5d).
AA-Turner added a commit that referenced this pull request Aug 26, 2023
This resolves a regression introduced in GH-10478
(commit 97d2c5d).
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type:enhancement enhance or introduce a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow creating custom targets in a domain
3 participants