Skip to content

Commit

Permalink
fix: handling gdal dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
vschaffn committed Nov 21, 2024
1 parent b9fe77a commit f9f0bf9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
48 changes: 41 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ ifndef VENV
endif

# Python version requirement
PYTHON_VERSION_MIN = 3.9
PYTHON_VERSION_REQUIRED = 3.10

ifndef PYTHON
PYTHON = "python3"
# Try to find python version required
PYTHON = "python$(PYTHON_VERSION_REQUIRED)"
endif
PYTHON_CMD=$(shell command -v $(PYTHON))

PYTHON_VERSION_CUR=$(shell $(PYTHON_CMD) -c 'import sys; print("%d.%d" % sys.version_info[0:2])')
PYTHON_VERSION_OK=$(shell $(PYTHON_CMD) -c 'import sys; cur_ver = sys.version_info[0:2]; min_ver = tuple(map(int, "$(PYTHON_VERSION_MIN)".split("."))); print(int(cur_ver >= min_ver))')
PYTHON_VERSION_OK=$(shell $(PYTHON_CMD) -c 'import sys; req_ver = tuple(map(int, "$(PYTHON_VERSION_REQUIRED)".split("."))); cur_ver = sys.version_info[0:2]; print(int(cur_ver == req_ver))')

############### Check python version supported ############

Expand All @@ -29,7 +30,7 @@ ifeq (, $(PYTHON_CMD))
endif

ifeq ($(PYTHON_VERSION_OK), 0)
$(error "Requires python version >= $(PYTHON_VERSION_MIN). Current version is $(PYTHON_VERSION_CUR)")
$(error "Requires Python version == $(PYTHON_VERSION_REQUIRED). Current version is $(PYTHON_VERSION_CUR)")
endif

################ MAKE Targets ######################
Expand All @@ -44,19 +45,52 @@ venv: ## Create a virtual environment in 'venv' directory if it doesn't exist
@touch ${VENV}/bin/activate
@${VENV}/bin/python -m pip install --upgrade wheel setuptools pip

.PHONY: install-gdal
install-gdal: install-system-gdal ## Install GDAL version matching the system's GDAL via pip
@GDAL_VERSION=$$(gdalinfo --version | awk '{print $$2}') && \
echo "System GDAL version: $$GDAL_VERSION" && \
${VENV}/bin/pip install gdal==$$GDAL_VERSION

.PHONY: install-system-gdal
install-system-gdal: ## Install GDAL system-wide using the system's package manager
@echo "Checking for system-wide GDAL installation..."
@if command -v gdalinfo >/dev/null 2>&1; then \
echo "GDAL is already installed."; \
else \
echo "GDAL not found. Installing it using the system's package manager..."; \
if [ "$(shell uname -s)" = "Linux" ]; then \
if [ -f /etc/debian_version ]; then \
echo "Detected Debian/Ubuntu. Installing GDAL..."; \
sudo apt-get update && sudo apt-get install -y gdal-bin libgdal-dev; \
elif [ -f /etc/redhat-release ]; then \
echo "Detected Red Hat/CentOS. Installing GDAL..."; \
sudo yum install -y gdal gdal-devel; \
else \
echo "Unsupported Linux distribution. Please install GDAL manually."; \
exit 1; \
fi; \
else \
echo "Unsupported operating system. Please install GDAL manually."; \
exit 1; \
fi; \
fi
@echo "System-wide GDAL installation completed or confirmed."

.PHONY: install
install: venv ## Install xDEM for development (depends on venv)
@test -f ${VENV}/bin/xdem || echo "Installing xdem in development mode"
@test -f ${VENV}/bin/xdem || ${VENV}/bin/pip install -e .[dev]
@test -f .git/hooks/pre-commit || echo "Installing pre-commit hooks"
@test -f .git/hooks/pre-commit || ${VENV}/bin/pre-commit install -t pre-commit
@test -f .git/hooks/pre-push || ${VENV}/bin/pre-commit install -t pre-push
@echo "Attempting to install GDAL..."
@make install-gdal || echo "GDAL installation failed. Processing without GDAL."
@echo "XDEM installed in development mode in virtualenv ${VENV}"
@echo "To use: source ${VENV}/bin/activate; xdem -h"

#.PHONY: test
#test: ## run tests
# @${VENV}/bin/pytest
.PHONY: test
test: ## run tests
@${VENV}/bin/pytest

## Clean section

Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ test =
pylint
scikit-learn
richdem
gdal
doc =
sphinx
sphinx-book-theme
Expand All @@ -77,6 +76,6 @@ dev =
pre-commit
%(opt)s
%(doc)s
%(test)s
all =
%(dev)s
%(test)s

0 comments on commit f9f0bf9

Please sign in to comment.