sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.59k stars 2.12k forks source link

sphinx.ext.viewcode could not work as expected on parallel build #8933

Closed cheekyshibe closed 3 years ago

cheekyshibe commented 3 years ago

Describe the bug I'm using sphinx to build the document for the project MegEngine.

In Docs repo, most APIs are organized manually for some reasons:

.. autosummary::
   :toctree: api
   :nosignatures:

   cos
   sin
   tan
   acos
   asin
   atan
   atan2
   cosh
   sinh
   tanh
   acosh
   asinh
   atanh

As you can see, several functions are implemented here:

WeChat3bebe346a97db2dad70a63161e7f0ff9

Everything works for cosh():

WeChata2050cf6586bb572655ecd991b785331 WeChate65d067246afe5f0d378e5776c672f1d

WeChat91eaedabab3eb86bbf83a80dc7574b44

But it doesn't work for some other APIs like asin() acos() ...

Seems viewcode-back class is not generated for every API.

To Reproduce

I'm sure that sphinx.ext.viewcode not works as expected. You can do it with these steps to reproduce the behavior with a GitHub workflow file: https://github.com/MegEngine/Tutorials/blob/main/.github/workflows/sphinx-build.yml

Expected behavior copied Class/Function source codes HTML pages can be highlighted and add links to documents correctly.

Your project MegEngine / Docs

Environment info

tk0miya commented 3 years ago

Now I checked your public document on https://megengine.org.cn/api/latest/_modules/megengine/functional/elemwise.html#cosh, but it seems working fine. Does this trouble happen in your local environment?

cheekyshibe commented 3 years ago

@tk0miya Thanks for your reply. Now our doc website is an old version(all APIs are generated by sphinx.ext.autodoc automodule) and it will be replaced soon. If you want to reproduce the problem locally, here is the source code: https://github.com/MegEngine/Tutorials/tree/docs-transfer

And I can provide a Tutorial to build and deploy the document locally. But it was written in Chinese so I think you can use Google translation or look at this file:

jobs:
  Build:
    name: Build html
    runs-on: ubuntu-latest
    steps:
      - name: Checkout document repp
        uses: actions/checkout@v2

      - name: Checkout theme repo
        uses: actions/checkout@v2
        with: 
          repository: MegEngine/pydata-sphinx-theme
          ref: dev
          fetch-depth: 1
          path: theme

      - name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.6

      - name: Cache Python packages
        id: cache-python
        uses: actions/cache@v2
        with:
          path: ${{ env.pythonLocation }}
          key: ${{ env.pythonLocation }}$-${{ hashFiles('requirements.txt') }}

      - name: Install MegEngine, Sphinx and other Python dependencies
        if: steps.cache-python.outputs.cache-hit != 'true'
        run: |
          python3 -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
          pip install megengine
      - name: Install Pydata Sphinx theme
        run: python3 -m pip install ./theme

      - name: Install pandoc and other dependencies
        run: sudo apt-get install -y pandoc

      - name: Generate HTML files
        run: make html -W --keep-going

It's in the testing status for MegEngine 1.3 (not release now) so there will be lots of API missing warning if you build it with MegEngine v1.2.

tk0miya commented 3 years ago

I found the reason. It's a bug of the viewcode extension on parallel build mode. #8935 will resolve the error.

cheekyshibe commented 3 years ago

So efficient. 👍

astrojuanlu commented 3 years ago

@MegChai Hi! I see that you closed MegEngine/Documentation#49 but, from what I understand, MegEngine has Sphinx 3.5.4 pinned. We are investigating whether there is still a bug with sphinx.ext.viewcode accidentally introduced by #8935 (see #9210). Could you please try to build MegEngine docs with Sphinx 4.0 and report back the results? Thanks in advance!

cheekyshibe commented 3 years ago

@astrojuanlu Cool. sphinx.ext.viewcode works as expected now. Thanks for your work.

I fix the Sphinx version because of other unadapted extensions and have a workaround later. And I will start using Sphinx 4.0 in the next version of MegEngine documentation (see WIP PR).