forked from stac-extensions/mlm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
166 lines (131 loc) · 5 KB
/
Makefile
File metadata and controls
166 lines (131 loc) · 5 KB
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
158
159
160
161
162
163
164
165
166
#* Variables
SHELL ?= /usr/bin/env bash
# use the directory rather than the python binary to allow auto-discovery, which is more cross-platform compatible
PYTHON_PATH := $(shell which python)
# handle whether running on Windows or Unix-like systems
ifneq ($(findstring $(PYTHON_PATH),bin/python),)
PYTHON_ROOT := $(shell dirname $(dir $(PYTHON_PATH)))
else
PYTHON_ROOT := $(shell dirname $(PYTHON_PATH))
endif
ifeq ($(patsubst %/bin,,$(lastword $(PYTHON_ROOT))),)
PYTHON_ROOT := $(dir $(PYTHON_ROOT))
endif
UV_PYTHON_ROOT ?= $(PYTHON_ROOT)
# to actually reuse an existing virtual/conda environment, the 'UV_PROJECT_ENVIRONMENT' variable must be set to it
# use this command:
# UV_PROJECT_ENVIRONMENT=/path/to/env make [target]
# consider exporting this variable in '/path/to/env/etc/conda/activate.d/env.sh' to enable it by default when
# activating a conda environment, and reset it in '/path/to/env/etc/conda/deactivate.d/env.sh'
UV_PROJECT_ENVIRONMENT ?=
# make sure every uv command employs the specified environment path
ifeq (${UV_PROJECT_ENVIRONMENT},)
UV_COMMAND := uv
else
UV_COMMAND := UV_PROJECT_ENVIRONMENT="${UV_PROJECT_ENVIRONMENT}" uv
endif
#* UV
.PHONY: setup
setup:
which uv >/dev/null || (curl -LsSf https://astral.sh/uv/install.sh | sh)
.PHONY: publish
publish:
$(UV_COMMAND) publish --build
#* Installation
.PHONY: install
install: setup
$(UV_COMMAND) export --format requirements-txt -o requirements.txt --no-dev
$(UV_COMMAND) pip install --python "$(UV_PYTHON_ROOT)" -r requirements.txt
.PHONY: install-dev
install-dev: setup
$(UV_COMMAND) export --format requirements-txt -o requirements-dev.txt
$(UV_COMMAND) pip install --python "$(UV_PYTHON_ROOT)" -r requirements-dev.txt
.PHONY: install-dev-extras
install-dev-extras: setup
$(UV_COMMAND) export --format requirements-txt -o requirements-dev.txt
$(UV_COMMAND) pip install --python "$(UV_PYTHON_ROOT)" -e .[torch] -r requirements-dev.txt
.PHONY: pre-commit-install
pre-commit-install: setup
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" pre-commit install
#* Formatters
.PHONY: codestyle
codestyle: setup
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" ruff format --config=pyproject.toml stac_model tests
.PHONY: format
format: codestyle
#* Testing
.PHONY: test
test: setup
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" pytest -c pyproject.toml -v --cov-report=html --cov=stac_model --cov-config pyproject.toml tests/
#* Linting
.PHONY: check
check: check-examples check-markdown check-lint check-mypy check-safety check-citation
.PHONY: check-all
check-all: check
.PHONY: mypy
mypy: setup
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" mypy --config-file pyproject.toml ./
.PHONY: check-mypy
check-mypy: mypy
.PHONY: check-safety
check-safety: setup
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" safety check --full-report
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" bandit -ll --recursive stac_model tests
.PHONY: check-citation
check-citation: setup
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" cffconvert --validate
# see https://docs.astral.sh/ruff/formatter/#sorting-imports for use of both `check` and `format` commands
.PHONY: lint
lint: setup
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" ruff check --select I --fix --config=pyproject.toml ./
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" ruff format --config=pyproject.toml ./
.PHONY: check-lint
check-lint: setup
$(UV_COMMAND) run --python "$(UV_PYTHON_ROOT)" ruff check --config=pyproject.toml ./
.PHONY: format-lint
format-lint: lint
$(UV_COMMAND) run --no-sync --python "$(UV_PYTHON_ROOT)" ruff check --fix --config=pyproject.toml ./
.PHONY: install-npm
install-npm:
npm install
.PHONY: check-markdown
check-markdown: install-npm
npm run check-markdown
.PHONY: format-markdown
format-markdown: install-npm
npm run format-markdown
.PHONY: check-examples
check-examples: install-npm
npm run check-examples
.PHONY: format-examples
format-examples: install-npm
npm run format-examples
FORMATTERS := lint markdown examples
$(addprefix fix-, $(FORMATTERS)): fix-%: format-%
.PHONY: lint-all
lint-all: lint mypy check-safety check-markdown
.PHONY: update-dev-deps
update-dev-deps: setup
$(UV_COMMAND) export --only-dev --format requirements-txt -o requirements-only-dev.txt
$(UV_COMMAND) pip install --python "$(UV_PYTHON_ROOT)" -r requirements-only-dev.txt
#* Cleaning
.PHONY: pycache-remove
pycache-remove:
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf
.PHONY: dsstore-remove
dsstore-remove:
find . | grep -E ".DS_Store" | xargs rm -rf
.PHONY: mypycache-remove
mypycache-remove:
find . | grep -E ".mypy_cache" | xargs rm -rf
.PHONY: ipynbcheckpoints-remove
ipynbcheckpoints-remove:
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
.PHONY: pytestcache-remove
pytestcache-remove:
find . | grep -E ".pytest_cache" | xargs rm -rf
.PHONY: build-remove
build-remove:
rm -rf build/
.PHONY: cleanup
cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove pytestcache-remove