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

Feature Request: Ability to silence more than one target found for cross-reference warning #3866

Closed
Blendify opened this issue Jun 14, 2017 · 15 comments

Comments

@Blendify
Copy link
Contributor

Subject: Feature request to extend the suppress_warnings function

Problem

A project that I work with currently has 1000+ warning from duplicate cross references.
WARNING: more than one target found for cross-reference 'float' while e may be able to fix this later, it would be great if we can silence them in the mean time.

Procedure to reproduce the problem

Create duplicate cross references.

Error logs / results

`WARNING: more than one target found for cross-reference 'float'` 

Expected results

The error should not appear.

Reproducible project / your project

https://developer.blender.org/diffusion/B/browse/master/doc/python_api/sphinx_doc_gen.py

Environment info

  • OS: Windows 10
  • Python version: 3.5.x
  • Sphinx version: 1.6.1
@tk0miya
Copy link
Member

tk0miya commented Jun 17, 2017

+1. I will add new filter to suppress_warnings.
It would be nice if you provide small reproducible example for us (I'd failed to reproduce the warning...)

@tk0miya tk0miya added this to the 1.7 milestone Jun 17, 2017
@Blendify
Copy link
Contributor Author

Blendify commented Jun 17, 2017

I think this actually is a bigger issue... I think the issue is the auto-linking for int, string, and, float types in Info field lists. I tried to scale this down to one case which can be seen below:

In one rst file:

.. module:: bge.constraints

.. function:: createConstraint(pivot_y=0.0)

   Creates a constraint.

   :arg pivot_y: Pivot Y position. (optional)
   :type pivot_y: float

   :return: A constraint wrapper.
   :rtype: :class:`~bge.types.KX_ConstraintWrapper`

In another rst file:

.. module:: bmesh.types

.. class:: BMLayerAccessVert

   .. attribute:: float

      Generic float custom-data layer.
      
      type: :class:`BMLayerCollection`

.. class:: BMLayerAccessLoop

   .. attribute:: float

      Generic float custom-data layer.
      
      type: :class:`BMLayerCollection`

@tk0miya
Copy link
Member

tk0miya commented Jun 17, 2017

Thank you for quick response. reproduced!
And I send #3869. It will resolve this problem.
Thanks,

@Blendify
Copy link
Contributor Author

I think what would really help is the ability to just not make these links. For us it does not make sense and the links are not relevent. E.g. a link will link to a class in a different class in a different module that does not relate to the orginal link in anyway. We just need it to tell the data type instead.

@tliron
Copy link

tliron commented Jun 26, 2017

Here's a quick workaround to put in conf.py:

class PatchedPythonDomain(PythonDomain):
    def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
        if 'refspecific' in node:
            del node['refspecific']
        return super(PatchedPythonDomain, self).resolve_xref(
            env, fromdocname, builder, typ, target, node, contnode)
    
def setup(sphinx):
    sphinx.override_domain(PatchedPythonDomain)

@Blendify
Copy link
Contributor Author

@tliron thanks and sorry for the wait but while testing it out I get the error NameError: name 'PythonDomain' is not defined might I have done something wrong?

@tliron
Copy link

tliron commented Jul 16, 2017

You will also need this:

from sphinx.domains.python import PythonDomain

@Blendify
Copy link
Contributor Author

Blendify commented Jul 16, 2017 via email

tk0miya added a commit that referenced this issue Jul 17, 2017
@tliron
Copy link

tliron commented Jul 17, 2017

I understand that the feature requested was specifically to silence the warning, but I think some of us would like to turn off the feature entirely. To be honest, it's hard for me to imagine the use case for this feature.

For those who want to turn off the feature, my patch would work. But it seems like this should be part of Sphinx.

@pitrou
Copy link

pitrou commented Oct 22, 2017

Hi, I tried the workaround mentioned in #3866 (comment), but now I get another error:

Warning, treated as error:
/home/travis/build/tornadoweb/tornado/tornado/platform/asyncio.py:docstring of tornado.platform.asyncio.AsyncIOMainLoop:1:py:obj reference target not found: IOLoop

See https://travis-ci.org/tornadoweb/tornado/jobs/291144347#L1444

Any guidance on this?

@tk0miya
Copy link
Member

tk0miya commented Oct 22, 2017

@pitrou Is that related with this issue? And did you mean that is a bug of Sphinx?
This is isseus list of Sphinx, not forum. Please move to forum if it is question.

Thanks,

@pitrou
Copy link

pitrou commented Oct 22, 2017

@tk0miya, yes this is related, since I tried the workaround mentioned here after I got bitten by this issue.

@ashafer01
Copy link

I came across this issue because I deliberately had created a "canonical path" for user import in my project, which obviously created the 'more than one target found' warning. I ended up adapting @tliron's response to override find_obj instead so that it would always resolve the desired path if it was found there:

class MyPythonDomain(PythonDomain):
    def find_obj(self, env, modname, classname, name, type, searchmode=0):
        """Ensures an object always resolves to the desired module if defined there."""
        orig_matches = PythonDomain.find_obj(self, env, modname, classname, name, type, searchmode)
        matches = []
        for match in orig_matches:
            match_name = match[0]
            desired_name = _desired_base_module + '.' + name.strip('.')
            if match_name == desired_name:
                matches.append(match)
                break
        if matches:
            return matches
        else:
            return orig_matches


def setup(sphinx):
    """Use MyPythonDomain in place of PythonDomain"""
    sphinx.override_domain(MyPythonDomain)

facebook-github-bot pushed a commit to facebookresearch/pytext that referenced this issue Dec 28, 2018
Summary:
our config objects are being added to the index twice, once in the modules docs, once in the config docs. This change removes the config doc verions from the index. Long term we likely want to merge these, but for now, this will do.

based on discussion here:
sphinx-doc/sphinx#3866
Pull Request resolved: #165

Reviewed By: bethebunny

Differential Revision: D13553706

Pulled By: m3rlin45

fbshipit-source-id: 62a23cce983e3e3a10a8169c990b9af9c12278bd
ghost pushed a commit to torproject/stem that referenced this issue May 14, 2020
Sphinx attempts to create cross-references for attribute and variable names...

  sphinx-doc/sphinx#2549
  sphinx-doc/sphinx#3866

This results in numerous warnings of the form...

  WARNING: more than one target found for cross-reference 'digest'

Adapting a patch from the tickets above. Sphinx deprecated override_domain(),
so using add_domain() instead...

  https://www.sphinx-doc.org/en/2.0/extdev/appapi.html#sphinx.application.Sphinx.override_domain
@pablosjv
Copy link

The @tliron patch needs a slight modification to work for Sphinx 3.4.3. In case someone finds this issue in google recently (like me), here it is:

from sphinx.domains.python import PythonDomain

class PatchedPythonDomain(PythonDomain):
    def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
        if 'refspecific' in node:
            del node['refspecific']
        return super(PatchedPythonDomain, self).resolve_xref(
            env, fromdocname, builder, typ, target, node, contnode)

def setup(sphinx):
    sphinx.add_domain(PatchedPythonDomain, override=True)

@Blendify
Copy link
Contributor Author

Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants