view locale/Makefile @ 7752:b2dbab2b34bc

fix(refactor): multiple fixups using ruff linter; more testing. Converting to using the ruff linter and its rulesets. Fixed a number of issues. admin.py: sort imports use immutable tuples as default value markers for parameters where a None value is valid. reduced some loops to list comprehensions for performance used ternary to simplify some if statements named some variables to make them less magic (e.g. _default_savepoint_setting = 1000) fixed some tests for argument counts < 2 becomes != 2 so 3 is an error. moved exception handlers outside of loops for performance where exception handler will abort loop anyway. renamed variables called 'id' or 'dir' as they shadow builtin commands. fix translations of form _("string %s" % value) -> _("string %s") % value so translation will be looked up with the key before substitution. end dicts, tuples with a trailing comma to reduce missing comma errors if modified simplified sorted(list(self.setting.keys())) to sorted(self.setting.keys()) as sorted consumes whole list. in if conditions put compared variable on left and threshold condition on right. (no yoda conditions) multiple noqa: suppression removed unneeded noqa as lint rulesets are a bit different do_get - refactor output printing logic: Use fast return if not special formatting is requested; use isinstance with a tuple rather than two isinstance calls; cleaned up flow and removed comments on algorithm as it can be easily read from the code. do_filter, do_find - refactor output printing logic. Reduce duplicate code. do_find - renamed variable 'value' that was set inside a loop. The loop index variable was also named 'value'. do_pragma - added hint to use list subcommand if setting was not found. Replaced condition 'type(x) is bool' with 'isinstance(x, bool)' for various types. test_admin.py added testing for do_list better test coverage for do_get includes: -S and -d for multilinks, error case for -d with non-link. better testing for do_find including all output modes better testing for do_filter including all output modes fixed expected output for do_pragma that now includes hint to use pragma list if setting not found.
author John Rouillard <rouilj@ieee.org>
date Fri, 01 Mar 2024 14:53:18 -0500
parents b54653a182a9
children ed0fce27fd75
line wrap: on
line source

# Extract translatable strings from Roundup sources,
# update and compile all existing translations

# tool locations
XPOT ?= xpot
MSGFMT ?= msgfmt
MSGMERGE ?= msgmerge
XGETTEXT ?= xgettext
PYTHON ?= python3

TEMPLATE=roundup.pot

PACKAGES=$(shell find ../roundup ../share/roundup/templates -name '*.py' \
	 | sed -e 's,/[^/]*$$,,' | sort | uniq)
SOURCES=$(PACKAGES:=/*.py)
PO_FILES=$(wildcard *.po)
MO_FILES=$(PO_FILES:.po=.mo)
RUN_PYTHON=PYTHONPATH=.. $(PYTHON) -O

all: dist

help:
	@echo "$(MAKE)           - build MO files.  Run this before sdist"
	@echo "$(MAKE) dist      - same as above"
	@echo "$(MAKE) template  - update message template from sources"
	@echo "$(MAKE) merge     - merge template into *.po files"
	@echo "$(MAKE) diff      - see template differences in vi"
	@echo "$(MAKE) potest    - check .po files for errors"
	@echo "$(MAKE) pytest    - create locale files to run pytest"
	@echo "$(MAKE) locale.po - update message file from template"
	@echo "$(MAKE) locale.mo - compile individual message file"
	@echo "$(MAKE) help      - this text"
	@echo ""
	@echo "Running make dist is the same as: make template merge dist"

# This will rebuild all MO files without updating their corresponding PO
# files first.  Run before creating Roundup distribution (hence the name).
# PO files should be updated by their translators only, automatic update
# adds unwanted fuzzy labels.
dist: $(MO_FILES)

template: roundup.pot

pytest local_install:
	for file in $(PO_FILES); do \
           ${MSGFMT} -o `basename $$file .po`.mo $$file; \
	done
	for file in $(MO_FILES); do \
	   lang=`basename $$file .mo`; \
	   mkdir -p locale/$$lang/LC_MESSAGES; \
	   cp $$file locale/$$lang/LC_MESSAGES/roundup.mo; \
	done

# helps to check template file before check in
diff:
	hg cat roundup.pot | diff -u -I '^\#: \.\./roundup.*$$' \
	                             -I '^#:\s*:[0-9]*.*$$' \
                                     - roundup.pot || exit 0
merge: $(PO_FILES)

potest:
	 sh -c 'for file in $(PO_FILES); do \
	   ${MSGFMT} -cv --statistics $$file; \
	done' 2>&1 | sort -k 2,2n

%.po: $(TEMPLATE)
	@echo "Rebuild $@"
	@${MSGMERGE} -U --suffix=.bak $@ $<
	@# update Project-Id-Version to match roundup.pot
	@VER="`sed -ne \"/__version__/s/.*'\(.*\)'.*/\1/p\" \
	      ../roundup/__init__.py`"; \
	sed -i -e \
          "s/^\(\"Project-Id-Version: Roundup\).*/\1 $${VER}\\\\n\"/" $@

%.mo: %.po
	${MSGFMT} -o $@ $<

roundup.pot: $(SOURCES) $(TEMPLATES)
	${XPOT} -n -o $(TEMPLATE) $(SOURCES) 2>&1 | sed -e "/: Unexpected in Python source: #64 \`@'/d"

	${RUN_PYTHON} ../roundup/cgi/TAL/talgettext.py -u $(TEMPLATE) \
	  ../share/roundup/templates/classic/html/*.html \
	  ../share/roundup/templates/devel/html/*.html \
	  ../share/roundup/templates/minimal/html/*.html \
	  ../share/roundup/templates/responsive/html/*.html
	VERSION="`sed -ne \"/__version__/s/.*'\(.*\)'.*/\1/p\" \
	      ../roundup/__init__.py`"; \
	${XGETTEXT} -j -w 80 -F \
	  --package-name=Roundup \
	  --package-version=$$VERSION \
	  --msgid-bugs-address=roundup-devel@lists.sourceforge.net \
	  --copyright-holder="See Roundup README.txt" \
	  -o $(TEMPLATE) $(SOURCES)


Roundup Issue Tracker: http://roundup-tracker.org/