Skip to content

Commit

Permalink
chore: move from setuptools to hatch_build
Browse files Browse the repository at this point in the history
packages are built with hatch instead of setuptools.
Translations catalogs are compiled at package build time, and before unit tests are
ran. Thus there is no need to keep them versioned in git anymore.
  • Loading branch information
azmeuk committed Nov 12, 2023
1 parent e507b44 commit e51715e
Show file tree
Hide file tree
Showing 41 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.pyc
*.egg-info
*.mo
dist
.venv
docs/_build/
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ remove-install-stamp:
update: remove-install-stamp install ## Update the dependencies

.PHONY: serve
serve: install ## Run the ihatemoney server
serve: install build-translations ## Run the ihatemoney server
@echo 'Running ihatemoney on http://localhost:5000'
FLASK_DEBUG=1 FLASK_APP=ihatemoney.wsgi $(VENV)/bin/flask run --host=0.0.0.0

Expand Down Expand Up @@ -74,8 +74,8 @@ compress-assets: compress-showcase ## Compress static assets
build-translations: ## Build the translations
$(VENV)/bin/pybabel compile -d ihatemoney/translations

.PHONY: update-translations
update-translations: ## Extract new translations from source code
.PHONY: extract-translations
extract-translations: ## Extract new translations from source code
$(VENV)/bin/pybabel extract --add-comments "I18N:" --strip-comments --omit-header --no-location --mapping-file ihatemoney/babel.cfg -o ihatemoney/messages.pot ihatemoney
$(VENV)/bin/pybabel update -i ihatemoney/messages.pot -d ihatemoney/translations/

Expand Down
5 changes: 2 additions & 3 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,9 @@ In order to issue a new release, follow the following steps:

make compress-assets

- Build the translations:
- Extract the translations:

make update-translations
make build-translations
make extract-translations

- If you're not completely sure of yourself at this point, you can
optionally: create a new branch, push it, open a pull request, check
Expand Down
14 changes: 14 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class CustomBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
from babel.messages.frontend import compile_catalog

cmd = compile_catalog()
cmd.directory = Path(__file__).parent / "ihatemoney" / "translations"
cmd.statistics = True
cmd.finalize_options()
cmd.run()
11 changes: 11 additions & 0 deletions ihatemoney/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
from pathlib import Path
from unittest.mock import MagicMock

from babel.messages.frontend import compile_catalog
from flask import Flask
import pytest

from ihatemoney.currency_convertor import CurrencyConverter
from ihatemoney.run import create_app, db


@pytest.fixture(autouse=True, scope="session")
def babel_catalogs():
cmd = compile_catalog()
cmd.directory = Path(__file__).parent.parent / "translations"
cmd.quiet = True
cmd.finalize_options()
cmd.run()


@pytest.fixture
def app(request: pytest.FixtureRequest):
"""Create the Flask app with database"""
Expand Down
Binary file removed ihatemoney/translations/bn/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file not shown.
Binary file removed ihatemoney/translations/ca/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/cs/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/de/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/el/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/eo/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/es/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file not shown.
Binary file removed ihatemoney/translations/fa/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file not shown.
Binary file removed ihatemoney/translations/he/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/hi/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/hu/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/id/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/it/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/ja/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/kn/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/ms/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file not shown.
Binary file removed ihatemoney/translations/nl/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/pl/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/pt/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file not shown.
Binary file removed ihatemoney/translations/ru/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/sr/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/sv/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/ta/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/te/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/th/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/tr/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/uk/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/ur/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file removed ihatemoney/translations/vi/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file not shown.
13 changes: 9 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ihatemoney"
Expand Down Expand Up @@ -84,5 +84,10 @@ doc = [
[project.scripts]
ihatemoney = "ihatemoney.manage:cli"

[tool.setuptools]
packages = ["ihatemoney"]
[tool.hatch.build.hooks.custom]
dependencies = [
"Babel>=2.6.0"
]

[tool.hatch.build]
artifacts = ["ihatemoney/translations/**/*.mo"]

0 comments on commit e51715e

Please sign in to comment.