readthedocs / readthedocs.org

The source code that powers readthedocs.org
https://readthedocs.org/
MIT License
7.99k stars 3.58k forks source link

Feature request: provide libgdal/libgeos inside the build container #8160

Closed vdboor closed 3 years ago

vdboor commented 3 years ago

Currently it's hard to build autodoc files for projects that use GDAL. This affects all GeoDjango projects / django.contrib.gis imports.

The proposed solution to use autodoc_mock_imports doesn't work here. Before it's applied, the django setup already imports the real module. I've failed to move django.setup() after de autodoc initialization, even when using Sphinx events. Plus, the mock breaks other imports in a different way.

My current workaround is adding this to docs/source/conf.py:

import os
import sys 

import django
from sphinx.ext.autodoc.mock import _MockModule

sys.path.insert(0, os.path.abspath("../../src"))
os.environ["DJANGO_SETTINGS_MODULE"] = "myproject.settings"

# GDAL is not part of the build container
# The workaround to use 'autodoc_mock_imports' doesn't work either, and is applied too late.
# Instead, the internal machinery of 'autodoc_mock_imports' is reused here to avoid GDAL imports.

class GDALMockModule(_MockModule):
    GDAL_VERSION = (0, 0)

sys.modules["django.contrib.gis.geos.libgeos"] = _MockModule("django.contrib.gis.geos.libgeos")
sys.modules["django.contrib.gis.gdal.libgdal"] = GDALMockModule("django.contrib.gis.gdal.libgdal")

django.setup()

Since GDAL is a common dependency for any GIS-related project, could you consider adding it by default in the project?

stsewd commented 3 years ago

Hi @vdboor is this the package https://packages.ubuntu.com/hirsute/gdal-bin? Soon you'll be able to install this from a config file https://github.com/readthedocs/readthedocs.org/pull/8065. Also, looks like you can use conda https://gdal.org/download.html#conda

vdboor commented 3 years ago

@stsewd This concerns libgdal20 and libproj12. Both are libraries who are directly used via ctypes (in Django at least)

Behind able to install apt-packages would definitely fix the build issue! Both are part of the standard Ubuntu/Debian package repo's

stsewd commented 3 years ago

https://github.com/readthedocs/readthedocs.org/pull/8065 should be live by next tuesday. You would need to use a config file like

version: 2

build:
   apt_packages:
      - libgdal20
      - libproj12