generated from stac-extensions/template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
686 lines (584 loc) · 27.5 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
RELEASE := master
# Included custom configs change the value of MAKEFILE_LIST
# Extract the required reference beforehand so we can use it for help target
MAKEFILE_NAME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
# Include custom config if it is available
-include Makefile.config
# Application
APP_ROOT := $(abspath $(lastword $(MAKEFILE_NAME))/..)
APP_NAME := $(shell basename $(APP_ROOT))
APP_PKG := pystac_ml_aoi
APP_VERSION ?= 0.2.0
# guess OS (Linux, Darwin,...)
OS_NAME := $(shell uname -s 2>/dev/null || echo "unknown")
CPU_ARCH := $(shell uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown")
# conda
CONDA_CMD ?= __EMPTY__
CONDA_ENV ?= $(APP_NAME)
CONDA_HOME ?= $(HOME)/.conda
CONDA_ENVS_DIR ?= $(CONDA_HOME)/envs
CONDA_ENV_PATH := $(CONDA_ENVS_DIR)/$(CONDA_ENV)
ifneq ($(CONDA_CMD),__EMPTY__)
CONDA_CMD :=
CONDA_BIN :=
CONDA_ENV :=
CONDA_ENV_MODE := [using overridden conda command]
else
CONDA_CMD :=
# allow pre-installed conda in Windows bash-like shell
ifeq ($(findstring MINGW,$(OS_NAME)),MINGW)
CONDA_BIN_DIR ?= $(CONDA_HOME)/Scripts
else
CONDA_BIN_DIR ?= $(CONDA_HOME)/bin
endif
CONDA_BIN ?= $(CONDA_BIN_DIR)/conda
CONDA_ENV_REAL_TARGET_PATH := $(realpath $(CONDA_ENV_PATH))
CONDA_ENV_REAL_ACTIVE_PATH := $(realpath ${CONDA_PREFIX})
# environment already active - use it directly
ifneq ("$(CONDA_ENV_REAL_ACTIVE_PATH)", "")
CONDA_ENV_MODE := [using active environment]
CONDA_ENV := $(notdir $(CONDA_ENV_REAL_ACTIVE_PATH))
CONDA_CMD :=
endif
# environment not active but it exists - activate and use it
ifneq ($(CONDA_ENV_REAL_TARGET_PATH), "")
CONDA_ENV := $(notdir $(CONDA_ENV_REAL_TARGET_PATH))
endif
# environment not active and not found - create, activate and use it
ifeq ("$(CONDA_ENV)", "")
CONDA_ENV := $(APP_NAME)
endif
# update paths for environment activation
ifeq ("$(CONDA_ENV_REAL_ACTIVE_PATH)", "")
CONDA_ENV_MODE := [will activate environment]
CONDA_CMD := source "$(CONDA_BIN_DIR)/activate" "$(CONDA_ENV)";
endif
endif
DOWNLOAD_CACHE ?= $(APP_ROOT)/downloads
PYTHON_VERSION ?= `python -c 'import platform; print(platform.python_version())'`
PYTHON_VERSION_MAJOR := $(shell echo $(PYTHON_VERSION) | cut -f 1 -d '.')
PYTHON_VERSION_MINOR := $(shell echo $(PYTHON_VERSION) | cut -f 2 -d '.')
PYTHON_VERSION_PATCH := $(shell echo $(PYTHON_VERSION) | cut -f 3 -d '.' | cut -f 1 -d ' ')
PIP_USE_FEATURE := `python -c '\
import pip; \
try: \
from packaging.version import Version \
except ImportError: \
from distutils.version import LooseVersion as Version \
print(Version(pip.__version__) < Version("21.0"))'`
PIP_XARGS ?=
ifeq ("$(PIP_USE_FEATURE)", "True")
PIP_XARGS := --use-feature=2020-resolver $(PIP_XARGS)
endif
# choose conda installer depending on your OS
CONDA_URL = https://repo.continuum.io/miniconda
ifeq ("$(OS_NAME)", "Linux")
FN := Miniconda3-latest-Linux-x86_64.sh
else ifeq ("$(OS_NAME)", "Darwin")
FN := Miniconda3-latest-MacOSX-x86_64.sh
else
FN := unknown
endif
# Tests
REPORTS_DIR := $(APP_ROOT)/reports
# end of configuration
.DEFAULT_GOAL := help
## -- Informative targets ------------------------------------------------------------------------------------------- ##
.PHONY: all
all: help
# Auto documented help targets & sections from comments
# - detects lines marked by double octothorpe (#), then applies the corresponding target/section markup
# - target comments must be defined after their dependencies (if any)
# - section comments must have at least a double dash (-)
#
# Original Reference:
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
# Formats:
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
_SECTION := \033[34m
_TARGET := \033[36m
_NORMAL := \033[0m
.PHONY: help
# note: use "\#\#" to escape results that would self-match in this target's search definition
help: ## print this help message (default)
@echo "$(_SECTION)=======================================$(_NORMAL)"
@echo "$(_SECTION) $(APP_NAME) help $(_NORMAL)"
@echo "$(_SECTION)=======================================$(_NORMAL)"
@echo "Please use 'make <target>' where <target> is one of below options."
@echo ""
@echo "NOTE:"
@echo " Targets suffixed '<target>-only' can be called as '<target> to run setup before their main operation."
@echo ""
# @grep -E '^[a-zA-Z_-]+:.*?\#\# .*$$' $(MAKEFILE_LIST) \
# | awk 'BEGIN {FS = ":.*?\#\# "}; {printf " $(_TARGET)%-24s$(_NORMAL) %s\n", $$1, $$2}'
@grep -E '\#\#.*$$' "$(APP_ROOT)/$(MAKEFILE_NAME)" \
| awk ' BEGIN {FS = "(:|\-\-\-)+.*?\#\# "}; \
/\--/ {printf "$(_SECTION)%s$(_NORMAL)\n", $$1;} \
/:/ {printf " $(_TARGET)%-24s$(_NORMAL) %s\n", $$1, $$2} \
'
.PHONY: targets
targets: help
.PHONY: version
version: ## display current version
@-echo "$(APP_NAME) version: $(APP_VERSION)"
.PHONY: info
info: ## display make information
@echo "Makefile configuration details:"
@echo " OS Name $(OS_NAME)"
@echo " CPU Architecture $(CPU_ARCH)"
@echo " Conda Home $(CONDA_HOME)"
@echo " Conda Prefix $(CONDA_ENV_PATH)"
@echo " Conda Env Name $(CONDA_ENV)"
@echo " Conda Env Path $(CONDA_ENV_REAL_ACTIVE_PATH)"
@echo " Conda Binary $(CONDA_BIN)"
@echo " Conda Activation $(CONDA_ENV_MODE)"
@echo " Conda Command $(CONDA_CMD)"
@echo " Application Name $(APP_NAME)"
@echo " Application Root $(APP_ROOT)"
@echo " Download Cache $(DOWNLOAD_CACHE)"
@echo " Docker Repository $(DOCKER_REPO)"
.PHONY: fixme-list-only
fixme-list-only: mkdir-reports ## list all FIXME/TODO/HACK items that require attention in the code
@echo "Listing code that requires fixes..."
@echo '[MISCELLANEOUS]\nnotes=FIXME,TODO,HACK' > "$(REPORTS_DIR)/fixmerc"
@bash -c '$(CONDA_CMD) \
pylint \
--disable=all,use-symbolic-message-instead --enable=miscellaneous,W0511 \
--score n --persistent n \
--rcfile="$(REPORTS_DIR)/fixmerc" \
-f colorized \
"$(APP_ROOT)/$(APP_PKG)" "$(APP_ROOT)/tests" \
1> >(tee "$(REPORTS_DIR)/fixme.txt")'
.PHONY: fixme-list
fixme-list: install-dev fixme-list-only ## list all FIXME/TODO/HACK items with pre-installation of dependencies
## -- Conda targets ------------------------------------------------------------------------------------------------- ##
.PHONY: conda-base
conda-base: ## obtain and install a missing conda distribution
@echo "Validating conda installation..."
@test -f "$(CONDA_BIN)" || test -d "$(DOWNLOAD_CACHE)" || \
(echo "Creating download directory: $(DOWNLOAD_CACHE)" && mkdir -p "$(DOWNLOAD_CACHE)")
@test -f "$(CONDA_BIN)" || test -f "$(DOWNLOAD_CACHE)/$(FN)" || \
(echo "Fetching conda distribution from: $(CONDA_URL)/$(FN)" && \
curl "$(CONDA_URL)/$(FN)" --insecure --location --output "$(DOWNLOAD_CACHE)/$(FN)")
@test -f "$(CONDA_BIN)" || \
(bash "$(DOWNLOAD_CACHE)/$(FN)" -b -u -p "$(CONDA_HOME)" && \
echo "Make sure to add '$(CONDA_BIN_DIR)' to your PATH variable in '~/.bashrc'.")
.PHONY: conda-clean
clean-clean: ## remove the conda environment
@echo "Removing conda env '$(CONDA_ENV)'"
@-test -d "$(CONDA_ENV_PATH)" && "$(CONDA_BIN)" remove -n "$(CONDA_ENV)" --yes --all
.PHONY: conda-config
conda-config: conda-base ## setup configuration of the conda environment
@echo "Updating conda configuration..."
@ "$(CONDA_BIN)" config --add envs_dirs "$(CONDA_ENVS_DIR)"
@ "$(CONDA_BIN)" config --set ssl_verify true
@ "$(CONDA_BIN)" config --set channel_priority true
@ "$(CONDA_BIN)" config --set auto_update_conda false
@ "$(CONDA_BIN)" config --add channels defaults
@ "$(CONDA_BIN)" config --append channels conda-forge
.PHONY: conda-install
conda-install:
@[ -z "$(CONDA_ENV)" ] && echo "Skipping conda environment setup [CONDA_ENV empty]" || ( \
echo "Setup conda environment..."; \
$(MAKE) -C "$(APP_ROOT)" conda-env \
)
.PHONY: conda-env
conda-env: conda-base conda-config ## create the conda environment
@test -d "$(CONDA_ENV_PATH)" || \
(echo "Creating conda environment at '$(CONDA_ENV_PATH)'..." && \
"$(CONDA_HOME)/bin/conda" create -y -n "$(CONDA_ENV)" python=$(PYTHON_VERSION))
.PHONY: conda-pinned
conda-pinned: conda-env ## pin the conda version
@echo "Update pinned conda packages..."
@-test -d $(CONDA_ENV_PATH) && test -f $(CONDA_PINNED) && \
cp -f "$(CONDA_PINNED)" "$(CONDA_ENV_PATH)/conda-meta/pinned"
.PHONY: conda-env-export
conda-env-export: ## export the conda environment
@echo "Exporting conda environment..."
@test -d $(CONDA_ENV_PATH) && "$(CONDA_BIN)" env export -n $(CONDA_ENV) -f environment.yml
## -- Build targets ------------------------------------------------------------------------------------------------- ##
.PHONY: install
install: install-run install-pip ## alias for 'install-all' target
.PHONY: install-run
install-run: conda-install install-sys install-pkg install-raw ## install requirements and application to run locally
.PHONY: install-all
install-all: conda-install install-sys install-pkg install-pip install-dev ## install application with all dependencies
.PHONY: install-doc
install-doc: install-pip ## install documentation dependencies
@test -f "$(APP_ROOT)/requirements-doc.txt" && ( \
echo "Installing development packages with pip..." && \
bash -c '$(CONDA_CMD) pip install $(PIP_XARGS) -r "$(APP_ROOT)/requirements-doc.txt"' && \
echo "Install with pip complete. Run documentation generation with 'make docs' target." \
) || echo "No documentation requirements to install."
.PHONY: install-dev
install-dev: install-run install-npm-remarklint ## install development and test dependencies
@test -f "$(APP_ROOT)/requirements-dev.txt" && ( \
echo "Installing development packages with pip..." && \
bash -c '$(CONDA_CMD) pip install $(PIP_XARGS) -r "$(APP_ROOT)/requirements-dev.txt"' && \
echo "Install with pip complete. Test service with 'make test*' variations." \
) || echo "No development requirements to install."
.PHONY: install-pkg
install-pkg: install-pip ## install application package dependencies
@test -f "$(APP_ROOT)/requirements.txt" && ( \
echo "Installing base packages with pip..." && \
bash -c "$(CONDA_CMD) pip install $(PIP_XARGS) -r "$(APP_ROOT)/requirements.txt" --no-cache-dir" && \
echo "Install with pip complete." \
) || echo "No application requirements to install."
# don't use 'PIP_XARGS' in this case since extra features could not yet be supported by pip being installed/updated
.PHONY: install-sys
install-sys: ## install system dependencies and required installers/runners
@test -f "$(APP_ROOT)/requirements-sys.txt" && ( \
echo "Installing system dependencies..." && \
bash -c '$(CONDA_CMD) pip install --upgrade -r "$(APP_ROOT)/requirements-sys.txt"' && \
echo "Install with pip complete." \
) || echo "No system requirements to install."
.PHONY: install-pip
install-pip: ## install application as a package to allow import from another python package
@echo "Installing package with pip..."
@-bash -c '$(CONDA_CMD) pip install $(PIP_XARGS) --upgrade -e "$(APP_ROOT)" --no-cache'
@echo "Install with pip complete."
.PHONY: install-raw
install-raw: ## install without any requirements or dependencies (suppose everything is setup)
@echo "Installing package without dependencies..."
@bash -c '$(CONDA_CMD) pip install $(PIP_XARGS) -e "$(APP_ROOT)" --no-deps'
@echo "Install package complete."
# install locally to ensure they can be found by config extending them
.PHONY: install-npm
install-npm: ## install npm package manager and dependencies if they cannot be found
@[ -f "$(shell which npm)" ] || ( \
echo "Binary package manager npm not found. Attempting to install it."; \
apt-get install npm \
)
.PHONY: install-npm-remarklint
install-npm-remarklint: install-npm ## install remark-lint dependency for 'check-md' target using npm
@[ `npm ls 2>/dev/null | grep remark-lint | wc -l` = 1 ] || ( \
echo "Install required dependencies for Markdown checks." && \
npm install --save-dev \
remark-lint \
remark-gfm \
remark-cli \
remark-lint-maximum-line-length \
remark-lint-checkbox-content-indent \
remark-preset-lint-recommended \
remark-preset-lint-markdown-style-guide \
)
## -- Cleanup targets ----------------------------------------------------------------------------------------------- ##
.PHONY: clean
clean: clean-all ## alias for 'clean-all' target
.PHONY: clean-all
clean-all: clean-build clean-cache clean-docs-dirs clean-src clean-reports clean-test ## run all cleanup targets
.PHONY: clean-build
clean-build: ## remove the temporary build files
@echo "Removing build files..."
@-rm -fr "$(APP_ROOT)/eggs"
@-rm -fr "$(APP_ROOT)/develop-eggs"
@-rm -fr "$(APP_ROOT)/$(APP_NAME).egg-info"
@-rm -fr "$(APP_ROOT)/parts"
.PHONY: clean-cache
clean-cache: ## remove caches such as DOWNLOAD_CACHE
@echo "Removing caches..."
@-rm -fr "$(APP_ROOT)/.pytest_cache"
@-rm -fr "$(DOWNLOAD_CACHE)"
.PHONY: clean-docs
clean-docs: clean-docs-dirs ## remove documentation artifacts
@echo "Removing documentation build files..."
@$(MAKE) -C "$(APP_ROOT)/docs" clean || true
# extensive cleanup is possible only using sphinx-build
# allow minimal cleanup when it could not *yet* be installed (dev)
.PHONY: clean-docs-dirs
clean-docs-dirs: ## remove documentation artifacts (minimal)
@echo "Removing documentation directories..."
@-rm -fr "$(APP_ROOT)/docs/_build"
@-rm -fr "$(APP_ROOT)/docs/build"
@-rm -fr "$(APP_ROOT)/docs/source/autoapi"
@-rm -fr "$(APP_ROOT)/docs/html"
@-rm -fr "$(APP_ROOT)/docs/xml"
.PHONY: clean-src
clean-src: ## remove all *.pyc files
@echo "Removing python artifacts..."
@-find "$(APP_ROOT)" -type f -name "*.pyc" -exec rm {} \;
@-rm -rf ./build
@-rm -rf ./src
.PHONY: clean-test
clean-test: ## remove files created by tests and coverage analysis
@echo "Removing test/coverage/report files..."
@-rm -f "$(APP_ROOT)/.coverage"
@-rm -f "$(APP_ROOT)/coverage.*"
@-rm -fr "$(APP_ROOT)/coverage"
@-rm -fr "$(REPORTS_DIR)/coverage"
@-rm -fr "$(REPORTS_DIR)/test-*.xml"
.PHONY: clean-reports
clean-reports: ## remove report files generated by code checks
@-rm -fr "$(REPORTS_DIR)"
.PHONY: clean-dist
clean-dist: clean ## remove *all* files that are not controlled by 'git' except *.bak and makefile configuration
@echo "Cleaning distribution..."
@git diff --quiet HEAD || echo "There are uncommitted changes! Not doing 'git clean'..."
@-git clean -dfx -e *.bak -e Makefile.config
## -- Testing targets ----------------------------------------------------------------------------------------------- ##
## -- [variants '<target>-only' without '-only' suffix are also available with pre-install setup]
# -v: list of test names with PASS/FAIL/SKIP/ERROR/etc. next to it
# -vv: extended collection of stdout/stderr on top of test results
TEST_VERBOSITY ?= -v
override TEST_VERBOSE_FLAG := $(shell echo $(TEST_VERBOSITY) | tr ' ' '\n' | grep -E "^\-v+" || echo "")
override TEST_VERBOSE_CAPTURE := $(shell \
test $$(echo "$(TEST_VERBOSE_FLAG)" | tr -cd 'v' | wc -c) -gt 1 && echo 1 || echo 0 \
)
ifeq ($(filter $(TEST_VERBOSITY),"--capture"),)
ifeq ($(TEST_VERBOSE_CAPTURE),1)
TEST_VERBOSITY := $(TEST_VERBOSITY) --capture tee-sys
endif
endif
# autogen tests variants with pre-install of dependencies using the '-only' target references
TESTS := unit spec coverage
TESTS := $(addprefix test-, $(TESTS))
$(TESTS): test-%: install-dev test-%-only
.PHONY: test
test: clean-test test-all ## alias for 'test-all' target
.PHONY: test-all
test-all: install-dev test-only ## run all tests (including long running tests)
.PHONY: test-only
test-only: mkdir-reports ## run all tests but without prior validation of installed dependencies
@echo "Running all tests (including slow and online tests)..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) \
--junitxml "$(REPORTS_DIR)/test-results.xml"'
.PHONY: test-unit-only
test-unit-only: mkdir-reports ## run unit tests (skip long running and online tests)
@echo "Running unit tests (skip slow and online tests)..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) \
-m "not slow and not online and not functional" --junitxml "$(REPORTS_DIR)/test-results.xml"'
.PHONY: test-spec-only
test-spec-only: mkdir-reports ## run tests with custom specification (pytest format) [make SPEC='<spec>' test-spec]
@echo "Running custom tests from input specification..."
@[ "${SPEC}" ] || ( echo ">> 'SPEC' is not set"; exit 1 )
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) \
-k "${SPEC}" --junitxml "$(REPORTS_DIR)/test-results.xml"'
.PHONY: test-coverage-only
test-coverage-only: mkdir-reports ## run all tests using coverage analysis
@echo "Running coverage analysis..."
@bash -c '$(CONDA_CMD) coverage run --rcfile="$(APP_ROOT)/setup.cfg" "$$(which pytest)" "$(APP_ROOT)/tests" || true'
@bash -c '$(CONDA_CMD) coverage xml --rcfile="$(APP_ROOT)/setup.cfg" -i -o "$(REPORTS_DIR)/coverage.xml"'
@bash -c '$(CONDA_CMD) coverage report --rcfile="$(APP_ROOT)/setup.cfg" -i -m'
@bash -c '$(CONDA_CMD) coverage html --rcfile="$(APP_ROOT)/setup.cfg" -d "$(REPORTS_DIR)/coverage"'
.PHONY: coverage
coverage: test-coverage ## alias to run test with coverage analysis
## -- Static code check targets ------------------------------------------------------------------------------------- ##
## -- [variants '<target>-only' without '-only' suffix are also available with pre-install setup]
# autogen check variants with pre-install of dependencies using the '-only' target references
CHECKS := pep8 lint security security-code security-deps doc8 docf fstring docstring links imports
CHECKS := $(addprefix check-, $(CHECKS))
# items that should not install python dev packages should be added here instead
# they must provide their own target/only + with dependency install variants
CHECKS_NO_PY := md
CHECKS_NO_PY := $(addprefix check-, $(CHECKS_NO_PY))
CHECKS_ALL := $(CHECKS) $(CHECKS_NO_PY)
$(CHECKS): check-%: install-dev check-%-only
.PHONY: mkdir-reports
mkdir-reports:
@mkdir -p "$(REPORTS_DIR)"
.PHONY: check
check: check-all ## alias for 'check-all' target
.PHONY: check-only
check-only: $(addsuffix -only, $(CHECKS_ALL))
.PHONY: check-all
check-all: install-dev $(CHECKS_ALL) ## check all code linters
.PHONY: check-pep8-only
check-pep8-only: mkdir-reports ## check for PEP8 code style issues
@echo "Running PEP8 code style checks..."
@-rm -fr "$(REPORTS_DIR)/check-pep8.txt"
@bash -c '$(CONDA_CMD) \
flake8 --config="$(APP_ROOT)/setup.cfg" --output-file="$(REPORTS_DIR)/check-pep8.txt" --tee'
.PHONY: check-lint-only
check-lint-only: mkdir-reports ## check linting of code style
@echo "Running linting code style checks..."
@-rm -fr "$(REPORTS_DIR)/check-lint.txt"
@bash -c '$(CONDA_CMD) \
pylint \
--load-plugins pylint_quotes \
--rcfile="$(APP_ROOT)/.pylintrc" \
--reports y \
"$(APP_ROOT)/$(APP_PKG)" "$(APP_ROOT)/tests" \
1> >(tee "$(REPORTS_DIR)/check-lint.txt")'
.PHONY: check-security-only
check-security-only: check-security-code-only check-security-deps-only ## run security checks
# FIXME: safety ignore file (https://github.com/pyupio/safety/issues/351)
# ignored codes:
# 45185: pylint<2.13.0: unrelated doc extension (https://github.com/PyCQA/pylint/issues/5322)
SAFETY_IGNORE := 45185
SAFETY_IGNORE := $(addprefix "-i ",$(SAFETY_IGNORE))
.PHONY: check-security-deps-only
check-security-deps-only: mkdir-reports ## run security checks on package dependencies
@echo "Running security checks of dependencies..."
@-rm -fr "$(REPORTS_DIR)/check-security-deps.txt"
@bash -c '$(CONDA_CMD) \
safety check \
--full-report \
-r "$(APP_ROOT)/requirements.txt" \
-r "$(APP_ROOT)/requirements-dev.txt" \
-r "$(APP_ROOT)/requirements-sys.txt" \
$(SAFETY_IGNORE) \
1> >(tee "$(REPORTS_DIR)/check-security-deps.txt")'
# FIXME: bandit excludes not working (https://github.com/PyCQA/bandit/issues/657), clean-src beforehand to avoid error
.PHONY: check-security-code-only
check-security-code-only: mkdir-reports clean-src ## run security checks on source code
@echo "Running security code checks..."
@-rm -fr "$(REPORTS_DIR)/check-security-code.txt"
@bash -c '$(CONDA_CMD) \
bandit -v --ini "$(APP_ROOT)/setup.cfg" -r \
1> >(tee "$(REPORTS_DIR)/check-security-code.txt")'
.PHONY: check-doc8-only
check-doc8-only: mkdir-reports ## check documentation RST styles and linting
@echo "Running doc8 doc style checks..."
@-rm -fr "$(REPORTS_DIR)/check-doc8.txt"
@bash -c '$(CONDA_CMD) \
doc8 "$(APP_ROOT)/docs" \
1> >(tee "$(REPORTS_DIR)/check-doc8.txt")'
.PHONY: check-docf-only
check-docf-only: mkdir-reports ## run PEP8 code documentation format checks
@echo "Checking PEP8 doc formatting problems..."
@-rm -fr "$(REPORTS_DIR)/check-docf.txt"
@bash -c '$(CONDA_CMD) \
docformatter --check --recursive --config "$(APP_ROOT)/setup.cfg" "$(APP_ROOT)" \
1>&2 2> >(tee "$(REPORTS_DIR)/check-docf.txt")'
# FIXME: no configuration file support
define FLYNT_FLAGS
--line-length 120 \
--verbose
endef
ifeq ($(shell test $(PYTHON_VERSION_MAJOR) -eq 3 && test $(PYTHON_VERSION_MINOR) -ge 8; echo $$?),0)
FLYNT_FLAGS := $(FLYNT_FLAGS) --transform-concats
endif
.PHONY: check-fstring-only
check-fstring-only: mkdir-reports ## check f-string format definitions
@echo "Running code f-string formats substitutions..."
@-rm -f "$(REPORTS_DIR)/check-fstring.txt"
@bash -c '$(CONDA_CMD) \
flynt --dry-run --fail-on-change $(FLYNT_FLAGS) "$(APP_ROOT)" \
1> >(tee "$(REPORTS_DIR)/check-fstring.txt")'
.PHONY: check-docstring-only
check-docstring-only: mkdir-reports ## check code docstring style and linting
@echo "Running docstring checks..."
@-rm -fr "$(REPORTS_DIR)/check-docstring.txt"
@bash -c '$(CONDA_CMD) \
pydocstyle --explain --config "$(APP_ROOT)/setup.cfg" "$(APP_ROOT)" \
1> >(tee "$(REPORTS_DIR)/check-docstring.txt")'
.PHONY: check-links-only
check-links-only: ## check all external links in documentation for integrity
@echo "Running link checks on docs..."
@bash -c '$(CONDA_CMD) $(MAKE) -C "$(APP_ROOT)/docs" linkcheck' || true
.PHONY: check-imports-only
check-imports-only: mkdir-reports ## check imports ordering and styles
@echo "Running import checks..."
@-rm -fr "$(REPORTS_DIR)/check-imports.txt"
@bash -c '$(CONDA_CMD) \
isort --check-only --diff --recursive $(APP_ROOT) \
1> >(tee "$(REPORTS_DIR)/check-imports.txt")'
# must pass 2 search paths because '<dir>/.<subdir>' are somehow not correctly detected with only the top-level <dir>
.PHONY: check-md-only
check-md-only: mkdir-reports ## check Markdown linting
@echo "Running Markdown style checks..."
@npx --no-install remark \
--inspect --frail \
--silently-ignore \
--stdout --color \
--rc-path "$(APP_ROOT)/.remarkrc" \
--ignore-path "$(APP_ROOT)/.remarkignore" \
"$(APP_ROOT)" "$(APP_ROOT)/.*/" \
> "$(REPORTS_DIR)/check-md.txt"
.PHONY: check-md
check-md: install-npm-remarklint check-md-only ## check Markdown linting after dependency installation
# autogen fix variants with pre-install of dependencies using the '-only' target references
FIXES := imports lint docf fstring
FIXES := $(addprefix fix-, $(FIXES))
# items that should not install python dev packages should be added here instead
# they must provide their own target/only + with dependency install variants
FIXES_NO_PY := md
FIXES_NO_PY := $(addprefix fix-, $(FIXES_NO_PY))
FIXES_ALL := $(FIXES) $(FIXES_NO_PY)
$(FIXES): fix-%: install-dev fix-%-only
.PHONY: fix
fix: fix-all ## alias for 'fix-all' target
.PHONY: fix-only
fix-only: $(addsuffix -only, $(FIXES)) ## run all automatic fixes without development dependencies pre-install
.PHONY: fix-all
fix-all: install-dev $(FIXES_ALL) ## fix all code check problems automatically after install of dependencies
.PHONY: fix-imports-only
fix-imports-only: mkdir-reports ## apply import code checks corrections
@echo "Fixing flagged import checks..."
@-rm -fr "$(REPORTS_DIR)/fixed-imports.txt"
@bash -c '$(CONDA_CMD) \
isort --recursive $(APP_ROOT) \
1> >(tee "$(REPORTS_DIR)/fixed-imports.txt")'
# FIXME: https://github.com/PyCQA/pycodestyle/issues/996
# Tool "pycodestyle" doesn't respect "# noqa: E241" locally, but "flake8" and other tools do.
# Because "autopep8" uses "pycodestyle", it is impossible to disable locally extra spaces (as in tests to align values).
# Override the codes here from "setup.cfg" because "autopep8" also uses the "flake8" config, and we want to preserve
# global detection of those errors (typos, bad indents), unless explicitly added and excluded for readability purposes.
# WARNING: this will cause inconsistencies between what 'check-lint' detects and what 'fix-lint' can actually fix
_DEFAULT_SETUP_ERROR := E126,E226,E402,F401,W503,W504
_EXTRA_SETUP_ERROR := E241,E731
.PHONY: fix-lint-only
fix-lint-only: mkdir-reports ## fix some PEP8 code style problems automatically
@echo "Fixing PEP8 code style problems..."
@-rm -fr "$(REPORTS_DIR)/fixed-lint.txt"
@bash -c '$(CONDA_CMD) \
autopep8 \
--global-config "$(APP_ROOT)/setup.cfg" \
--ignore "$(_DEFAULT_SETUP_ERROR),$(_EXTRA_SETUP_ERROR)" \
-v -j 0 -i -r $(APP_ROOT) \
1> >(tee "$(REPORTS_DIR)/fixed-lint.txt")'
.PHONY: fix-docf-only
fix-docf-only: mkdir-reports ## fix some PEP8 code documentation style problems automatically
@echo "Fixing PEP8 code documentation problems..."
@-rm -fr "$(REPORTS_DIR)/fixed-docf.txt"
@bash -c '$(CONDA_CMD) \
docformatter --in-place --recursive --config "$(APP_ROOT)/setup.cfg" "$(APP_ROOT)" \
1> >(tee "$(REPORTS_DIR)/fixed-docf.txt")'
.PHONY: fix-fstring-only
fix-fstring-only: mkdir-reports
@echo "Fixing code string formats substitutions to f-string definitions..."
@-rm -f "$(REPORTS_DIR)/fixed-fstring.txt"
@bash -c '$(CONDA_CMD) \
flynt $(FLYNT_FLAGS) "$(APP_ROOT)" \
1> >(tee "$(REPORTS_DIR)/fixed-fstring.txt")'
# must pass 2 search paths because '<dir>/.<subdir>' are somehow not correctly detected with only the top-level <dir>
.PHONY: fix-md-only
fix-md-only: mkdir-reports ## fix Markdown linting problems automatically
@echo "Running Markdown style checks..."
@npx --no-install remark \
--output --frail \
--silently-ignore \
--rc-path "$(APP_ROOT)/.remarkrc" \
--ignore-path "$(APP_ROOT)/.remarkignore" \
"$(APP_ROOT)" "$(APP_ROOT)/.*/" \
2>&1 | tee "$(REPORTS_DIR)/fixed-md.txt"
.PHONY: fix-md
fix-md: install-npm-remarklint fix-md-only ## fix Markdown linting problems after dependency installation
## -- Documentation targets ----------------------------------------------------------------------------------------- ##
.PHONY: docs-build
docs-build: ## generate HTML documentation with Sphinx
@echo "Generating docs with Sphinx..."
@bash -c '$(CONDA_CMD) $(MAKE) -C "$(APP_ROOT)/docs" html'
@-echo "Documentation available: file://$(APP_ROOT)/docs/build/html/index.html"
.PHONY: docs-only
docs-only: docs-build ## generate HTML documentation with Sphinx (alias)
.PHONY: docs
docs: install-doc clean-docs docs-only ## generate HTML documentation with Sphinx after dependencies installation
## -- Versioning targets -------------------------------------------------------------------------------------------- ##
# Bumpversion 'dry' config
# if 'dry' is specified as target, any bumpversion call using 'BUMP_XARGS' will not apply changes
BUMP_XARGS ?= --verbose --allow-dirty
ifeq ($(filter dry, $(MAKECMDGOALS)), dry)
BUMP_XARGS := $(BUMP_XARGS) --dry-run --verbose --list
endif
.PHONY: dry
dry: setup.cfg ## run 'bump' target without applying changes (dry-run) [make VERSION=<x.y.z> bump dry]
@-echo > /dev/null
.PHONY: bump
bump: ## bump version using VERSION specified as user input [make VERSION=<x.y.z> bump]
@-echo "Updating package version ..."
@[ "${VERSION}" ] || ( echo ">> 'VERSION' is not set"; exit 1 )
@-bash -c '$(CONDA_CMD) bump2version $(BUMP_XARGS) --new-version "${VERSION}" patch;'
# Reapply config if overrides were defined.
# Ensure overrides take precedence over targets and auto-resolution logic of variables.
-include Makefile.config