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 Dec 2, 2023
1 parent 8bce025 commit 3f89b4e
Show file tree
Hide file tree
Showing 45 changed files with 52 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ CONTRIBUTORS
docker-compose.*
Dockerfile
docs
LICENSE
Makefile
MANIFEST.in
README.md
SECURITY.md
tox.ini
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
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

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
11 changes: 11 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys

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


class CustomBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
sys.path.insert(0, "./ihatemoney")
from babel_utils import compile_catalogs

compile_catalogs()
11 changes: 11 additions & 0 deletions ihatemoney/babel_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pathlib import Path

from babel.messages.frontend import compile_catalog


def compile_catalogs():
cmd = compile_catalog()
cmd.directory = Path(__file__).parent / "translations"
cmd.statistics = True
cmd.finalize_options()
cmd.run()
6 changes: 6 additions & 0 deletions ihatemoney/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
from flask import Flask
import pytest

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


@pytest.fixture(autouse=True, scope="session")
def babel_catalogs():
compile_catalogs()


@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.
21 changes: 17 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 @@ -85,5 +85,18 @@ doc = [
[project.scripts]
ihatemoney = "ihatemoney.manage:cli"

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

[tool.hatch.build]
artifacts = ["ihatemoney/translations/**/*.mo"]
include = [
"ihatemoney/",
"LICENSE",
"CONTRIBUTORS",
"CHANGELOG.md",
"README.md",
"SECURITY.md",
]
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[tox]
isolated_build = true
envlist = py312,py311,py310,py39,py38,py37,lint_docs
skip_missing_interpreters = True

Expand Down

0 comments on commit 3f89b4e

Please sign in to comment.