-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMakefile
More file actions
109 lines (88 loc) · 4.28 KB
/
Copy pathMakefile
File metadata and controls
109 lines (88 loc) · 4.28 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
.DEFAULT_GOAL := help
.PHONY: upgrade help requirements lint format test docs
.PHONY: extract_translations compile_translations
.PHONY: detect_changed_source_translations dummy_translations build_dummy_translations
.PHONY: validate_translations pull_translations push_translations install_transifex_clients
PACKAGE_NAME := xblocks_contrib
EXTRACT_DIR := conf/locale/en/LC_MESSAGES
COMBINED_LOCALE_DIR := $(PACKAGE_NAME)/conf/locale/en/LC_MESSAGES
JS_TARGET := $(PACKAGE_NAME)/public/js/translations
help:
@perl -nle'print $& if m{^[\.a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}'
lint: ## run linting checks
tox -e quality
format: ## auto-fix ruff lint and formatting issues
uv run ruff check --fix .
uv run ruff format .
test: ## run tests against all supported Python/Django combinations
tox -e "py312-django{42,52}"
docs: ## build documentation
tox -e docs
upgrade: ## update uv.lock and regenerate uv constraints from edx-lint
uv run --with edx-lint edx_lint write_uv_constraints pyproject.toml
uv lock --upgrade
requirements: ## install development environment requirements using uv
uv sync --group dev
uv tool install tox --with tox-uv
# XBlock directories
XBLOCKS=$(shell find $(shell pwd)/$(PACKAGE_NAME) -mindepth 2 -maxdepth 2 -type d -name 'conf' -exec dirname {} \;)
## Localization targets
extract_translations: ## extract strings to be translated, outputting .po files for each XBlock
@for xblock in $(XBLOCKS); do \
echo "Extracting translations for $$xblock..."; \
cd $$xblock && i18n_tool extract --no-segment; \
if [ -f $$xblock/$(EXTRACT_DIR)/djangojs.po ]; then \
cd $$xblock/$(EXTRACT_DIR) && msgcat django.po djangojs.po -o django.po && rm -f djangojs.po; \
fi; \
if [ -f $$xblock/$(EXTRACT_DIR)/django.po ]; then \
mv $$xblock/$(EXTRACT_DIR)/django.po $$xblock/$(EXTRACT_DIR)/text.po; \
fi; \
done
@# Merge all per-xblock text.po files into a single combined file for the
@# openedx-translations pipeline (OEP-58), which expects one conf/locale/en per repo.
@mkdir -p $(COMBINED_LOCALE_DIR)
@PO_FILES=""; \
for xblock in $(XBLOCKS); do \
if [ -f $$xblock/$(EXTRACT_DIR)/text.po ]; then \
PO_FILES="$$PO_FILES $$xblock/$(EXTRACT_DIR)/text.po"; \
fi; \
done; \
if [ -n "$$PO_FILES" ]; then \
msgcat --use-first $$PO_FILES -o $(COMBINED_LOCALE_DIR)/django.po; \
echo "Combined translation source file written to $(COMBINED_LOCALE_DIR)/django.po"; \
fi
compile_translations: ## compile translation files, outputting .mo files for each supported language for each XBlock
@for xblock in $(XBLOCKS); do \
echo "Compiling translations for $$xblock..."; \
cd $$xblock && django-admin compilemessages --locale en; \
done
detect_changed_source_translations:
@for xblock in $(XBLOCKS); do \
echo "Detecting changed translations for $$xblock..."; \
cd $$xblock && i18n_tool changed; \
done
dummy_translations: ## generate dummy translation (.po) files for each XBlock
@for xblock in $(XBLOCKS); do \
echo "Generating dummy translations for $$xblock..."; \
cd $$xblock && i18n_tool dummy; \
done
build_dummy_translations: extract_translations dummy_translations compile_translations ## generate and compile dummy translation files
validate_translations: build_dummy_translations detect_changed_source_translations ## validate translations
pull_translations: ## pull translations from Transifex for each XBlock
@for xblock in $(XBLOCKS); do \
echo "Pulling translations for $$xblock..."; \
cd $$xblock && i18n_tool transifex pull; \
done
push_translations: extract_translations ## push translations to Transifex for each XBlock
@for xblock in $(XBLOCKS); do \
echo "Pushing translations for $$xblock..."; \
cd $$xblock && i18n_tool transifex push; \
done
install_transifex_client: ## Install the Transifex client
# Instaling client will skip CHANGELOG and LICENSE files from git changes
# so remind the user to commit the change first before installing client.
git diff -s --exit-code HEAD || { echo "Please commit changes first."; exit 1; }
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
git checkout -- LICENSE README.md ## overwritten by Transifex installer
selfcheck: ## check that the Makefile is well-formed
@echo "The Makefile is well-formed."