From 9615a4be8c6f86d39de03a0b3d237d1247cad503 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Tue, 28 Mar 2023 00:29:45 +0200 Subject: [PATCH 1/6] CI: Add missing mdependency --- .woodpecker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.woodpecker.yml b/.woodpecker.yml index 2fda5eff..4ab00e8c 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -4,6 +4,8 @@ pipeline: test: image: python commands: + - apt-get update + - apt-get install -y hunspell hunspell-fr-comprehensive - python3 -m pip install -r requirements.txt - sphinx-lint --enable all --disable line-too-long *.po */*.po - pospell -p dict -l fr_FR *.po */*.po -- 2.30.2 From 7c8e9e4d81739ecb85143e5d3f5fb8968dcf2c12 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Tue, 28 Mar 2023 09:51:41 +0200 Subject: [PATCH 2/6] Drop gawk requirement, drop cpython requirement to run tests. --- .woodpecker.yml | 4 +--- Makefile | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 4ab00e8c..ac61bfe0 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -7,6 +7,4 @@ pipeline: - apt-get update - apt-get install -y hunspell hunspell-fr-comprehensive - python3 -m pip install -r requirements.txt - - sphinx-lint --enable all --disable line-too-long *.po */*.po - - pospell -p dict -l fr_FR *.po */*.po - - awk '{if (length(gensub(/శ్రీనివాస్/, ".", "g", $$0)) > 80 && length(gensub(/[^ ]/, "", "g")) > 1) {print FILENAME ":" FNR, "line too long:", $$0; ERRORS+=1}} END {if (ERRORS>0) {exit 1}}' *.po */*.po + - make verifs diff --git a/Makefile b/Makefile index 1357145a..f8f7d2a5 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,7 @@ else endif .PHONY: all -all: ensure_prerequisites +all: ensure_build_prerequisites git -C venv/cpython checkout $(CPYTHON_CURRENT_COMMIT) || (git -C venv/cpython fetch && git -C venv/cpython checkout $(CPYTHON_CURRENT_COMMIT)) mkdir -p locales/$(LANGUAGE)/LC_MESSAGES/ $(CP_CMD) -u --parents *.po */*.po locales/$(LANGUAGE)/LC_MESSAGES/ @@ -108,13 +108,22 @@ venv/cpython/.git/HEAD: git clone https://github.com/python/cpython venv/cpython -.PHONY: ensure_prerequisites -ensure_prerequisites: venv/cpython/.git/HEAD +.PHONY: ensure_test_prerequisites +ensure_test_prerequisites: + @if ! (pospell --help >/dev/null 2>&1 && potodo --help >/dev/null 2>&1); then \ + echo "You're missing dependencies please install:"; \ + echo ""; \ + echo " python -m pip install -r requirements.txt"; \ + exit 1; \ + fi + +.PHONY: ensure_build_prerequisites +ensure_build_prerequisites: venv/cpython/.git/HEAD @if ! (blurb help >/dev/null 2>&1 && sphinx-build --version >/dev/null 2>&1); then \ git -C venv/cpython/ checkout $(BRANCH); \ echo "You're missing dependencies please install:"; \ echo ""; \ - echo " python -m pip install -r requirements.txt -r venv/cpython/Doc/requirements.txt"; \ + echo " python -m pip install -r venv/cpython/Doc/requirements.txt"; \ exit 1; \ fi @@ -123,11 +132,11 @@ htmlview: MODE=htmlview htmlview: all .PHONY: todo -todo: ensure_prerequisites +todo: ensure_test_prerequisites potodo --api-url 'https://git.afpy.org/api/v1/repos/AFPy/python-docs-fr/issues?state=open&type=issues' --exclude venv .venv $(EXCLUDED) .PHONY: wrap -wrap: ensure_prerequisites +wrap: ensure_test_prerequisites @echo "Re wrapping modified files" powrap -m @@ -136,15 +145,15 @@ SRCS = $(shell git diff --name-only $(BRANCH) | grep '.po$$') DESTS = $(addprefix $(POSPELL_TMP_DIR)/,$(addsuffix .out,$(SRCS))) .PHONY: spell -spell: ensure_prerequisites $(DESTS) +spell: ensure_test_prerequisites $(DESTS) .PHONY: line-length line-length: @echo "Searching for long lines..." - @awk '{if (length(gensub(/శ్రీనివాస్/, ".", "g", $$0)) > 80 && length(gensub(/[^ ]/, "", "g")) > 1) {print FILENAME ":" FNR, "line too long:", $$0; ERRORS+=1}} END {if (ERRORS>0) {exit 1}}' *.po */*.po + @awk '{line=$$0; gsub(/శ్రీనివాస్/, ".", line); if (length(line) > 80) {print FILENAME ":" FNR, "line too long:", $$0; ERRORS+=1}} END {if (ERRORS>0) {exit 1}}' *.po */*.po .PHONY: sphinx-lint -sphinx-lint: +sphinx-lint: ensure_test_prerequisites @echo "Checking all files using sphinx-lint..." @sphinx-lint --enable all --disable line-too-long *.po */*.po @@ -154,7 +163,7 @@ $(POSPELL_TMP_DIR)/%.po.out: %.po dict pospell -p dict -l fr_FR $< && touch $@ .PHONY: fuzzy -fuzzy: ensure_prerequisites +fuzzy: ensure_test_prerequisites potodo --only-fuzzy --api-url 'https://git.afpy.org/api/v1/repos/AFPy/python-docs-fr/issues?state=open&type=issues' --exclude venv .venv $(EXCLUDED) .PHONY: check-headers -- 2.30.2 From 52fcc27bd45458421cc551297f3dfacfd14674f9 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Tue, 28 Mar 2023 11:29:19 +0200 Subject: [PATCH 3/6] Use Python instead of awk for better unicode handling. --- Makefile | 13 ++++++++++++- howto/regex.po | 4 ++-- library/os.po | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index f8f7d2a5..5689df8c 100644 --- a/Makefile +++ b/Makefile @@ -150,7 +150,18 @@ spell: ensure_test_prerequisites $(DESTS) .PHONY: line-length line-length: @echo "Searching for long lines..." - @awk '{line=$$0; gsub(/శ్రీనివాస్/, ".", line); if (length(line) > 80) {print FILENAME ":" FNR, "line too long:", $$0; ERRORS+=1}} END {if (ERRORS>0) {exit 1}}' *.po */*.po +# soft limit is used for splitables lines (with spaces in them) +# hard limit is used for non-splitables lines (without spaces in them) + @python -c 'soft_limit=80; \ + hard_limit=88; \ + from unicodedata import category; \ + import fileinput as fi; \ + clean = lambda line: "".join(char for char in line if category(char) != "Mn").strip(); \ + [print(f"""{fi.filename()}:{fi.filelineno()} line too long ({len(line)} > {soft_limit if line.count(" ") > 1 else hard_limit} characters)""") \ + for _line in fi.input(encoding="utf-8") \ + for line in [clean(_line)] \ + if line.count(" ") > 1 and len(line) > soft_limit or line.count(" ") <= 1 and len(line) > hard_limit]' \ + *.po */*.po .PHONY: sphinx-lint sphinx-lint: ensure_test_prerequisites diff --git a/howto/regex.po b/howto/regex.po index b4163780..eca54de9 100644 --- a/howto/regex.po +++ b/howto/regex.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: Python 3\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-01-15 22:33+0100\n" -"PO-Revision-Date: 2022-12-16 21:12+0100\n" +"PO-Revision-Date: 2023-03-28 11:09+0200\n" "Last-Translator: Nabil Bendafi \n" "Language-Team: FRENCH \n" "Language: fr\n" @@ -1762,7 +1762,7 @@ msgid "" "substitutions." msgstr "" "Les renvois tels que celui-ci ne sont pas très utiles pour effectuer une " -"simple recherche dans une chaîne —­ il n'y a que peu de formats de textes qui " +"simple recherche dans une chaîne — il n'y a que peu de formats de textes qui " "répètent des données ainsi — mais vous verrez bientôt qu'ils sont *très* " "utiles pour effectuer des substitutions dans les chaînes." diff --git a/library/os.po b/library/os.po index b31ca706..2cc7fb56 100644 --- a/library/os.po +++ b/library/os.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: Python 3\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-01-15 22:33+0100\n" -"PO-Revision-Date: 2023-02-09 12:25+0100\n" +"PO-Revision-Date: 2023-03-28 11:15+0200\n" "Last-Translator: Mathieu Dupuy \n" "Language-Team: FRENCH \n" "Language: fr\n" @@ -2372,7 +2372,7 @@ msgstr "" "répertoire, et le chemin sur lequel opérer devrait être relatif. Le chemin " "est donc relatif à ce répertoire. Si le chemin est absolu, *dir_fd* est " "ignoré (pour les systèmes POSIX, Python appelle la version avec un suffixe " -"``at`` et potentiellement préfixée avec ``f`` ­— par exemple ``faccessat`` au " +"``at`` et potentiellement préfixée avec ``f`` — par exemple ``faccessat`` au " "lieu de ``access``)." #: library/os.rst:1733 -- 2.30.2 From 712a2f67381ea0b1bbc3ffa9b0b3f308a2b591a0 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Tue, 28 Mar 2023 11:40:06 +0200 Subject: [PATCH 4/6] Fallabck on full scan if branch is not found. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5689df8c..752cbc87 100644 --- a/Makefile +++ b/Makefile @@ -140,7 +140,7 @@ wrap: ensure_test_prerequisites @echo "Re wrapping modified files" powrap -m -SRCS = $(shell git diff --name-only $(BRANCH) | grep '.po$$') +SRCS = $(shell git diff --name-only $(BRANCH) 2>/dev/null | grep '.po$$' || echo *.po */*.po) # foo/bar.po => $(POSPELL_TMP_DIR)/foo/bar.po.out DESTS = $(addprefix $(POSPELL_TMP_DIR)/,$(addsuffix .out,$(SRCS))) -- 2.30.2 From 3a64e23583595a923676fc06276601d552bb9efa Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Tue, 28 Mar 2023 11:45:25 +0200 Subject: [PATCH 5/6] Or get the branch? --- .woodpecker.yml | 3 +++ Makefile | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index ac61bfe0..8c96fd07 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -7,4 +7,7 @@ pipeline: - apt-get update - apt-get install -y hunspell hunspell-fr-comprehensive - python3 -m pip install -r requirements.txt + - BRANCH="$(grep ^BRANCH Makefile | awk '{print $3}')" + - git fetch origin --no-tags +refs/heads/$BRANCH + - git branch $BRANCH origin/$BRANCH - make verifs diff --git a/Makefile b/Makefile index 752cbc87..5689df8c 100644 --- a/Makefile +++ b/Makefile @@ -140,7 +140,7 @@ wrap: ensure_test_prerequisites @echo "Re wrapping modified files" powrap -m -SRCS = $(shell git diff --name-only $(BRANCH) 2>/dev/null | grep '.po$$' || echo *.po */*.po) +SRCS = $(shell git diff --name-only $(BRANCH) | grep '.po$$') # foo/bar.po => $(POSPELL_TMP_DIR)/foo/bar.po.out DESTS = $(addprefix $(POSPELL_TMP_DIR)/,$(addsuffix .out,$(SRCS))) -- 2.30.2 From ca8099afb22c12c365648b3de78c2f9124a3c71e Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Thu, 30 Mar 2023 09:40:37 +0200 Subject: [PATCH 6/6] Move scripts to a .scripts/ directory. --- .gitignore | 1 + .scripts/line-length.py | 38 +++++++++++++++++++++++++++++++++++ merge.py => .scripts/merge.py | 0 Makefile | 13 +----------- 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 .scripts/line-length.py rename merge.py => .scripts/merge.py (100%) diff --git a/.gitignore b/.gitignore index 6d4d663d..78c4fbf3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ venv/ .potodo/ locales/ .venv/ +.envrc diff --git a/.scripts/line-length.py b/.scripts/line-length.py new file mode 100644 index 00000000..b4ac21f4 --- /dev/null +++ b/.scripts/line-length.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +"""Measure line length in given files, run as: + + python line-length.py *.po + +It does not count zero-width caracters from the Mn Unicode category +(Nonspacing Mark). + +It returns 0 on success, 1 on failure. +""" + +from unicodedata import category +import fileinput +import sys + +SOFT_LIMIT = 80 # used for splitables lines (with spaces in them) +HARD_LIMIT = 88 # used for non-splitables lines (without spaces in them) + + +def clean(line): + return "".join(char for char in line if category(char) != "Mn").rstrip("\n") + + +return_code = 0 + +for line in fileinput.input(encoding="utf-8"): + line = clean(line) + limit = SOFT_LIMIT if line.count(" ") > 1 else HARD_LIMIT + if len(line) > limit: + print( + f"{fileinput.filename()}:{fileinput.filelineno()} line too long " + f"({len(line)} > {limit} characters)", + file=sys.stderr, + ) + return_code = 1 + + +sys.exit(return_code) diff --git a/merge.py b/.scripts/merge.py similarity index 100% rename from merge.py rename to .scripts/merge.py diff --git a/Makefile b/Makefile index 5689df8c..6042da54 100644 --- a/Makefile +++ b/Makefile @@ -150,18 +150,7 @@ spell: ensure_test_prerequisites $(DESTS) .PHONY: line-length line-length: @echo "Searching for long lines..." -# soft limit is used for splitables lines (with spaces in them) -# hard limit is used for non-splitables lines (without spaces in them) - @python -c 'soft_limit=80; \ - hard_limit=88; \ - from unicodedata import category; \ - import fileinput as fi; \ - clean = lambda line: "".join(char for char in line if category(char) != "Mn").strip(); \ - [print(f"""{fi.filename()}:{fi.filelineno()} line too long ({len(line)} > {soft_limit if line.count(" ") > 1 else hard_limit} characters)""") \ - for _line in fi.input(encoding="utf-8") \ - for line in [clean(_line)] \ - if line.count(" ") > 1 and len(line) > soft_limit or line.count(" ") <= 1 and len(line) > hard_limit]' \ - *.po */*.po + @python .scripts/line-length.py *.po */*.po .PHONY: sphinx-lint sphinx-lint: ensure_test_prerequisites -- 2.30.2