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

Subclasses of Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle #19839

Open
nstarman opened this issue Mar 31, 2021 · 15 comments · May be fixed by #20174
Open

Subclasses of Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle #19839

nstarman opened this issue Mar 31, 2021 · 15 comments · May be fixed by #20174
Milestone

Comments

@nstarman
Copy link

@nstarman nstarman commented Mar 31, 2021

Problem

The sphinx links to CapStyle and JoinStyle in v3.4.0 are relative to the file, so a subclass of matplotlib.patches.Patch in a package with numpydoc xref (https://numpydoc.readthedocs.io/en/latest/install.html) turned on cannot link to the objects and errors with.
WARNING: py:obj reference target not found: CapStyle
WARNING: py:obj reference target not found: JoinStyle

https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch.set_capstyle
https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch.set_joinstyle

   @docstring.interpd
    def set_capstyle(self, s):
        """
        Set the `.CapStyle`.

        Parameters
        ----------
        s : `.CapStyle` or %(CapStyle)s
        """
        cs = CapStyle(s)
        self._capstyle = cs
        self.stale = True

Edit:

The problem also appears to involve Patches.__init__. I can monkey-patch a fix with

Polygon.__init__.__doc__ = Polygon.__init__.__doc__.replace(
    "`.CapStyle`", "``matplotlib._enums.CapStyle``")
Polygon.__init__.__doc__ = Polygon.__init__.__doc__.replace(
    "`.JoinStyle`", "``matplotlib._enums.JoinStyle``")
Polygon.set_capstyle.__doc__ = Polygon.set_capstyle.__doc__.replace(
    "`.CapStyle`", "``matplotlib._enums.CapStyle``")
Polygon.set_joinstyle.__doc__ = Polygon.set_joinstyle.__doc__.replace(
    "`.JoinStyle`", "``matplotlib._enums.JoinStyle``")

Suggested Improvement

  • This line could be be changed to say
   @docstring.interpd
    def set_capstyle(self, s):
        """
        Set the `~matplotlib._enums.CapStyle`.

        Parameters
        ----------
        s : `~matplotlib._enums.CapStyle` or %(CapStyle)s
        """
        cs = CapStyle(s)
        self._capstyle = cs
        self.stale = True

Matplotlib version

  • Operating system: Big Sur & Ubuntu
  • Matplotlib version 3.4.0
  • Matplotlib documentation version (is listed under the logo): 3.4.0
@nstarman nstarman changed the title Subclasses Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle Subclasses of Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle Mar 31, 2021
@jklymak
Copy link
Contributor

@jklymak jklymak commented Mar 31, 2021

Umm, how did we end up with private libraries linked in the public docs? That shouldn't have happened. https://matplotlib.org/stable/api/_enums_api.html#matplotlib._enums.CapStyle I think @brunobeltran and @timhoffm worked on this?

@timhoffm
Copy link
Member

@timhoffm timhoffm commented Mar 31, 2021

The use of private modules is a workaround. The classes themselves are not public, but the concepts they describe are. We need a location to document these concepts and the simplest solution is with the classes that represent these concepts. There are other ways to solve this as I've proposed in #18544, but that would require additional machinery and was not appreciated in that discussion.

as for the xref thing, I do not fully understand where the warning is coming from and need to have a closer look.

@nstarman
Copy link
Author

@nstarman nstarman commented Apr 1, 2021

As far as I can tell, the xref issue stems from the fact that references to CapStyle and JoinStyle are relative paths, not absolute. I've found for other references in Astropy that changing `.object` to `~package.subpackage.object` resolves the issue

nstarman added a commit to nstarman/astropy that referenced this issue Apr 2, 2021
- Temporary fix to matplotlib/matplotlib#19839,
- from astropy#11118,
- closes (?) astropy#11464

Co-authored-by: @pllim
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
eteq added a commit to eteq/astropy that referenced this issue Apr 2, 2021
- Temporary fix to matplotlib/matplotlib#19839,
- from astropy#11118,
- closes (?) astropy#11464

Co-authored-by: @pllim
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
nstarman added a commit to nstarman/astropy that referenced this issue Apr 2, 2021
- Temporary fix to matplotlib/matplotlib#19839,
- from astropy#11118,
- closes (?) astropy#11464

Co-authored-by: @pllim
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
@tacaswell tacaswell added this to the v3.4.2 milestone Apr 2, 2021
@pllim
Copy link

@pllim pllim commented Apr 3, 2021

Circling back here... The patch suggested above did get around the ReadTheDocs "fail on warning" problem; see astropy/astropy#11466 though you still see those warnings in the log but they somehow not blocking RTD check. FYI 🤷

And for completeness: xref astropy/astropy#11458

@anntzer
Copy link
Contributor

@anntzer anntzer commented Apr 3, 2021

I think this may be related to sphinx-doc/sphinx#6211 (which I basically opened based on my experience with matplotlib)?

@anntzer
Copy link
Contributor

@anntzer anntzer commented Apr 8, 2021

I am bit confused why this specific dotted reference breaks your build whereas a lot of other dotted references (e.g. .Transform) don't?

@pllim
Copy link

@pllim pllim commented Apr 8, 2021

@anntzer , these are the warnings (it breaks because we have RTD set to fail on warning):

MatplotlibDeprecationWarning:
The validCap attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later.
  return getattr(obj, attr, *defargs)
MatplotlibDeprecationWarning:
The validJoin attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later.
  return getattr(obj, attr, *defargs)

The code in astropy does not specifically have them, but rather a subclass inherited them. And then Sphinx tries to render docstring for inherited attributes. We also use sphinx-automodapi plugin to render it. So, it is really a perfect storm of a few things put together.

References: astropy/astropy#11458 astropy/sphinx-automodapi#125

@timhoffm
Copy link
Member

@timhoffm timhoffm commented Apr 8, 2021

I'm now confused: Are you breaking because of the deprecation warnings or because of "reference target not found" in the first comment above? Or both?

@pllim
Copy link

@pllim pllim commented Apr 8, 2021

Ah, not really. I was redirected to this issue from #19850 . I specifically speaking about the MatplotlibDeprecationWarning. I don't know what the "reference target not found" issue is about but I think @nstarman found a fix.

@nstarman
Copy link
Author

@nstarman nstarman commented Apr 8, 2021

Originally it was both, but we monkey-patched a solution to the "reference target not found" error by editing the matplotlib docstrings before subclassing Polygon (https://github.com/astropy/astropy/pull/11466/files, but PR is incorrectly named for what it solves).

@nstarman
Copy link
Author

@nstarman nstarman commented Apr 8, 2021

It is presumably still an error if the monkey-patch is removed.

@timhoffm
Copy link
Member

@timhoffm timhoffm commented Apr 8, 2021

In the dev call today, we decided to replace the types (specifically CapStyle) by plain references, i.e.

s : `.CapStyle` or %(CapStyle)s

to

s : CapStyle_ or %(CapStyle)s

These should be resolved via intersphinx so that the monkey-patching becomes obsolete.

The deprecation warning is a separate topic, I'll reopen #19850.

@pllim
Copy link

@pllim pllim commented Apr 8, 2021

@nstarman , suggestion from #19850 (comment) is a no-go, so I think the monkeypatch is there to stay until astropy can bump minversion of matplotlib to the version that has removed the deprecated attributes. FYI.

@timhoffm
Copy link
Member

@timhoffm timhoffm commented Apr 8, 2021

@pllim @nstarman AFAICT these two issues are completely unrelated.

The planned change here (#19839 (comment)) should make the monkey-patching obsolete.

@pllim
Copy link

@pllim pllim commented Apr 9, 2021

I can't say I understand what's going on either. RTD passes with the monkey patch. Maybe the warning is red herring after all. 🤷🏻‍♀️

@brunobeltran brunobeltran mentioned this issue Apr 22, 2021
7 tasks
aaryapatil added a commit to aaryapatil/astropy that referenced this issue May 3, 2021
- Temporary fix to matplotlib/matplotlib#19839,
- from astropy#11118,
- closes (?) astropy#11464

Co-authored-by: @pllim
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
@brunobeltran brunobeltran linked a pull request that will close this issue May 6, 2021
3 tasks
@QuLogic QuLogic removed this from the v3.4.2 milestone May 7, 2021
@QuLogic QuLogic added this to the v3.4.3 milestone May 7, 2021
@QuLogic QuLogic removed this from the v3.4.3 milestone Aug 11, 2021
@QuLogic QuLogic added this to the v3.4.4 milestone Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

7 participants