Skip to content

Commit bc14708

Browse files
committed
trying to figure out how to get codespaces and gdal to be happy
1 parent 94d6a86 commit bc14708

6 files changed

Lines changed: 69 additions & 15 deletions

File tree

.devcontainer/bootstrap.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ wget https://raw.githubusercontent.com/Riverscapes/environment/master/nar-ys.zsh
44
wget https://raw.githubusercontent.com/Riverscapes/environment/master/.aliases -O ~/.aliases
55
wget https://raw.githubusercontent.com/Riverscapes/environment/master/.zshrc -O ~/.zshrc
66

7-
uv sync
7+
uv sync
8+
9+
# Install system GDAL and the matching Python gdal package.
10+
# The Python gdal version must match the system libgdal version, so it cannot
11+
# be pinned in pyproject.toml generically. We install it here explicitly.
12+
sudo apt-get update
13+
sudo apt-get install -y --no-install-recommends libgdal-dev gdal-bin
14+
bash install_geo.sh

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Data Excahnge Scripts",
55
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
6+
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm",
77
"features": {
88
"ghcr.io/va-h/devcontainers-features/uv:1": {}
99
},

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,41 @@ Running scripts this way will also allow you to drop breakpoints in your code an
6363

6464
## Optional Dependencies
6565

66-
This project includes optional dependencies for geospatial functionality. To install these dependencies, run:
66+
This project includes optional dependencies for geospatial functionality (e.g. `shapely`). Install them with:
6767

6868
```bash
6969
uv sync --extra geo
7070
```
7171

72-
This will install packages like `gdal` and `shapely`. Note that `gdal` may require additional system-level dependencies. On macOS, you can install `gdal` using Homebrew:
72+
### GDAL
7373

74+
`gdal` is **not** pinned in `pyproject.toml` because the Python package version must exactly match the system `libgdal` version, which varies per environment. Instead, use the provided helper script after installing system GDAL:
75+
76+
**Debian/Ubuntu (including Codespaces — requires Debian Bookworm / Ubuntu 22.04+ for Python 3.12 compatibility):**
77+
```bash
78+
sudo apt-get install -y libgdal-dev gdal-bin
79+
bash install_geo.sh
80+
```
81+
82+
> **Note:** Debian Bullseye (11) ships GDAL 3.2, which is incompatible with Python 3.12. The devcontainer uses Debian Bookworm (12) which provides GDAL 3.6+.
83+
84+
**macOS:**
7485
```bash
7586
brew install gdal
87+
bash install_geo.sh
7688
```
7789

90+
The `install_geo.sh` script calls `gdal-config --version` to detect the installed system GDAL version and installs the exactly matching `gdal` Python package into the active virtual environment.
91+
7892
## Codespace Instructions
7993

8094
1. Open the codespace "Riverscapes API Codespace."
8195
2. In VSCode, load the `RiverscapesAPI.code-workspace` workspace.
8296
3. Ensure the appropriate Python version is selected (e.g., `3.12.9 ('.venv')`).
8397

84-
### Codespace GDAL Limitation
98+
### Codespace GDAL
8599

86-
> NOTE: The codespace environment does not currently support scripts requiring GDAL (e.g. project merging). Run those locally.
100+
GDAL is installed automatically when the codespace is created (via `bootstrap.sh`). No extra steps needed — `gdal-config` will be available and `install_geo.sh` will have already run.
87101

88102
## Best Practices
89103

install_geo.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# Installs the GDAL Python package matching the currently installed system GDAL.
3+
#
4+
# Usage:
5+
# bash install_geo.sh
6+
#
7+
# Prerequisites (run once per machine/codespace before this script):
8+
# Debian/Ubuntu: sudo apt-get install -y libgdal-dev gdal-bin
9+
# macOS: brew install gdal
10+
# Windows: install OSGeo4W or download GDAL binaries from https://www.gisinternals.com/
11+
12+
set -euo pipefail
13+
14+
if ! command -v gdal-config &>/dev/null; then
15+
echo "ERROR: gdal-config not found."
16+
echo "Please install the system GDAL development libraries first:"
17+
echo " Debian/Ubuntu: sudo apt-get install -y libgdal-dev gdal-bin"
18+
echo " macOS: brew install gdal"
19+
exit 1
20+
fi
21+
22+
GDAL_VERSION=$(gdal-config --version)
23+
echo "System GDAL version: ${GDAL_VERSION}"
24+
25+
# GDAL < 3.3 Python bindings use the deprecated 'use_2to3' setuptools feature,
26+
# which was removed in setuptools 58+ and is incompatible with Python 3.12.
27+
MAJOR=$(echo "${GDAL_VERSION}" | cut -d. -f1)
28+
MINOR=$(echo "${GDAL_VERSION}" | cut -d. -f2)
29+
if [[ "${MAJOR}" -lt 3 ]] || [[ "${MAJOR}" -eq 3 && "${MINOR}" -lt 3 ]]; then
30+
echo "ERROR: System GDAL ${GDAL_VERSION} is too old. Python 3.12 requires GDAL >= 3.3."
31+
echo "Debian Bullseye only ships GDAL 3.2 — upgrade to Debian Bookworm (or use a"
32+
echo "newer apt source) to get a compatible GDAL version."
33+
exit 1
34+
fi
35+
36+
echo "Installing Python gdal==${GDAL_VERSION} into the current environment..."
37+
uv pip install "gdal==${GDAL_VERSION}"
38+
39+
echo "Done. GDAL Python package installed successfully."

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ dependencies = [
3838

3939
[project.optional-dependencies]
4040
geo = [
41-
"gdal==3.11.4",
4241
"shapely>=2.1.1",
4342
]
43+
# NOTE: gdal is intentionally excluded from the geo extra because the Python
44+
# gdal package version must exactly match the system libgdal version, which
45+
# varies per developer environment. Use `install_geo.sh` to install gdal.
4446

4547
[tool.setuptools]
4648
include-package-data = true

uv.lock

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)