diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml index 053986dd..ee1dcc5a 100644 --- a/.github/workflows/deploy-release.yml +++ b/.github/workflows/deploy-release.yml @@ -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 diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 7fc761a7..064c46f9 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -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[@]}" diff --git a/hatch_build.py b/hatch_build.py new file mode 100644 index 00000000..9f76ebdd --- /dev/null +++ b/hatch_build.py @@ -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() diff --git a/pyproject.toml b/pyproject.toml index f80be6c6..34711d8e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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