Search code examples
pythongitlabgitlab-cipython-sphinxgitlab-pages

gitlab-page for sphinx project is not working as expected


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

Solution

  • 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.