Skip to content

Commit 737ec92

Browse files
Switch to Hatchling build hooks for i18n packaging and exclude .po from wheels
1 parent f070136 commit 737ec92

5 files changed

Lines changed: 17 additions & 12 deletions

File tree

.github/workflows/pypi-package.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ jobs:
2525
persist-credentials: false
2626
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
2727

28-
- name: Compile translations
29-
run: |
30-
pip install --upgrade pip
31-
pip install -r requirements.txt
32-
python babel_runner.py compile
33-
3428
- uses: hynek/build-and-inspect-python-package@fe0a0fb1925ca263d076ca4f2c13e93a6e92a33e # v2.17.0
3529

3630
# Upload to real PyPI on GitHub Releases.

babel_runner.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import tomllib
99
from pathlib import Path
1010

11+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
12+
1113
# Global variables used by pybabel below (paths relative to PROJECT_DIR)
1214
DOMAIN = "python-docs-theme"
1315
COPYRIGHT_HOLDER = "Python Software Foundation"
@@ -106,6 +108,11 @@ def compile_catalogs(locale: str) -> None:
106108
subprocess.run(cmd, cwd=PROJECT_DIR, check=True)
107109

108110

111+
class CustomBuildHook(BuildHookInterface):
112+
def initialize(self, version: str, build_data: dict[str, object]) -> None:
113+
compile_catalogs("")
114+
115+
109116
def main() -> None:
110117
parser = argparse.ArgumentParser(description=__doc__)
111118
parser.add_argument(

pyproject.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[build-system]
2-
build-backend = "flit_core.buildapi"
2+
build-backend = "hatchling.build"
33
requires = [
4-
"flit-core>=3.7",
4+
"babel",
5+
"hatchling",
56
]
67

78
[project]
@@ -36,9 +37,12 @@ urls.Download = "https://pypi.org/project/python-docs-theme/"
3637
urls.Homepage = "https://github.com/python/python-docs-theme/"
3738
entry-points."sphinx.html_themes".python_docs_theme = "python_docs_theme"
3839

39-
[tool.flit]
40-
module.name = "python_docs_theme"
41-
sdist.include = [ "python_docs_theme/" ]
40+
[tool.hatch]
41+
build.artifacts = [ "python_docs_theme/locale/**/*.mo" ]
42+
build.hooks.custom.path = "babel_runner.py"
43+
build.targets.wheel.packages = [ "python_docs_theme" ]
44+
build.targets.wheel.exclude = [ "python_docs_theme/locale/**/*.po" ]
45+
version.path = "python_docs_theme/__init__.py"
4246

4347
[tool.ruff]
4448
fix = true

python_docs_theme/locale/de/LC_MESSAGES/python-docs-theme.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# Translators:
88
# Cristián Maureira-Fredes, 2025
99
#
10-
#, fuzzy
1110
msgid ""
1211
msgstr ""
1312
"Project-Id-Version: python-docs-theme 2025.5\n"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# for babel_runner.py
22
Babel
3+
hatchling
34
Jinja2

0 commit comments

Comments
 (0)