-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathMakefile
159 lines (123 loc) · 5.03 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/make
# 2024 Nicolas Gampierakis
LIBNAME=cosipy
ifeq (, $(shell which python ))
$(error "PYTHON=$(PYTHON) not found in $(PATH)")
endif
PYTHON=$(shell which python)
PYTHON_VERSION=$(shell $(PYTHON) -c "import sys;\
version='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));\
sys.stdout.write(version)")
PYTHON_CHECK_MAJOR=$(shell $(PYTHON) -c 'import sys;\
print(int(float("%d"% sys.version_info.major) >= 3))')
PYTHON_CHECK_MINOR=$(shell $(PYTHON) -c 'import sys;\
print(int(12 >= float("%d"% sys.version_info.minor) >= 9))' )
PYTHON_SOURCES=src/$(LIBNAME)/[a-z]*.py
TEST_SOURCES=tests/[a-z]*.py
DOCS_SOURCES=docs
LOG_DATE=$(shell date +%Y%m%d_%H%M%S)
.PHONY: help
help: ## Display this help screen
@grep -hE '^[A-Za-z0-9_ \-]*?:.*##.*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: install
install: install-conda-env ## Install editable package using conda/mamba
@echo "\nInstalling editable..."
@pip install -e .
install-conda-env: --check-python --hook-manager ## Install conda/mamba dependencies
@echo "\nInstalling dependencies (core)..."
@$(pkg-manager) install --file conda_requirements.txt -c conda-forge
install-pip: ## Install editable package using pip
@echo "\nInstalling editable..."
$(PYTHON) -m pip install --upgrade gdal==`gdal-config --version` pybind11
$(PYTHON) -m pip install -e .
install-pip-tests: install-pip ## Install editable package with tests using pip
@echo "\nInstalling editable with tests..."
$(PYTHON) -m pip install --upgrade gdal==`gdal-config --version` pybind11
@pip install -e .[tests]
install-pip-docs: ## Install editable package with local documentation using pip
@echo "\nInstalling editable with documentation..."
$(PYTHON) -m pip install --upgrade gdal==`gdal-config --version` pybind11
@pip install -e .[docs]
@make docs
install-pip-all: ## Install editable package with tests & documentation using pip
@echo "\nInstalling editable with tests & documentation..."
$(PYTHON) -m pip install --upgrade gdal==`gdal-config --version` pybind11
@pip install -e .[tests,docs]
@make docs
install-pip-dev: --check-python --hook-manager ## Install editable package in development mode using pip
@echo "\nInstalling editable in development mode..."
$(PYTHON) -m pip install --upgrade gdal==`gdal-config --version` pybind11
@pip install -e .[dev]
.PHONY: tests
tests: flake8 coverage pylint ## Run tests
.PHONY: commit
commit: tests ## Test, then commit
@echo "\nCommitting..."
@git commit
.PHONY: docs
docs: ## Build documentation
@echo "\nBuilding documentation..."
@cd $(DOCS_SOURCES); make clean && make html
format: isort black ## Format all python files
setup-cosipy: ## Generate COSIPY configuration files
@$(PYTHON) -m cosipy.utilities.setup_cosipy.setup_cosipy
create-static:
@$(PYTHON) -m cosipy.utilities.createStatic.create_static_file
commands: ## Display help for COSIPY
@$(PYTHON) -m COSIPY.py -h
.PHONY: run
run: commands ## Alias for `make commands`
flake8: ## Lint with flake8
@echo "\nLinting with flake8..."
@flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
@flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
.PHONY: coverage
coverage: ## Run pytest with coverage
@echo "\nRunning tests..."
@mkdir -p "./logs/coverage"
@coverage run --rcfile .coveragerc -m pytest && coverage html
.PHONY: pylint
pylint: ## Lint with Pylint
@echo "\nLinting with pylint..."
@pylint --rcfile .pylintrc **/*.py
black: ## Format all python files with black
@echo "\nFormatting..."
@black $(PYTHON_SOURCES) --line-length=80
@black $(TEST_SOURCES) --line-length=80
isort: ## Optimise python imports
@isort $(PYTHON_SOURCES)
@isort $(TEST_SOURCES)
.PHONY: pkg
pkg: tests docs build ## Run tests, build documentation, build package
.PHONY: build
build: --install-build-deps ## Build COSIPY package
$(PYTHON) -m build
@twine check dist/*
bump-version:
@bash bump_version.sh
.PHONY:
upload-pypi: # Private: upload COSIPY package
@twine check dist/*
@twine upload dist/*
--install-pip-deps: --check-python # Private: install core dependencies with pip
@echo "\nInstalling dependencies with pip..."
$(PYTHON) -m pip install --r requirements.txt
--install-build-deps: --check-python --hook-manager # Private: install build dependencies
@echo "\nInstalling build dependencies..."
$(PYTHON) -m pip install --upgrade build hatchling twine
--check-python: # Private: check Python is >=3.9
ifeq ($(PYTHON_CHECK_MAJOR),0)
$(error "Python version is $(PYTHON_VERSION). Requires Python >= 3.9")
else ifeq ($(PYTHON_CHECK_MINOR),0)
$(error "Python version is $(PYTHON_VERSION). Requires Python >= 3.9")
endif
--hook-manager: # Private: hook package manager
ifneq (,$(findstring mamba, ${CONDA_EXE}))
pkg-manager := @mamba
else ifneq (,$(findstring miniforge, ${CONDA_EXE}))
pkg-manager := @mamba
else ifeq (,$(findstring conda, ${CONDA_EXE}))
pkg-manager := @conda
else
$(error "No conda/mamba installation found. Try pip install -e . instead")
endif