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

docs: add hoverxref & codeautolink support. Various fixes #2968

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

kachida
Copy link
Contributor

@kachida kachida commented Mar 3, 2024

Fixes #1522

Copy link

codecov bot commented Mar 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.61%. Comparing base (1bb98ae) to head (f0cb052).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2968      +/-   ##
==========================================
- Coverage   99.63%   99.61%   -0.02%     
==========================================
  Files         117      117              
  Lines       17593    17593              
  Branches     3173     3173              
==========================================
- Hits        17528    17525       -3     
- Misses         46       47       +1     
- Partials       19       21       +2     

see 1 file with indirect coverage changes

@kachida
Copy link
Contributor Author

kachida commented Mar 3, 2024

Related issue:

#1522

@jakkdl
Copy link
Member

jakkdl commented Mar 3, 2024

Read the Docs build is failing (as can be seen by clicking through from the checks for the PR):
updated doc-requirements.in and .txt

@jakkdl
Copy link
Member

jakkdl commented Mar 3, 2024

The hoverxref seems to be working excellently, but objects in examples don't seem to be clickable (i.e. the codeautolink part)? https://trio--2968.org.readthedocs.build/en/2968/reference-testing.html

@jakkdl jakkdl linked an issue Mar 3, 2024 that may be closed by this pull request
@kachida
Copy link
Contributor Author

kachida commented Mar 4, 2024

Thank you, @jakkdl, for adding the missing dependencies in the requirements file. I will review and confirm with you why the objects do not appear clickable.

@jakkdl
Copy link
Member

jakkdl commented Apr 23, 2024

It appears that codeautolink requires explicitly marking code blocks as python code blocks, so this does not work:

In the simplest case, you can apply a timeout to a block of code::
with trio.move_on_after(30):
result = await do_http_get("https://...")
print("result is", result)
print("with block finished")

But this does (after adding import trio to codeautolink_global_preface)

In the simplest case, you can apply a timeout to a block of code:

.. code:: python

   with trio.move_on_after(30):
       result = await do_http_get("https://...")
       print("result is", result)
   print("with block finished")

Skimming configuration and examples I don't find a way to configure the former to work, so will have to replace the syntax of all code blocks - but shouldn't be too bad with a regex search&replace.

This does also add syntax highlighting in my editor, and in viewing the source on github.

jakkdl and others added 2 commits April 24, 2024 11:38
…mentation to use .. code::, and make the majority explicit what language (python, pycon, sh) they are in
Copy link
Member

@jakkdl jakkdl left a comment

Choose a reason for hiding this comment

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

The vast majority of the diff is near identical, so I pointed out most points where anything is different.

Comment on lines 381 to 385
def call_the_thing(fn, *args, kwonly1, kwonly2, ...)::
def call_the_thing(fn, *args, kwonly1, kwonly2, ...):
Copy link
Member

Choose a reason for hiding this comment

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

random typo I noticed when searching for ::$

Comment on lines 390 to 396
def call_the_thing(fn, *args)::
.. code:: python

def call_the_thing(fn, *args):
Copy link
Member

Choose a reason for hiding this comment

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

and a second instance of invalid python syntax

Comment on lines 338 to 350
function call that returns this weird "coroutine" object::
function call that returns this weird "coroutine" object:

.. code:: pycon
Copy link
Member

Choose a reason for hiding this comment

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

pycon is "python console"

Comment on lines 44 to 49
* push to PyPI::
* push to PyPI:

.. code::

git clean -xdf # maybe run 'git clean -xdn' first to see what it will delete
python3 -m build
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there is any language highlighting that's relevant here, so made it a generic code block.

Comment on lines 863 to 865
subshell, multiple layers of escaping can be needed:

.. code:: sh
Copy link
Member

Choose a reason for hiding this comment

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

shell

Comment on lines 865 to 884
because CMD.EXE handles them differently from the MSVC runtime rules; in::
because CMD.EXE handles them differently from the MSVC runtime rules; in:

.. code:: sh

prog.exe "foo \"bar\" baz"

Copy link
Member

Choose a reason for hiding this comment

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

there might be some windows console identifier, but I just made it sh /shrug

Comment on lines 183 to 186
codeautolink_global_preface = """
import trio
from trio import *
"""
Copy link
Member

Choose a reason for hiding this comment

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

most of the code uses trio.xxxx, maybe even all of it, but not much reason not to keep from trio import *. Although it's plausible we should also import testing/lowlevel/etc, have not scoured the docs that thoroughly yet.

@jakkdl jakkdl changed the title docs: added hoverxref & codeautolink support docs: add hoverxref & codeautolink support. Various fixes Apr 24, 2024
Comment on lines -714 to +715
import asyncio, trio
import asyncio
import trio
Copy link
Member

Choose a reason for hiding this comment

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

Don't know why this raised errors, or by what, but it gave

/home/h/Git/trio/docs/source/reference-lowlevel.rst: WARNING: Could not match transformation of `asyncio` on source lines 1-1

@jakkdl
Copy link
Member

jakkdl commented Apr 24, 2024

I noticed one file using

.. code-block:: python3


  if bool(int('5')):
      print("hello world")

Turns out github (or my editor) don't recognize python3 as a language directive for highlighting the rst source code

.. code-block:: python

  if bool(int('5')):
      print("hello world")

(No clue why, it works in normal code blocks, and is a valid identifier both according to linguist (used for GH code blocks) and pygments (used by RST))

After an unreasonable amount of digging I've finally figured out the difference between .. code:: and .. code-block::. Sphinx does not seem to document the existence of .. code:: at all, or mention it as an option for showing code, and you have to dig deep to find the docutils documentation for directives to find it documented. Sphinx seems to treat them identically in ~all cases, only diverging if you want to use options for code-block. So it seems like the reasonable default is to stick to .. code-block:: in case anybody want to add any options to a block in the future.

A trailing :: is a literal block (sphinx) / preformatted block (docutils), where python highlighting was set with highlight_language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable hoverxref in Trio docs
3 participants