Skip to content

gh-87378: [doc] Link to source #24521

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

verhovsky
Copy link
Contributor

@verhovsky verhovsky commented Feb 12, 2021

Links to source of classes and functions defined in Python or using the Argument Clinic using sphinx.ext.linkcode (available since Sphinx 1.1)

https://bugs.python.org/issue43212

@verhovsky
Copy link
Contributor Author

Looks like this (functions that don't span 2 lines look a bit nicer)

Screenshot from 2021-02-12 17-31-01

and links to this

Screenshot from 2021-02-12 17-31-28

@verhovsky
Copy link
Contributor Author

verhovsky commented Feb 16, 2021

You can test what this extension links each name to by pulling my fork

git clone git@github.com:verhovsky/cpython.git
cd cpython
git pull
git checkout link-to-source
cd Doc

then uncommenting the last 2 commented out print() lines in Doc/tools/extensions/link_to_source.py and building the documentation like this:

rm -rf build/*
make html | tee >(grep -v "\s" > doesnt-exist) | tee >(grep -v "\.\.\. ." | grep "\s" > exists)

creating two files exists and doesnt-exist which will contain functions it could and couldn't find a link to source for, which will look like this:

asyncio.Task.get_coro                                                  Lib/asyncio/tasks.py                          132       def get_coro(self):
asyncio.Task.get_name                                                  Lib/asyncio/tasks.py                          135       def get_name(self):
asyncio.Task.set_name                                                  Lib/asyncio/tasks.py                          138       def set_name(self, value):
asyncio.coroutine                                                      Lib/asyncio/coroutines.py                     105   def coroutine(func):
asyncio.iscoroutine                                                    Lib/asyncio/coroutines.py                     177   def iscoroutine(obj):
asyncio.iscoroutinefunction                                            Lib/asyncio/coroutines.py                     164   def iscoroutinefunction(func):
asyncore.loop                                                          Lib/asyncore.py                               192   def loop(timeout=30.0, use_poll=False, map=None, count=None):
asyncore.dispatcher                                                    Lib/asyncore.py                               210   class dispatcher:
asyncore.dispatcher.handle_read                                        Lib/asyncore.py                               479       def handle_read(self):
asyncore.dispatcher.handle_write                                       Lib/asyncore.py                               482       def handle_write(self):

Currently 5058/9079 documented symbols would have a link to source:

$ wc exists doesnt-exist 
  5058  31742 813825 exists
  4021   4015  96125 doesnt-exist
  9079  35757 909950 total

Some reasons for stuff not getting linked:

  1. objects defined in C without using the Argument Clinic aren't detected
  2. since we don't look at what happens in __init__() we don't have a source for most class variables, this doesn't really matter if the class definition is linked to
  3. some things are documented with a symbol name that doesn't correspond to the code, for example asyncio.loop.* is actually asyncio.AbstractEventLoop.* or asyncio.BaseEventLoop.*
  4. only top level import statements are processed, imports in if statements aren't picked up

This adds about 5 seconds to make html on my laptop, about 8% longer.

@verhovsky verhovsky changed the title Link to source of Python and Argument Clinic classes and functions bpo-43212: Link to source of Python and Argument Clinic classes and functions Feb 16, 2021
@verhovsky verhovsky changed the title bpo-43212: Link to source of Python and Argument Clinic classes and functions bpo-43212: [doc] Link to source of Python and Argument Clinic classes and functions Feb 16, 2021
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Mar 22, 2021
@verhovsky verhovsky force-pushed the link-to-source branch 2 times, most recently from 8295105 to 1524000 Compare April 7, 2022 05:23
@ghost
Copy link

ghost commented Apr 14, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@verhovsky verhovsky changed the title bpo-43212: [doc] Link to source of Python and Argument Clinic classes and functions gh-87378: [doc] Link to source of Python and Argument Clinic classes and functions Apr 14, 2022
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Aug 4, 2022
@erlend-aasland
Copy link
Contributor

cc. Sphinx experts @AA-Turner and @hugovk

@AA-Turner
Copy link
Member

Thanks for the ping @erlend-aasland -- from my perspective this PR needs several architectural changes (not doing things in the module scope, at the least) -- likely larger than what can reasonably be achieved via the GH suggestions mechanism, so unless anyone objects I'd propose to push my suggested changes to this branch?

A

@verhovsky verhovsky changed the title gh-87378: [doc] Link to source of Python and Argument Clinic classes and functions gh-87378: [doc] Link to source Jan 14, 2024
@AA-Turner AA-Turner self-requested a review January 14, 2024 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants