2

The link to the whole project https://gitlab.com/ComplicatedPhenomenon/doubancrawler

I tested the generated document on local machine, it works fine enter image description here

and gitlab page is as below (https://complicatedphenomenon.gitlab.io/doubancrawler/api.html) enter image description here

Is there something wrong with .gitlab-ci.yml?

image: python:3.7-alpine

test:
  stage: test
  script:
  - pip install -r requirements2.txt
  - cd docs/source/
  - sphinx-build -b html . public
  - mv public ../..
  only:
  - branches
  except:
  - master

pages:
  stage: deploy
  script:
  - pip install -r requirements2.txt
  - cd docs/source/
  - sphinx-build -b html . public
  - mv public ../..
  artifacts:
    paths:
    - public
  only:
  - master
sytech
  • 29,298
  • 3
  • 45
  • 86
ComplicatedPhenomenon
  • 4,055
  • 2
  • 18
  • 45
  • This happens when autodoc can’t find/import your references. Maybe try installing your package first in the job or modifying `sys.path` in your sphinx config to make sure your modules can be imported when building docs. – sytech Dec 18 '21 at 20:21

1 Answers1

3

This happens when autodoc can’t find/import your references.

You are not installing all of the requirements for your project. In order for autodoc to work, you need to be able to import all your package modules. However, you’re only installing the requirements for building docs (requirements2.txt).

Otherwise, autodoc will receive an ImportError when trying to pull your doc strings because your modules attempt to import packages that are not installed.

Locally, you probably don’t have issues because you have already installed all of the requirements.

To fix this, add pip install -r requirements.txt to your job.

sytech
  • 29,298
  • 3
  • 45
  • 86
  • That's the case indeed, I should have carefully checked the generated log during GitLab CI/CD as there existed clues. Even the CI/CD passed at that time, lots of warnings remain. – ComplicatedPhenomenon Dec 19 '21 at 04:05
  • Actually, it's not clear to me why autodoc need to check whether the import library is installed, to me, I think the necessary work for autodoc is to check the grammar of the documentation. – ComplicatedPhenomenon Dec 20 '21 at 02:11
  • 1
    @ComplicatedPhenomenon because the autodoc extension does not use a static analysis technique. It uses `inspect`, which works by inspecting the Python objects, which requires the module be imported. Keep in mind, docstrings can be generated programmatically. – sytech Dec 20 '21 at 09:12
  • Now I'm less confused , I appreciate your explanation – ComplicatedPhenomenon Dec 20 '21 at 09:38