Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile initial installation #630

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ be reported by CoverAlls.

### Setup

#### With `mamba`
Clone the git repo and create a `mamba` environment (see how to install `mamba` in the [mamba documentation](https://mamba.readthedocs.io/en/latest/)):

```bash
Expand All @@ -38,6 +39,15 @@ mamba env create -f dev-environment.yml # Add '-n custom_name' if you want.
mamba activate xdem-dev # Or any other name specified above
```

#### With `pip`
```bash
git clone https://github.com/GlacioHack/xdem.git
cd xdem
make install
```

Please note: pip installation is currently only possible under python3.10.
rhugonnet marked this conversation as resolved.
Show resolved Hide resolved

### Tests

At least one test per feature (in the associated `tests/test_*.py` file) should be included in the PR, using `pytest` (see existing tests for examples).
Expand Down
112 changes: 112 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Autodocumented Makefile for xDEM
# see: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
# Dependencies : python3 venv

############### GLOBAL VARIABLES ######################
.DEFAULT_GOAL := help
SHELL := /bin/bash

# Virtualenv directory name (can be overridden)
ifndef VENV
VENV = "venv"
endif

# Python version requirement
PYTHON_VERSION_REQUIRED = 3.10

ifndef PYTHON
# 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; 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 ############

ifeq (, $(PYTHON_CMD))
$(error "PYTHON_CMD=$(PYTHON_CMD) not found in $(PATH)")
endif

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

################ MAKE Targets ######################

help: ## Show this help
@echo " XDEM MAKE HELP"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: venv
venv: ## Create a virtual environment in 'venv' directory if it doesn't exist
@test -d ${VENV} || $(PYTHON_CMD) -m venv ${VENV}
@touch ${VENV}/bin/activate
@${VENV}/bin/python -m pip install --upgrade wheel setuptools pip

.PHONY: install-gdal
install-gdal: ## Install GDAL version matching the system's GDAL via pip
@if command -v gdalinfo >/dev/null 2>&1; then \
GDAL_VERSION=$$(gdalinfo --version | awk '{print $$2}'); \
echo "System GDAL version: $$GDAL_VERSION"; \
${VENV}/bin/pip install gdal==$$GDAL_VERSION; \
else \
echo "Warning: GDAL not found on the system. Proceeding without GDAL."; \
echo "Try installing GDAL by running the following commands depending on your system:"; \
echo "Debian/Ubuntu: sudo apt-get install -y gdal-bin libgdal-dev"; \
echo "Red Hat/CentOS: sudo yum install -y gdal gdal-devel"; \
echo "Then run 'make install-gdal' to proceed with GDAL installation."; \
fi

.PHONY: install
install: venv ## Install xDEM for development (depends on venv)
@test -f ${VENV}/bin/xdem || echo "Installing xdem in development mode"
vschaffn marked this conversation as resolved.
Show resolved Hide resolved
@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 "xdem installed in development mode in virtualenv ${VENV}"
@echo "To use: source ${VENV}/bin/activate; xdem -h"
vschaffn marked this conversation as resolved.
Show resolved Hide resolved


.PHONY: test
test: ## run tests
@if ! ${VENV}/bin/python -m pip show gdal >/dev/null 2>&1; then \
echo "Error: GDAL is not installed in the virtual environment. Tests require GDAL to run."; \
echo "Please ensure GDAL is installed by running 'make install-gdal'."; \
exit 1; \
else \
${VENV}/bin/pytest; \
fi

## Clean section

.PHONY: clean
clean: clean-venv clean-build clean-pyc clean-precommit ## Clean all

.PHONY: clean-venv
clean-venv: ## Clean the virtual environment
@echo "+ $@"
@rm -rf ${VENV}

.PHONY: clean-build
clean-build: ## Remove build artifacts
@echo "+ $@"
@rm -rf build/ dist/ .eggs/
@find . -name '*.egg-info' -exec rm -rf {} +
@find . -name '*.egg' -exec rm -f {} +

.PHONY: clean-precommit
clean-precommit: ## Remove pre-commit hooks from .git/hooks
@rm -f .git/hooks/pre-commit
@rm -f .git/hooks/pre-push

.PHONY: clean-pyc
clean-pyc: ## Remove Python cache and artifacts
@echo "+ $@"
@find . -type f -name "*.py[co]" -exec rm -rf {} +
@find . -type d -name "__pycache__" -exec rm -rf {} +
@find . -name '*~' -exec rm -rf {} +
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ For a quick start, full feature description or search through the API, see xDEM'

## Installation

### With `mamba`

```bash
mamba install -c conda-forge xdem
```
See [mamba's documentation](https://mamba.readthedocs.io/en/latest/) to install `mamba`, which will solve your environment much faster than `conda`.

### With `pip`

```bash
pip install xdem
```

## Citing methods implemented in the package

When using a method implemented in xDEM, please **cite both the package and the related study**:
Expand Down
9 changes: 8 additions & 1 deletion dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ dependencies:
- scikit-image=0.*
- scikit-gstat>=1.0.18,<1.1
- geoutils=0.1.12
- affine
- pandas
- pyogrio
- shapely

# Development-specific, to mirror manually in setup.cfg [options.extras_require].
- pip

# Optional dependencies
- pytransform3d
- pyyaml
- scikit-learn

# Test dependencies
- gdal # To test against GDAL
Expand All @@ -28,7 +34,7 @@ dependencies:
- pyyaml
- flake8
- pylint
- richdem
- richdem # To test against richdem

# Doc dependencies
- sphinx
Expand All @@ -47,6 +53,7 @@ dependencies:
# Optional dependency
- -e ./

- noisyopt
# "Headless" needed for opencv to install without requiring system dependencies
- opencv-contrib-python-headless

Expand Down
11 changes: 11 additions & 0 deletions doc/source/how_to_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@ Updating packages with `pip` (and sometimes `mamba`) can break your installation

## Installing for contributors

### With ``mamba``

```bash
git clone https://github.com/GlacioHack/xdem.git
mamba env create -f xdem/dev-environment.yml
```

### With ``pip``

vschaffn marked this conversation as resolved.
Show resolved Hide resolved
Please note: pip installation is currently only possible under python3.10.

```bash
git clone https://github.com/GlacioHack/xdem.git
make install
```

After installing, you can check that everything is working by running the tests: `pytest`.
vschaffn marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ dependencies:
- scikit-gstat>=1.0.18,<1.1
- geoutils=0.1.12
- pip
- affine
- pandas
- pyogrio
- shapely

# To run CI against latest GeoUtils
# - pip:
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ scikit-image==0.*
scikit-gstat>=1.0.18,<1.1
geoutils==0.1.12
pip
affine
pandas
pyogrio
shapely
10 changes: 6 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ include =

[options.extras_require]
opt =
opencv
openh264
opencv-contrib-python-headless
pytransform3d
noisyopt
scikit-learn
pyyaml
test =
pytest
pytest-xdist
pyyaml
pre-commit
flake8
pylint
scikit-learn
richdem
doc =
sphinx
Expand All @@ -73,7 +75,7 @@ doc =
numpydoc
dev =
%(opt)s
%(test)s
vschaffn marked this conversation as resolved.
Show resolved Hide resolved
%(doc)s
%(test)s
all =
%(dev)s
Loading