Integrate Babel build steps as a Hatch hook (#2992)

This commit is contained in:
Oleh Prypin
2022-10-07 18:07:35 +02:00
committed by GitHub
parent 30cdac47a9
commit 65c24c21f0
4 changed files with 34 additions and 15 deletions

View File

@@ -6,7 +6,6 @@ on:
- '*'
jobs:
pypi:
runs-on: ubuntu-latest
steps:
@@ -15,14 +14,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
- name: Install Hatch
run: |
python -m pip install -U hatch babel
- name: Compile localization message files
run: |
pybabel compile --statistics --directory mkdocs/themes/mkdocs/locales
pybabel compile --statistics --directory mkdocs/themes/readthedocs/locales
- name: Build
python -m pip install -U hatch
- name: Build package
run: |
hatch build
- name: Publish

View File

@@ -93,18 +93,24 @@ jobs:
if: always()
run: python -m tox -e codespell
translation:
package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install Python dependencies
python-version: 3.9
- name: Install Hatch
run: |
python -m pip install babel
- name: Compile localization message files
python -m pip install -U hatch
- name: Build package
run: |
pybabel compile --statistics --directory mkdocs/themes/mkdocs/locales
pybabel compile --statistics --directory mkdocs/themes/readthedocs/locales
hatch build
- name: Check packaged files
shell: bash -e -x {0}
run: |
expected_wheel=(-emkdocs/{templates/sitemap.xml,config/base.py,py.typed,contrib/search/lunr-language/lunr.nl.js,themes/{mkdocs,readthedocs}/{base.html,locales/{de,es}/LC_MESSAGES/messages.mo}})
expected_sdist=("${expected_wheel[@]}" -e{pyproject.toml,hatch_build.py})
test "$(tar -ztf dist/mkdocs-*.tar.gz | grep -F "${expected_sdist[@]}" | tee /dev/stderr | wc -l)" -eq "${#expected_sdist[@]}"
test "$(unzip -l dist/mkdocs-*any.whl | grep -F "${expected_wheel[@]}" | tee /dev/stderr | wc -l)" -eq "${#expected_wheel[@]}"

14
hatch_build.py Normal file
View File

@@ -0,0 +1,14 @@
import os
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
class CustomBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
from babel.messages.frontend import compile_catalog
for theme in 'mkdocs', 'readthedocs':
cmd = compile_catalog()
cmd.directory = os.path.join('mkdocs', 'themes', theme, 'locales')
cmd.finalize_options()
cmd.run()

View File

@@ -75,6 +75,10 @@ artifacts = ["/mkdocs/**/*.mo"]
include = ["/mkdocs"]
[tool.hatch.build.targets.wheel]
exclude = ["/mkdocs/tests/integration", "*.po", "*.pot", "babel.cfg"]
[tool.hatch.build.hooks.custom]
dependencies = [
"babel",
]
[tool.black]
line-length = 100