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

[Doc]: [source] link for deprecated functions leads to _api/deprecation.py #22039

Closed
StefRe opened this issue Dec 22, 2021 · 3 comments · Fixed by #22044
Closed

[Doc]: [source] link for deprecated functions leads to _api/deprecation.py #22039

StefRe opened this issue Dec 22, 2021 · 3 comments · Fixed by #22044
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Documentation Good first issue Open a pull request against these issues if there are no active ones!
Milestone

Comments

@StefRe
Copy link
Contributor

StefRe commented Dec 22, 2021

Documentation Link

https://matplotlib.org/devdocs/api/dates_api.html#matplotlib.dates.MicrosecondLocator.set_data_interval

Problem

see title, [source] links to https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/_api/deprecation.py#L1693-L1696, i.e. the line numbers are correct but the file is wrong (_api/deprecation.py instead of matplotlib/dates.py)

Suggested improvement

[source] link should lead to deprecated function, i.e. in the given example to

@_api.deprecated("3.5", alternative=".axis.set_data_interval")
def set_data_interval(self, vmin, vmax):
self._wrapped_locator.set_data_interval(vmin, vmax)
return super().set_data_interval(vmin, vmax)

Matplotlib Version

3.5.1

@tacaswell tacaswell added Good first issue Open a pull request against these issues if there are no active ones! Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Dec 23, 2021
@tacaswell
Copy link
Member

This will presumably would be a fix to

matplotlib/doc/conf.py

Lines 580 to 636 in a35921c

if link_github:
import inspect
from packaging.version import parse
extensions.append('sphinx.ext.linkcode')
def linkcode_resolve(domain, info):
"""
Determine the URL corresponding to Python object
"""
if domain != 'py':
return None
modname = info['module']
fullname = info['fullname']
submod = sys.modules.get(modname)
if submod is None:
return None
obj = submod
for part in fullname.split('.'):
try:
obj = getattr(obj, part)
except AttributeError:
return None
try:
fn = inspect.getsourcefile(obj)
except TypeError:
fn = None
if not fn or fn.endswith('__init__.py'):
try:
fn = inspect.getsourcefile(sys.modules[obj.__module__])
except (TypeError, AttributeError, KeyError):
fn = None
if not fn:
return None
try:
source, lineno = inspect.getsourcelines(obj)
except (OSError, TypeError):
lineno = None
linespec = (f"#L{lineno:d}-L{lineno + len(source) - 1:d}"
if lineno else "")
startdir = Path(matplotlib.__file__).parent.parent
fn = os.path.relpath(fn, start=startdir).replace(os.path.sep, '/')
if not fn.startswith(('matplotlib/', 'mpl_toolkits/')):
return None
version = parse(matplotlib.__version__)
tag = 'main' if version.is_devrelease else f'v{version.public}'
return ("https://github.com/matplotlib/matplotlib/blob"
f"/{tag}/lib/{fn}{linespec}")

Labeled as good first issue because it involves no public API changes, but medium as you will need to work with the code linked above and do a bunch of code scraping to see if we can get back to the source of the decorated function!

@StefRe
Copy link
Contributor Author

StefRe commented Dec 23, 2021

maybe it makes more sense to integrate this in sphinx-doc/sphinx#1556 (if not already covered by sphinx-doc/sphinx#9625) than to create an own version?

@StefRe
Copy link
Contributor Author

StefRe commented Dec 23, 2021

Thanks @tacaswell for pointing me to the rigth file. With the help of https://bugs.python.org/issue34305 the fix was trivial.

@QuLogic QuLogic added this to the v3.5.2 milestone Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Documentation Good first issue Open a pull request against these issues if there are no active ones!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants