diff --git a/Makefile b/Makefile index 773bef9..192fa03 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ substitute = @sed \ $(1) > $(2) \ && echo "Substituted from '$(1)' to '$(2)'." +.PHONY: all all: install # $< - %.in file, $@ desired file % @@ -66,15 +67,19 @@ all: install %.py: %.tmp.py $(call substitute,$<,$@) +.PHONY: substitute-sources substitute-sources: $(SOURCE_SUB_FILES) @echo "Substituted information about the utility in the source files." +.PHONY: substitute-debian substitute-debian: $(DEBIAN_SUB_FILES) @echo "Substituted information about the utility in the debian files." +.PHONY: substitute-docker substitute-docker: $(DOCKER_SUB_FILES) @echo "Substituted information about the utility in the docker files." +.PHONY: install install: substitute-sources man translate-compile python3 -m pip install --root=$(DESTDIR)/ . @@ -104,6 +109,7 @@ install: substitute-sources man translate-compile install -D -m 0644 man/$(UTIL_NAME).1 $(DESTDIR)/usr/share/man/man1/$(UTIL_NAME).1 +.PHONY: man man: substitute-sources mkdir -p man if [ ! -f man/$(UTIL_NAME).1 ]; then \ @@ -115,6 +121,7 @@ man: substitute-sources --output man/$(UTIL_NAME).1; \ fi +.PHONY: package package: substitute-debian find $(DEBIAN_PACKAGES_PATH)/$(UTIL_NAME)* > /dev/null 2>&1 || ( \ dpkg-buildpackage -jauto -b \ @@ -127,22 +134,27 @@ package: substitute-debian chown --recursive ${USER_UID}:${USER_GID} $(DEBIAN_PACKAGES_PATH) \ ) +.PHONY: test test: substitute-sources pytest test/unit test/misc --cov=src/ --cov-report xml --cov-report term make clean-cache +.PHONY: autotest autotest: pytest test/auto make clean-cache +.PHONY: pre-commit pre-commit: python3 -m pre_commit run --all-files +.PHONY: clean-cache clean-cache: find . -maxdepth 1 -type d | grep -E "pytest_cache" | (xargs rm -r 2> /dev/null || exit 0) find "src/$(UTIL_NAME)/" -type f -name '*.c' -exec rm --force '{}' + rm --recursive --force $(shell find -type d -iname "__pycache__") +.PHONY: clean clean: clean-cache rm --force --recursive man/ rm --force --recursive build/ @@ -156,6 +168,7 @@ clean: clean-cache rm --force ${DEBIAN_PATH}/$(UTIL_NAME)-util.substvars rm --force --recursive src/$(UTIL_NAME).egg-info +.PHONY: clean-all clean-all: clean rm --force src/$(UTIL_NAME)/consts.py @@ -165,18 +178,23 @@ clean-all: clean rm --force ${DEBIAN_PATH}/preinst rm --force ${DEBIAN_PATH}/copyright +.PHONY: uninstall uninstall: rm --force $(DESTDIR)/usr/share/man/man1/$(UTIL_NAME).1 rm --force --recursive $(DESTDIR)/$(LIB_PATH) pip3 uninstall $(UTIL_NAME) -y +.PHONY: reinstall reinstall: uninstall install +.PHONY: todo-list todo-list: clean-all @grep --color=auto -r -n 'TODO' ./* --exclude=Makefile --exclude-dir=docs +.PHONY: help help: general-help docker-help translate-help +.PHONY: general-help general-help: @echo "Usage:" @echo " make [targets] [arguments]" @@ -205,7 +223,6 @@ general-help: .EXPORT_ALL_VARIABLES: -.PHONY: all test man include docker/docker.mk include locales/i18n.mk diff --git a/docker/docker.mk b/docker/docker.mk index 2447567..1ed1bae 100644 --- a/docker/docker.mk +++ b/docker/docker.mk @@ -2,6 +2,7 @@ MONGO_DOCKER_TAG := mongo:8.0.9 MONGO_CONTAINER_NAME := mongo-$(UTIL_NAME)-test +.PHONY: docker-help docker-help: @echo "Docker:" @echo " docker-run Runs docker container with installed util;" @@ -18,6 +19,7 @@ docker-help: @echo " docker-help Displays information about available docker targets." @echo +.PHONY: docker-base-image docker-base-image: substitute-sources substitute-docker @docker image inspect $(BASE_DOCKER_TAG) > /dev/null 2>&1 || ( \ echo "Building base docker image." && \ @@ -30,6 +32,7 @@ docker-base-image: substitute-sources substitute-docker . \ ) +.PHONY: docker-test-image docker-test-image: docker-base-image @docker image inspect $(TEST_DOCKER_TAG) > /dev/null 2>&1 || \ docker image build \ @@ -42,6 +45,7 @@ docker-test-image: docker-base-image --file docker/test_ubuntu2204.dockerfile \ . +.PHONY: docker-test-mongo-run docker-test-mongo-run: @docker run \ --env MONGO_INITDB_ROOT_USERNAME=root \ @@ -50,10 +54,12 @@ docker-test-mongo-run: --name $(MONGO_CONTAINER_NAME) \ $(MONGO_DOCKER_TAG) +.PHONY: docker-test-mongo-stop docker-test-mongo-stop: @docker container stop $(MONGO_CONTAINER_NAME) @docker container rm $(MONGO_CONTAINER_NAME) +.PHONY: docker-test docker-test: docker-test-image docker-test-mongo-run @docker run --rm \ --env MONGO_HOST=$(shell docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(MONGO_CONTAINER_NAME)) \ @@ -61,6 +67,7 @@ docker-test: docker-test-image docker-test-mongo-run "$(TEST_DOCKER_TAG)" || (make docker-test-mongo-stop && exit 200) @make docker-test-mongo-stop +.PHONY: docker-autotest docker-autotest: docker-test-image docker-build-package docker-test-mongo-run @if [ $(shell find . -maxdepth 1 -type f -name .env | wc --lines) != 1 ]; then \ echo "Requires '.env' file with provided GitHub token for running autotests."; \ @@ -76,6 +83,7 @@ docker-autotest: docker-test-image docker-build-package docker-test-mongo-run make docker-test-mongo-stop; \ fi +.PHONY: docker-build-package docker-build-package: docker-test-image docker run --rm \ --volume $(PWD)/$(DEBIAN_PACKAGES_PATH):/usr/src/$(UTIL_NAME)/$(DEBIAN_PACKAGES_PATH) \ @@ -85,6 +93,7 @@ docker-build-package: docker-test-image "$(TEST_DOCKER_TAG)" bash -c \ "make package" +.PHONY: docker-image docker-image: docker-base-image docker-test-image @if [ "$(REBUILD)" = "1" ]; then \ make clean-all docker-rmi ALL="$(ALL)"; \ @@ -104,6 +113,7 @@ docker-image: docker-base-image docker-test-image . \ ) +.PHONY: docker-run docker-run: docker-image @touch .env docker run --rm --tty --interactive \ @@ -111,6 +121,7 @@ docker-run: docker-image --add-host=host.docker.internal:host-gateway \ "$(DOCKER_TAG)" +.PHONY: docker-rmi docker-rmi: @docker rmi $(DOCKER_TAG) --force @docker rmi $(TEST_DOCKER_TAG) --force diff --git a/locales/i18n.mk b/locales/i18n.mk index 64e2dba..9faa572 100644 --- a/locales/i18n.mk +++ b/locales/i18n.mk @@ -2,6 +2,7 @@ LOCALES_DIR := locales/ TRANSLATIONS_DIR := ${LOCALES_DIR}/translations +.PHONY: translate-help translate-help: @echo "Translate:" @echo " translate-extract Extracts all lines that need to be translated;" @@ -12,6 +13,7 @@ translate-help: @echo " translate-help Displays information about available translation targets." @echo +.PHONY: translate-extract translate-extract: pybabel extract --mapping-file ${LOCALES_DIR}/babel.cfg \ --keywords _ \ @@ -24,6 +26,7 @@ translate-extract: sed -ri '2 s/[0-9]{4}/2024-2025/' ${LOCALES_DIR}/${UTIL_NAME}.pot sed -i -e '4d;10d;$$ d' ${LOCALES_DIR}/${UTIL_NAME}.pot +.PHONY: translate-update translate-update: translate-extract pybabel update --input-file ${LOCALES_DIR}/${UTIL_NAME}.pot \ --update-header-comment \ @@ -33,10 +36,12 @@ translate-update: translate-extract sed -i -e '8d;$$ d' ${TRANSLATIONS_DIR}/en/LC_MESSAGES/${UTIL_NAME}.po sed -i -e '8d;$$ d' ${TRANSLATIONS_DIR}/ru/LC_MESSAGES/${UTIL_NAME}.po +.PHONY: translate-compile translate-compile: pybabel compile --directory ${TRANSLATIONS_DIR} \ --domain ${UTIL_NAME} +.PHONY: translate-init translate-init: @if [ -n "$(LANGUAGE)" ]; then \ pybabel init --input-file ${LOCALES_DIR}/${UTIL_NAME}.pot \