Failure to find file when building docs

I am trying to build Sphinx documentation for my python project using Github Actions and I am hitting an error stating that the relevant file is not found. The documentation builds fine locally (it works on my machine!). I thought it was might be an issue with location of file but that doesnt seem to be the case as from as the paths in the error hold the correct relative position.

I’ve checked the Sphinx and Github Actions documentation and I havent found anything to indicate what I am doing wrong.

The file structure looks like this:

  • data
    • game
      • traits.json <- the file not found
  • docs
    • _build <- where the docs are being built to
  • scripts
    • engine
      • action.py <- where the error occurs

The error:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/site-packages/sphinx/ext/autodoc/importer.py", line 66, in import_module
    return importlib.import_module(modname)
  File "/opt/hostedtoolcache/Python/3.8.5/x64/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/runner/work/notquiteparadise/notquiteparadise/scripts/engine/action.py", line 26, in <module>
    from scripts.engine.effect import Effect, MoveActorEffect
  File "/home/runner/work/notquiteparadise/notquiteparadise/scripts/engine/effect.py", line 9, in <module>
    from scripts.engine import utility, world
  File "/home/runner/work/notquiteparadise/notquiteparadise/scripts/engine/world.py", line 15, in <module>
    from scripts.engine import action, chronicle, debug, library, utility
  File "/home/runner/work/notquiteparadise/notquiteparadise/scripts/engine/chronicle.py", line 8, in <module>
    from scripts.engine import library, world
  File "/home/runner/work/notquiteparadise/notquiteparadise/scripts/engine/library.py", line 228, in <module>
    refresh_library()
  File "/home/runner/work/notquiteparadise/notquiteparadise/scripts/engine/library.py", line 73, in refresh_library
    _load_traits_data()
  File "/home/runner/work/notquiteparadise/notquiteparadise/scripts/engine/library.py", line 111, in _load_traits_data
    with open(DATA_PATH + "game/traits.json") as file:
FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/work/notquiteparadise/notquiteparadise/data/game/traits.json'

The Github Action yaml:

name: NQP - Build Docs

on:
  workflow_run:
    workflows: ["NQP - Run Tests"]
    branches: [develop, master]
    types:
      - completed

jobs:
  docs:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Set up Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: 3.8

      - name: Use cache
        uses: actions/cache@v2
        with:
          path: ~\AppData\Local\pip\Cache
          key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
          restore-keys: ${{ runner.os }}-pip-

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install libsdl2-dev
          sudo apt-get install python-sphinx
          python -m pip install --upgrade poetry
          poetry config virtualenvs.create false
          poetry install --no-root

      - name: build-docs
        run: |
          sphinx-apidoc -o ./docs .
          cd docs
          sphinx-build -a -E --keep-going . _build
          
      - name: deploy-docs
        uses: JamesIves/github-pages-deploy-action@3.5.7
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BRANCH: gh-pages
          FOLDER: docs/_build

Any help would be appeciated!

Your code was referencing a directory that does not exist.

sent you a PR to correct this.

Fix:

git mv data/Game data/temp

git mv data/temp data/game

git commit -m "Rename folder Game to game"

Hope that’s helpful :v:t4:

2 Likes

Thank you, mate, I have no idea why it was ever Game instead of game!

The PR seems to have fixed that issue (thank you!) but generated a new one. I’ve not seen anything like that before, have you?

ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default
File "/home/runner/work/notquiteparadise/notquiteparadise/scripts/engine/ui/manager.py", line 65, in __init__
    self._window: pygame.display = pygame.display.set_mode((self._desired_width, self._desired_height))
pygame.error: No available video device

If that’s from the Actions build, too, I’d guess it’s tests having issues with the runner VMs not having displays and sound cards. Could you run tests in a headless mode? If not you might need to set up some sort of emulation.

1 Like

I think all the tests are headless but given this is just to build documentation I would have thought it was all headless anyway.

I checked the pygame repo for their CI build and it flags video drivers so perhaps I need to do that, too. They’re using Travis so I need to check if there is anything that wouldn’t apply to Actions. https://github.com/pygame/pygame/blob/d43040e3825535bb543d72a270f1fa3a591875aa/.travis.yml

That depends: As noted in the documentation the call to sphinx-apidoc will import the modules, and side-effects of the imports will be executed. So if, for example, any of your modules tries to initialize display access during import that won’t work headless, similar for audio. The pygame.display.set_mode() call hints at something like that.

If that is indeed the issue the ideal fix would be to change the module so that display and audio initialization is done only when any related code is called.

1 Like

Ah, I am with you. That makes sense and it gives me a clear way forward. Thank you very much. I’ll refactor to avoid those sort of calls and see how it goes.

1 Like

Legend, that did it! Thank you again!

1 Like

Nice, thanks for the update! :smile_cat: