python-docs-fr/.scripts/line-length.py
Julien Palard c68566b785 Fully working CI (#118)
Ça commence à marcher, par contre on a un souci avec un :rfc: dans pospell :

    <rst-doc>:1: (ERROR/3) RFC number must be a number greater than or equal to 1; "la spécification correspondante <5424#section-6>" is invalid. while parsing: La :rfc:`5424` requiert qu’un message Unicode soit envoyé à un démon *syslog* sous la forme d’un ensemble d’octets ayant la structure suivante : un composant ASCII pur facultatif, suivi d’une marque d’ordre d’octet (*BOM* pour *Byte Order Mark* en anglais) UTF-8, suivie de contenu Unicode UTF-8 (voir la :rfc:`la spécification correspondante <5424#section-6>`).

Reviewed-on: AFPy/python-docs-fr#118
2023-04-01 19:44:08 +00:00

39 lines
945 B
Python

#!/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)