From c54717e917c3ace01228ba1409cfa6823c465405 Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Tue, 9 Jun 2026 15:34:43 -0400 Subject: [PATCH 1/2] docs: refresh all docs for embedded-python runtime layer and offline install - README: new technical section on embedded CPython / osgeo_utils, offline air-gapped install instructions, PYTHONPATH in activation list - vignette: embedded-python algorithm example (driver gpkg validate) and offline install section - AGENTS.md: bundle contract includes python/osgeo_utils and PYTHONPATH - dev/docs: align overview, ci/release, runtime api, troubleshooting, and toolchain notes with current bundle contents and smoke tests; remove references to nonexistent tools/audit_gdal_bundle.ps1; add osgeo_utils ModuleNotFoundError triage entry - roxygen: document offline install path for install_gdal_runtime() (#5) --- AGENTS.md | 7 ++-- R/gdal_runtime.R | 16 +++++++++ README.md | 58 ++++++++++++++++++++++++++++++-- dev/docs/01-overview.md | 4 +-- dev/docs/03-ci-and-release.md | 17 +++++++--- dev/docs/04-r-runtime-api.md | 4 +++ dev/docs/05-troubleshooting.md | 25 ++++++++++++-- dev/docs/06-toolchain-and-abi.md | 32 +++++++++++++++++- man/install_gdal_runtime.Rd | 17 ++++++++++ vignettes/runtime-guide.Rmd | 38 +++++++++++++++++++++ 10 files changed, 205 insertions(+), 13 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0326461..10cf58d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,11 +40,14 @@ gdalraster::gdal_global_reg_names() - a top-level GDAL runtime DLL (`libgdal-*.dll`) - all required non-Windows dependent DLLs - required runtime data directories (`share/gdal`, `share/proj`) + - pure-python GDAL utilities (`python/osgeo_utils`) for embedded-python + algorithms (e.g. `gdal driver gpkg validate`) 4. Build `gdalraster` from source against that bundled GDAL runtime. 5. Ensure runtime loading is configured so `gdalraster` resolves bundled DLL dependencies at runtime (without relying on a matching user-installed - Rtools environment). -6. Verify success with `gdalraster::gdal_global_reg_names()` returning non-empty output. + Rtools environment), and so GDAL's embedded python can import bundled + `osgeo_utils` (session-scoped `PYTHONPATH`). +6. Verify success with `gdalraster::gdal_global_reg_names()` returning non-empty output and the `driver gpkg validate` algorithm running end-to-end. 7. Keep installs non-destructive by default: - runtime installs under package-managed user data paths - source builds target an isolated library path unless explicitly overridden diff --git a/R/gdal_runtime.R b/R/gdal_runtime.R index bda28b7..5e2a44d 100644 --- a/R/gdal_runtime.R +++ b/R/gdal_runtime.R @@ -52,6 +52,22 @@ configure_gdal_home <- function(path, mode = c("option", "env")) { #' #' The selected zip must contain a GDAL root with `bin/libgdal-*.dll`. #' +#' @section Offline / air-gapped installation: +#' On machines without network access, download the release asset manually +#' from , transfer it +#' to the target machine, and install directly: +#' +#' ```r +#' gdalraster.windows::install_gdal_runtime( +#' local_zip = "C:/Downloads/gdal-ucrt64-v3.13.0-windows-x64.zip" +#' ) +#' ``` +#' +#' Note the packaged `fallback_zip` default +#' (`inst/extdata/gdal-ucrt64-fallback.zip`) is not shipped with the package +#' (a full runtime bundle is too large to vendor); the fallback path only +#' applies when you provide a `fallback_zip` yourself. +#' #' @param repo GitHub repo slug, e.g. `"jimbrig/gdalraster.windows"`. #' @param tag Release tag or `"latest"`. #' @param asset_pattern Regex used to select the release asset. diff --git a/README.md b/README.md index b2c936c..fd76447 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,25 @@ library(gdalraster.windows) gdalraster::gdal_global_reg_names() ``` +## Offline / Air-Gapped Installation + +`install_gdal_runtime()` downloads the runtime bundle from GitHub Releases by +default. On machines without network access (or to pin an exact asset), pass a +local zip directly: + +```r +# 1) download the release asset on a connected machine: +# https://github.com/jimbrig/gdalraster.windows/releases +# 2) transfer to the target machine +# 3) install from the local zip +gdalraster.windows::install_gdal_runtime( + local_zip = "C:/Downloads/gdal-ucrt64-v3.13.0-windows-x64.zip" +) +``` + +A `fallback_zip` argument is also supported: when a release download fails and +a fallback zip exists, it is installed instead. + ## Common Flows If runtime and custom `gdalraster` install are already present: @@ -170,6 +189,7 @@ needs to resolve `libgdal-*.dll` and its dependency tree in the active process. - prepending bundle `bin/` to `PATH` - setting GDAL/PROJ data env vars +- prepending bundle `python/` to `PYTHONPATH` (see section 9) - optionally preloading `libgdal-*.dll` with `dyn.load(..., local = FALSE, now = TRUE)` This is why explicit runtime activation exists in addition to source builds. @@ -188,7 +208,41 @@ succeeds. from the installed bundle when available. -### 9) Compile-time paths vs runtime paths +### 9) Embedded Python utilities (`osgeo_utils`) + +Some GDAL CLI algorithms are implemented in Python rather than C++. For +example, `gdal driver gpkg validate` is a thin C++ entry point in `libgdal` +that embeds a CPython interpreter at runtime: GDAL locates a `python.exe` on +`PATH`, dynamically loads the matching `libpython` DLL, calls +`Py_Initialize()`, and imports `osgeo_utils.samples.validate_gpkg`. + +`osgeo_utils` is the pure-Python package shipped by GDAL's `gdal-utils` +distribution (`swig/python/gdal-utils/` in the GDAL source tree). Because it +contains no compiled extension modules, it has no CPython ABI coupling — any +embedded interpreter version can import it. + +The runtime bundle ships this package under `python/osgeo_utils`, +version-locked to the built GDAL tag. `activate_gdal_runtime()` prepends +`/python` to `PYTHONPATH` (session-scoped; never persisted to user +or machine environment) so the embedded interpreter can resolve it. +`PYTHONPATH` is read at `Py_Initialize()`, which `libgdal` triggers lazily on +first use of an embedded-python algorithm, so activation-time configuration is +early enough. + +Without this, such algorithms fail with: + +```text +GDAL FAILURE 1: ... ModuleNotFoundError: No module named 'osgeo_utils' +``` + +Note: the compiled `osgeo` SWIG bindings (`from osgeo import gdal`) are +intentionally **not** built or bundled (`BUILD_PYTHON_BINDINGS` stays off — +no Python/SWIG in the build environment). They would pin the bundle to a +single CPython version/ABI. The Python-implemented validators degrade +gracefully without them (e.g. `validate_gpkg` skips only tiled gridded +coverage checks). + +### 10) Compile-time paths vs runtime paths These are separate concerns: @@ -198,7 +252,7 @@ These are separate concerns: This package scopes compile-time settings to install calls (`withr`), then manages runtime activation separately for session reliability. -### 10) Optional `.Rprofile` startup hook +### 11) Optional `.Rprofile` startup hook For users who want persistence, `add_gdal_rprofile_hook()` writes a managed startup block that can load runtime context early in each session. diff --git a/dev/docs/01-overview.md b/dev/docs/01-overview.md index 0c50630..423e22c 100644 --- a/dev/docs/01-overview.md +++ b/dev/docs/01-overview.md @@ -34,8 +34,8 @@ This project closes that gap with a custom GDAL build and distribution pipeline, ## high-level flow -1. CI compiles GDAL and assembles `gdal-bundle/` (`bin`, `include`, `lib`, `share`). -2. CI verifies `gdalraster` source builds against that bundle and validates Algorithm API availability. +1. CI compiles GDAL and assembles `gdal-bundle/` (`bin`, `include`, `lib`, `share`, `python`). +2. CI verifies `gdalraster` source builds against that bundle, validates Algorithm API availability, and runs the embedded-python `driver gpkg validate` algorithm end-to-end. 3. End users install runtime locally, source-build `gdalraster`, then activate/load through helper APIs. ## upstream status snapshot diff --git a/dev/docs/03-ci-and-release.md b/dev/docs/03-ci-and-release.md index 99fd73f..d7d4593 100644 --- a/dev/docs/03-ci-and-release.md +++ b/dev/docs/03-ci-and-release.md @@ -22,12 +22,17 @@ Triggers: - configures MSYS2 `UCRT64` - restores/saves GDAL build cache keyed to version and script hash -- runs [`tools/build_gdal.sh`](../../tools/build_gdal.sh) -- runs [`tools/collect_dlls.sh`](../../tools/collect_dlls.sh) +- runs [`tools/build_gdal.sh`](../../tools/build_gdal.sh) (also stages + pure-python `osgeo_utils` from the GDAL source tree into the install prefix) +- runs [`tools/collect_dlls.sh`](../../tools/collect_dlls.sh) (carries + `python/` into the bundle alongside `bin`, `include`, `lib`, `share`) - verifies runtime bundle integrity - uploads intermediate artifact for downstream job - on tag builds, publishes runtime bundle zip to GitHub release +note: release publication happens inside job 1, so a job 2 failure can leave a +published release asset alongside a red workflow run. + ### job 2: `verify-gdalraster-build` - installs R and Rtools45 @@ -35,6 +40,8 @@ Triggers: - writes `Makevars.win` to point source compilation at bundled GDAL headers/libs - builds `gdalraster` Windows binary from source - runs smoke test for GDAL load and algorithm registry presence +- runs embedded-python smoke test: creates a GeoPackage, sets `PYTHONPATH` to + the bundle `python/` dir, runs `driver gpkg validate`, asserts success - uploads verification artifact ## release artifacts to expect @@ -44,8 +51,10 @@ Triggers: ## local rehearsal tools -- [`tools/audit_gdal_bundle.ps1`](../../tools/audit_gdal_bundle.ps1): inspect and repair local bundle dependency state -- outputs `.audit` reports under selected bundle path +- `ntldd -R /bin/libgdal-*.dll` (from an MSYS2/Rtools shell): + inspect the transitive DLL dependency tree of a local bundle +- a dedicated bundle audit script (`tools/audit_gdal_bundle.ps1`) is planned + but not yet present in the repository ## common CI maintenance tasks diff --git a/dev/docs/04-r-runtime-api.md b/dev/docs/04-r-runtime-api.md index 7838dca..8582938 100644 --- a/dev/docs/04-r-runtime-api.md +++ b/dev/docs/04-r-runtime-api.md @@ -36,7 +36,11 @@ Configures runtime home for current session via: - ensures runtime paths/files exist - prepends runtime `bin` directory to `PATH` - sets `GDAL_DATA`, `PROJ_LIB`, and `PROJ_DATA` when available +- prepends runtime `python` directory to `PYTHONPATH` when available + (exposes bundled pure-python `osgeo_utils` to GDAL's embedded python) - optionally preloads `libgdal-*.dll` discovered in runtime `bin/` +- invisibly returns a list of configured paths + (`gdal_home`, `gdal_bin`, `gdal_dll`, `gdal_data`, `proj_data`, `gdal_python`) ### `load_gdal_dll(gdal_home = default_gdal_home(), quiet = FALSE)` diff --git a/dev/docs/05-troubleshooting.md b/dev/docs/05-troubleshooting.md index c457ed4..1731082 100644 --- a/dev/docs/05-troubleshooting.md +++ b/dev/docs/05-troubleshooting.md @@ -9,8 +9,8 @@ - `gdalraster.windows::activate_gdal_runtime()` 3. verify behavior: - `gdalraster.windows::verify_gdalraster_runtime()` -4. if still failing, audit bundle: - - [`tools/audit_gdal_bundle.ps1`](../../tools/audit_gdal_bundle.ps1) +4. if still failing, audit the bundle dependency tree: + - `ntldd -R /bin/libgdal-*.dll` from an MSYS2/Rtools shell Quick checks in R: @@ -52,6 +52,27 @@ Example: Rscript -e "gdalraster.windows::activate_gdal_runtime(); library(gdalraster); print(length(gdalraster::gdal_global_reg_names()))" ``` +### embedded-python algorithm fails with `ModuleNotFoundError: No module named 'osgeo_utils'` + +Applies to GDAL algorithms implemented in Python, e.g. `driver gpkg validate`. + +Most likely: + +- runtime bundle predates `python/osgeo_utils` support +- `PYTHONPATH` was not set in this session (activation did not run) + +First actions: + +- check `dir.exists(file.path(gdalraster.windows::gdal_home(), "python", "osgeo_utils"))`; + if missing, reinstall: `install_gdal_runtime(overwrite = TRUE)` +- run `activate_gdal_runtime()` and confirm + `Sys.getenv("PYTHONPATH")` contains `/python` +- confirm a `python.exe` is discoverable on `PATH` (GDAL needs one to embed an + interpreter; the GDAL debug stream shows which python/libpython it loads) + +Note: `validate_gpkg` treats the compiled `osgeo` bindings as optional; without +them it still runs all checks except tiled gridded coverage content checks. + ### install/test-load fails but manual session works Most likely: diff --git a/dev/docs/06-toolchain-and-abi.md b/dev/docs/06-toolchain-and-abi.md index ca55816..079f675 100644 --- a/dev/docs/06-toolchain-and-abi.md +++ b/dev/docs/06-toolchain-and-abi.md @@ -99,13 +99,42 @@ transitive non-Windows dependencies are available. `tools/collect_dlls.sh` does this by: -1. collecting primary GDAL install outputs (`bin`, `include`, `lib`, `share`) +1. collecting primary GDAL install outputs (`bin`, `include`, `lib`, `share`, `python`) 2. recursively inspecting dependencies with `ntldd -R` 3. copying required `/ucrt64` DLLs into bundle `bin/` 4. failing if unresolved non-Windows dependencies remain This closure check is one of the main safety guarantees in this repository. +## embedded python layer (osgeo_utils) + +Some GDAL CLI algorithms (e.g. `gdal driver gpkg validate`) are thin C++ +entry points around Python implementations. The mechanism in `libgdal`: + +1. locate a `python.exe` on `PATH` and the corresponding `libpython` DLL +2. load it dynamically (`LoadLibrary`, not an import-table dependency — + `libgdal` has no static link against CPython) +3. call `Py_Initialize()` lazily on first use +4. import the needed module, e.g. `osgeo_utils.samples.validate_gpkg` + +Implications for this repository: + +- `osgeo_utils` (GDAL's `gdal-utils` distribution, pure python) must be on the + embedded interpreter's `sys.path`. `build_gdal.sh` stages it from the GDAL + source checkout (version-locked) into `/python`, and + `activate_gdal_runtime()` prepends `/python` to `PYTHONPATH`. +- because the package is pure python (no `.pyd` extension modules), it has no + CPython version/ABI coupling — any embedded interpreter can import it. +- the compiled SWIG bindings (`osgeo` with `_gdal.pyd` etc.) are deliberately + not built (`BUILD_PYTHON_BINDINGS` is effectively off: no python/swig in the + CI build environment). Shipping them would pin the bundle to one CPython + ABI and require the bundled `osgeo` to resolve this repo's `libgdal-*.dll` + at import time. Python-implemented validators degrade gracefully without + them (`has_gdal = False` path in `validate_gpkg`). +- `PYTHONPATH` handling stays session-scoped: it leaks into no other python + environments (pixi/conda/system), and within an R session it only adds a + directory containing `osgeo_utils`. + ## compile-time vs runtime paths ### compile-time @@ -122,6 +151,7 @@ dependencies. `activate_gdal_runtime()` handles this by: - prepending `/bin` to `PATH` - setting `GDAL_DATA`, `PROJ_LIB`, `PROJ_DATA` +- prepending `/python` to `PYTHONPATH` (embedded-python algorithms) - optionally preloading the GDAL DLL via `dyn.load()` Compile-time success does not guarantee runtime success without this step. diff --git a/man/install_gdal_runtime.Rd b/man/install_gdal_runtime.Rd index b4b5c6b..bfaf611 100644 --- a/man/install_gdal_runtime.Rd +++ b/man/install_gdal_runtime.Rd @@ -45,3 +45,20 @@ Installs the GDAL runtime into \code{gdal_home} from one of: The selected zip must contain a GDAL root with \verb{bin/libgdal-*.dll}. } +\section{Offline / air-gapped installation}{ + +On machines without network access, download the release asset manually +from \url{https://github.com/jimbrig/gdalraster.windows/releases}, transfer it +to the target machine, and install directly: + +\if{html}{\out{
}}\preformatted{gdalraster.windows::install_gdal_runtime( + local_zip = "C:/Downloads/gdal-ucrt64-v3.13.0-windows-x64.zip" +) +}\if{html}{\out{
}} + +Note the packaged \code{fallback_zip} default +(\code{inst/extdata/gdal-ucrt64-fallback.zip}) is not shipped with the package +(a full runtime bundle is too large to vendor); the fallback path only +applies when you provide a \code{fallback_zip} yourself. +} + diff --git a/vignettes/runtime-guide.Rmd b/vignettes/runtime-guide.Rmd index 5939b48..657985d 100644 --- a/vignettes/runtime-guide.Rmd +++ b/vignettes/runtime-guide.Rmd @@ -53,6 +53,44 @@ gdalraster.windows::load_gdalraster() gdalraster::gdal_global_reg_names() ``` +## Offline / air-gapped install + +Download the release asset from + on a connected +machine, transfer it, then: + +```{r eval = FALSE} +gdalraster.windows::install_gdal_runtime( + local_zip = "C:/Downloads/gdal-ucrt64-v3.13.0-windows-x64.zip" +) +``` + +## Embedded-python algorithms + +Some GDAL algorithms (e.g. `gdal driver gpkg validate`) are implemented in +Python: `libgdal` embeds a CPython interpreter at runtime and imports the +pure-python `osgeo_utils` package. The runtime bundle ships that package under +`/python`, and `activate_gdal_runtime()` exposes it to the embedded +interpreter by prepending it to `PYTHONPATH` (session-scoped). + +```{r eval = FALSE} +library(gdalraster.windows) +library(gdalraster) + +alg <- gdalraster::gdal_alg(cmd = "driver gpkg validate") +alg$setArg("dataset", "path/to/file.gpkg") +alg$setArg("full-check", TRUE) +alg$run() +alg$output() +#> [1] "Checking gpkg_spatial_ref_sys\n...\nValidation succeeded" +``` + +A `python.exe` must be discoverable on `PATH` for GDAL to embed an +interpreter (Rtools' UCRT64 python works, as does any system python). +If such an algorithm fails with `ModuleNotFoundError: No module named +'osgeo_utils'`, the runtime bundle predates python support — reinstall with +`install_gdal_runtime(overwrite = TRUE)` and re-activate. + ## Default install behavior By default: From a69ed0f08be46b9b737375459c1865ed8b0c179e Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Tue, 9 Jun 2026 15:49:02 -0400 Subject: [PATCH 2/2] docs: address review feedback - clarify fallback_zip default, namespace-qualify troubleshooting calls --- R/gdal_runtime.R | 11 ++++++----- dev/docs/05-troubleshooting.md | 4 ++-- man/install_gdal_runtime.Rd | 11 ++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/R/gdal_runtime.R b/R/gdal_runtime.R index 5e2a44d..1c0fd14 100644 --- a/R/gdal_runtime.R +++ b/R/gdal_runtime.R @@ -63,10 +63,9 @@ configure_gdal_home <- function(path, mode = c("option", "env")) { #' ) #' ``` #' -#' Note the packaged `fallback_zip` default -#' (`inst/extdata/gdal-ucrt64-fallback.zip`) is not shipped with the package -#' (a full runtime bundle is too large to vendor); the fallback path only -#' applies when you provide a `fallback_zip` yourself. +#' Note that no fallback zip is shipped with the package (a full runtime +#' bundle is too large to vendor), so the fallback path only applies when you +#' provide a `fallback_zip` yourself. #' #' @param repo GitHub repo slug, e.g. `"jimbrig/gdalraster.windows"`. #' @param tag Release tag or `"latest"`. @@ -75,7 +74,9 @@ configure_gdal_home <- function(path, mode = c("option", "env")) { #' @param overwrite Whether to replace existing `gdal_home`. #' @param local_zip Optional local GDAL runtime zip to install directly. #' @param fallback_zip Optional fallback zip path used when release download -#' fails. Defaults to package file `inst/extdata/gdal-ucrt64-fallback.zip`. +#' fails. When `NULL` (default), a vendored zip at +#' `inst/extdata/gdal-ucrt64-fallback.zip` is used if present; none ships +#' with the package, so by default no fallback is attempted. #' #' @return Invisibly returns installed GDAL home path. #' @export diff --git a/dev/docs/05-troubleshooting.md b/dev/docs/05-troubleshooting.md index 1731082..63e4c9d 100644 --- a/dev/docs/05-troubleshooting.md +++ b/dev/docs/05-troubleshooting.md @@ -64,8 +64,8 @@ Most likely: First actions: - check `dir.exists(file.path(gdalraster.windows::gdal_home(), "python", "osgeo_utils"))`; - if missing, reinstall: `install_gdal_runtime(overwrite = TRUE)` -- run `activate_gdal_runtime()` and confirm + if missing, reinstall: `gdalraster.windows::install_gdal_runtime(overwrite = TRUE)` +- run `gdalraster.windows::activate_gdal_runtime()` and confirm `Sys.getenv("PYTHONPATH")` contains `/python` - confirm a `python.exe` is discoverable on `PATH` (GDAL needs one to embed an interpreter; the GDAL debug stream shows which python/libpython it loads) diff --git a/man/install_gdal_runtime.Rd b/man/install_gdal_runtime.Rd index bfaf611..5b6ee0b 100644 --- a/man/install_gdal_runtime.Rd +++ b/man/install_gdal_runtime.Rd @@ -28,7 +28,9 @@ install_gdal_runtime( \item{local_zip}{Optional local GDAL runtime zip to install directly.} \item{fallback_zip}{Optional fallback zip path used when release download -fails. Defaults to package file \code{inst/extdata/gdal-ucrt64-fallback.zip}.} +fails. When \code{NULL} (default), a vendored zip at +\code{inst/extdata/gdal-ucrt64-fallback.zip} is used if present; none ships +with the package, so by default no fallback is attempted.} } \value{ Invisibly returns installed GDAL home path. @@ -56,9 +58,8 @@ to the target machine, and install directly: ) }\if{html}{\out{}} -Note the packaged \code{fallback_zip} default -(\code{inst/extdata/gdal-ucrt64-fallback.zip}) is not shipped with the package -(a full runtime bundle is too large to vendor); the fallback path only -applies when you provide a \code{fallback_zip} yourself. +Note that no fallback zip is shipped with the package (a full runtime +bundle is too large to vendor), so the fallback path only applies when you +provide a \code{fallback_zip} yourself. }