Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ tox -e py -- tests/test_number.py
tox -e py -- tests/test_number.py -k intcomma
```

Some localisation tests are skipped when compiled `.mo` translation files are missing.
Generate them with `scripts/generate-translation-binaries.sh`, which requires Bash and
GNU gettext's `msgfmt`. Translation-update tests also require `xgettext` and `msgmerge`.
Use `tox -e py -- -rs` to see skip reasons.

CI generates translation binaries and runs the
[configured tox environments](../tox.ini). See the [test workflow](workflows/test.yml)
for supported Python versions and platforms.
The tox test environments compile the `.mo` translation binaries from the `.po` catalogs
before running the tests. When running `pytest` directly, some localisation tests are
skipped if the `.mo` files are missing. Generate them with:

```sh
tox -e compile-translations
```

Translation-update tests also require GNU gettext's `xgettext` and `msgmerge`. Use
`tox -e py -- -rs` to see skip reasons.

CI runs the [configured tox environments](../tox.ini). See the
[test workflow](workflows/test.yml) for supported Python versions and platforms.

## Linting

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/actions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ workflows:
'.github/workflows/benchmark.yml':
- 'actions/checkout@v7.0.1'
- 'actions/setup-python@v7.1.0'
- 'astral-sh/setup-uv@v10.3.2'
- 'codspeedhq/action@v5.6.0'
'.github/workflows/docs.yml':
- 'actions/checkout@v7.0.1'
Expand All @@ -28,6 +29,7 @@ workflows:
'.github/workflows/release.yml':
- 'actions/checkout@v7.0.1'
- 'actions/download-artifact@v8.0.2'
- 'astral-sh/setup-uv@v10.3.2'
- 'hynek/build-and-inspect-python-package@v3.0.2'
- 'pypa/gh-action-pypi-publish@v1.14.3'
'.github/workflows/require-pr-label.yml':
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ jobs:
python-version: "3.15"
allow-prereleases: true

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

- name: Generate translation binaries
- name: Compile translations
run: |
scripts/generate-translation-binaries.sh
uvx --with tox-uv tox -e compile-translations

- name: Install dependencies
run: pip install -e ".[tests]"
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ jobs:
fetch-depth: 0
persist-credentials: false

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

- name: Generate translation binaries
- name: Compile translations
run: |
scripts/generate-translation-binaries.sh
uvx --with tox-uv tox -e compile-translations

- uses: hynek/build-and-inspect-python-package@v3.0.2

Expand Down
45 changes: 29 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,9 @@ jobs:
run: |
echo "PYTHON_GIL=0" >> "$GITHUB_ENV"

- name: Install Linux dependencies
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt install gettext

- name: Install macOS dependencies
if: startsWith(matrix.os, 'macos')
run: |
brew install gettext

- name: Install uv
uses: astral-sh/setup-uv@v10.3.2

- name: Generate translation binaries
run: |
scripts/generate-translation-binaries.sh

- name: Tox tests
run: |
uvx --python ${{ matrix.python-version }} --with tox-uv tox -e py
Expand All @@ -69,13 +55,40 @@ jobs:
flags: ${{ matrix.os }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}

translations:
name: Translation catalogs up to date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7.0.1
with:
persist-credentials: false

- name: Install gettext
run: |
sudo apt install gettext

- name: Update translations
run: |
scripts/update-translations.sh

- name: Check catalogs are up to date
run: |
if ! git diff --exit-code -I '^"POT-Creation-Date: ' -- src/humanize/locale; then
echo "::error::Translation catalogs are out of date." \
"Run scripts/update-translations.sh and commit the .po changes."
exit 1
fi

success:
if: always()
needs: test
needs: [test, translations]
runs-on: ubuntu-latest
name: Test successful
steps:
- name: Success
env:
TEST_RESULT: ${{ needs.test.result }}
run: test "$TEST_RESULT" = "success"
TRANSLATIONS_RESULT: ${{ needs.translations.result }}
run: |
test "$TEST_RESULT" = "success"
test "$TRANSLATIONS_RESULT" = "success"
8 changes: 0 additions & 8 deletions scripts/generate-translation-binaries.sh

This file was deleted.

41 changes: 21 additions & 20 deletions src/humanize/filesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
__lazy_modules__ = {"humanize.i18n"}

from humanize.i18n import _gettext as _
from humanize.i18n import _gettext_noop as N_

suffixes = {
"decimal": (
"kB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB",
"RB",
"QB",
N_("kB"),
N_("MB"),
N_("GB"),
N_("TB"),
N_("PB"),
N_("EB"),
N_("ZB"),
N_("YB"),
N_("RB"),
N_("QB"),
),
"binary": (
"KiB",
"MiB",
"GiB",
"TiB",
"PiB",
"EiB",
"ZiB",
"YiB",
"RiB",
"QiB",
N_("KiB"),
N_("MiB"),
N_("GiB"),
N_("TiB"),
N_("PiB"),
N_("EiB"),
N_("ZiB"),
N_("YiB"),
N_("RiB"),
N_("QiB"),
),
"gnu": "KMGTPEZYRQ",
}
Expand Down
Loading
Loading