Skip to content

Commit 874eeb7

Browse files
authored
Fix untranslated filesize units and compile catalogs in tox (#514)
2 parents 2ee2a83 + 35ec6a7 commit 874eeb7

45 files changed

Lines changed: 7425 additions & 4124 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/CONTRIBUTING.md‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ tox -e py -- tests/test_number.py
1717
tox -e py -- tests/test_number.py -k intcomma
1818
```
1919

20-
Some localisation tests are skipped when compiled `.mo` translation files are missing.
21-
Generate them with `scripts/generate-translation-binaries.sh`, which requires Bash and
22-
GNU gettext's `msgfmt`. Translation-update tests also require `xgettext` and `msgmerge`.
23-
Use `tox -e py -- -rs` to see skip reasons.
24-
25-
CI generates translation binaries and runs the
26-
[configured tox environments](../tox.ini). See the [test workflow](workflows/test.yml)
27-
for supported Python versions and platforms.
20+
The tox test environments compile the `.mo` translation binaries from the `.po` catalogs
21+
before running the tests. When running `pytest` directly, some localisation tests are
22+
skipped if the `.mo` files are missing. Generate them with:
23+
24+
```sh
25+
tox -e compile-translations
26+
```
27+
28+
Translation-update tests also require GNU gettext's `xgettext` and `msgmerge`. Use
29+
`tox -e py -- -rs` to see skip reasons.
30+
31+
CI runs the [configured tox environments](../tox.ini). See the
32+
[test workflow](workflows/test.yml) for supported Python versions and platforms.
2833

2934
## Linting
3035

‎.github/workflows/actions.lock‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ workflows:
66
'.github/workflows/benchmark.yml':
77
- 'actions/checkout@v7.0.1'
88
- 'actions/setup-python@v7.1.0'
9+
- 'astral-sh/setup-uv@v10.3.2'
910
- 'codspeedhq/action@v5.6.0'
1011
'.github/workflows/docs.yml':
1112
- 'actions/checkout@v7.0.1'
@@ -28,6 +29,7 @@ workflows:
2829
'.github/workflows/release.yml':
2930
- 'actions/checkout@v7.0.1'
3031
- 'actions/download-artifact@v8.0.2'
32+
- 'astral-sh/setup-uv@v10.3.2'
3133
- 'hynek/build-and-inspect-python-package@v3.0.2'
3234
- 'pypa/gh-action-pypi-publish@v1.14.3'
3335
'.github/workflows/require-pr-label.yml':

‎.github/workflows/benchmark.yml‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ jobs:
2222
python-version: "3.15"
2323
allow-prereleases: true
2424

25-
- name: Install gettext
26-
run: |
27-
sudo apt install gettext
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v10.3.2
2827

29-
- name: Generate translation binaries
28+
- name: Compile translations
3029
run: |
31-
scripts/generate-translation-binaries.sh
30+
uvx --with tox-uv tox -e compile-translations
3231
3332
- name: Install dependencies
3433
run: pip install -e ".[tests]"

‎.github/workflows/release.yml‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ jobs:
2828
fetch-depth: 0
2929
persist-credentials: false
3030

31-
- name: Install gettext
32-
run: |
33-
sudo apt install gettext
31+
- name: Install uv
32+
uses: astral-sh/setup-uv@v10.3.2
3433

35-
- name: Generate translation binaries
34+
- name: Compile translations
3635
run: |
37-
scripts/generate-translation-binaries.sh
36+
uvx --with tox-uv tox -e compile-translations
3837
3938
- uses: hynek/build-and-inspect-python-package@v3.0.2
4039

‎.github/workflows/test.yml‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,9 @@ jobs:
4242
run: |
4343
echo "PYTHON_GIL=0" >> "$GITHUB_ENV"
4444
45-
- name: Install Linux dependencies
46-
if: startsWith(matrix.os, 'ubuntu')
47-
run: |
48-
sudo apt install gettext
49-
50-
- name: Install macOS dependencies
51-
if: startsWith(matrix.os, 'macos')
52-
run: |
53-
brew install gettext
54-
5545
- name: Install uv
5646
uses: astral-sh/setup-uv@v10.3.2
5747

58-
- name: Generate translation binaries
59-
run: |
60-
scripts/generate-translation-binaries.sh
61-
6248
- name: Tox tests
6349
run: |
6450
uvx --python ${{ matrix.python-version }} --with tox-uv tox -e py
@@ -69,13 +55,40 @@ jobs:
6955
flags: ${{ matrix.os }}
7056
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
7157

58+
translations:
59+
name: Translation catalogs up to date
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v7.0.1
63+
with:
64+
persist-credentials: false
65+
66+
- name: Install gettext
67+
run: |
68+
sudo apt install gettext
69+
70+
- name: Update translations
71+
run: |
72+
scripts/update-translations.sh
73+
74+
- name: Check catalogs are up to date
75+
run: |
76+
if ! git diff --exit-code -I '^"POT-Creation-Date: ' -- src/humanize/locale; then
77+
echo "::error::Translation catalogs are out of date." \
78+
"Run scripts/update-translations.sh and commit the .po changes."
79+
exit 1
80+
fi
81+
7282
success:
7383
if: always()
74-
needs: test
84+
needs: [test, translations]
7585
runs-on: ubuntu-latest
7686
name: Test successful
7787
steps:
7888
- name: Success
7989
env:
8090
TEST_RESULT: ${{ needs.test.result }}
81-
run: test "$TEST_RESULT" = "success"
91+
TRANSLATIONS_RESULT: ${{ needs.translations.result }}
92+
run: |
93+
test "$TEST_RESULT" = "success"
94+
test "$TRANSLATIONS_RESULT" = "success"

‎scripts/generate-translation-binaries.sh‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎src/humanize/filesize.py‎

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,32 @@
55
__lazy_modules__ = {"humanize.i18n"}
66

77
from humanize.i18n import _gettext as _
8+
from humanize.i18n import _gettext_noop as N_
89

910
suffixes = {
1011
"decimal": (
11-
"kB",
12-
"MB",
13-
"GB",
14-
"TB",
15-
"PB",
16-
"EB",
17-
"ZB",
18-
"YB",
19-
"RB",
20-
"QB",
12+
N_("kB"),
13+
N_("MB"),
14+
N_("GB"),
15+
N_("TB"),
16+
N_("PB"),
17+
N_("EB"),
18+
N_("ZB"),
19+
N_("YB"),
20+
N_("RB"),
21+
N_("QB"),
2122
),
2223
"binary": (
23-
"KiB",
24-
"MiB",
25-
"GiB",
26-
"TiB",
27-
"PiB",
28-
"EiB",
29-
"ZiB",
30-
"YiB",
31-
"RiB",
32-
"QiB",
24+
N_("KiB"),
25+
N_("MiB"),
26+
N_("GiB"),
27+
N_("TiB"),
28+
N_("PiB"),
29+
N_("EiB"),
30+
N_("ZiB"),
31+
N_("YiB"),
32+
N_("RiB"),
33+
N_("QiB"),
3334
),
3435
"gnu": "KMGTPEZYRQ",
3536
}

0 commit comments

Comments
 (0)