Skip to content

Commit fab4214

Browse files
committed
🐛 Enhance reqs target in Makefile to support upgrading packages starting with a specified prefix
1 parent 0816baa commit fab4214

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

requirements/base.Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
99
.DEFAULT_GOAL := help
1010

1111
DO_CLEAN_OR_UPGRADE:=$(if $(clean),,--upgrade)
12-
UPGRADE_OPTION := $(if $(upgrade),--upgrade-package "$(upgrade)",$(DO_CLEAN_OR_UPGRADE))
12+
STARTSWITH_UPGRADE := $(if $(startswith),$(shell grep '^$(startswith)' $(basename $@).txt 2>/dev/null | cut -d= -f1 | xargs -n1 echo --upgrade-package),)
13+
UPGRADE_OPTION := $(if $(upgrade),--upgrade-package "$(upgrade)",$(if $(startswith),$(STARTSWITH_UPGRADE),$(DO_CLEAN_OR_UPGRADE))
1314
1415
1516
objects = $(sort $(wildcard *.in))
1617
outputs := $(objects:.in=.txt)
1718
18-
reqs: $(outputs) ## pip-compiles all requirements/*.in -> requirements/*.txt; make reqs upgrade=foo will only upgrade package foo
19+
reqs: $(outputs) ## pip-compiles all requirements/*.in -> requirements/*.txt; make reqs upgrade=foo will only upgrade package foo; make reqs startswith=pytest will upgrade packages starting with pytest
1920
2021
touch:
2122
@$(foreach p,${objects},touch ${p};)
@@ -36,6 +37,12 @@ help: ## this colorful help
3637
@echo ""
3738
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
3839
@echo ""
40+
@echo "Examples:"
41+
@echo " make reqs # Upgrade all packages"
42+
@echo " make reqs upgrade=pytest # Upgrade only pytest package"
43+
@echo " make reqs startswith=pytest # Upgrade all packages starting with 'pytest'"
44+
@echo " make reqs clean=1 # Clean and rebuild all requirements"
45+
@echo ""
3946
4047
4148
# ------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)