Skip to content

Commit

Permalink
Integrate Babel build steps as a Hatch hook (mkdocs#2992)
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin authored Oct 7, 2022
1 parent 30cdac4 commit 65c24c2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/deploy-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- '*'

jobs:

pypi:
runs-on: ubuntu-latest
steps:
Expand All @@ -15,14 +14,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install -U hatch babel
- name: Compile localization message files
- name: Install Hatch
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
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -U hatch
- name: Build package
run: |
python -m pip install babel
- name: Compile localization message files
hatch build
- name: Check packaged files
shell: bash -e -x {0}
run: |
pybabel compile --statistics --directory mkdocs/themes/mkdocs/locales
pybabel compile --statistics --directory mkdocs/themes/readthedocs/locales
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 changes: 14 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 65c24c2

Please sign in to comment.