chore: move from setuptools to hatch_build

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.
This commit is contained in:
Éloi Rivard 2023-10-08 11:29:32 +02:00
parent 9f7ecf6614
commit 8c865b1037
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
45 changed files with 53 additions and 15 deletions

View file

@ -14,9 +14,7 @@ CONTRIBUTORS
docker-compose.* docker-compose.*
Dockerfile Dockerfile
docs docs
LICENSE
Makefile Makefile
MANIFEST.in MANIFEST.in
README.md
SECURITY.md SECURITY.md
tox.ini tox.ini

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
*.pyc *.pyc
*.egg-info *.egg-info
*.mo
dist dist
.venv .venv
docs/_build/ docs/_build/

View file

@ -1,3 +0,0 @@
include *.md
recursive-include ihatemoney *.py *.yaml *.po *.mo *.html *.css *.js *.eot *.svg *.woff *.txt *.png *.webp *.ini *.cfg *.j2 *.jpg *.gif *.ico *.xml
include LICENSE CONTRIBUTORS

View file

@ -36,7 +36,7 @@ remove-install-stamp:
update: remove-install-stamp install ## Update the dependencies update: remove-install-stamp install ## Update the dependencies
.PHONY: serve .PHONY: serve
serve: install ## Run the ihatemoney server serve: install build-translations ## Run the ihatemoney server
@echo 'Running ihatemoney on http://localhost:5000' @echo 'Running ihatemoney on http://localhost:5000'
FLASK_DEBUG=1 FLASK_APP=ihatemoney.wsgi $(VENV)/bin/flask run --host=0.0.0.0 FLASK_DEBUG=1 FLASK_APP=ihatemoney.wsgi $(VENV)/bin/flask run --host=0.0.0.0
@ -74,8 +74,8 @@ compress-assets: compress-showcase ## Compress static assets
build-translations: ## Build the translations build-translations: ## Build the translations
$(VENV)/bin/pybabel compile -d ihatemoney/translations $(VENV)/bin/pybabel compile -d ihatemoney/translations
.PHONY: update-translations .PHONY: extract-translations
update-translations: ## Extract new translations from source code 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 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/ $(VENV)/bin/pybabel update -i ihatemoney/messages.pot -d ihatemoney/translations/

View file

@ -274,10 +274,9 @@ In order to issue a new release, follow the following steps:
make compress-assets make compress-assets
- Build the translations: - Extract the translations:
make update-translations make extract-translations
make build-translations
- If you're not completely sure of yourself at this point, you can - 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 optionally: create a new branch, push it, open a pull request, check

11
hatch_build.py Normal file
View file

@ -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
ihatemoney/babel_utils.py Normal file
View file

@ -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()

View file

@ -3,10 +3,16 @@ from unittest.mock import MagicMock
from flask import Flask from flask import Flask
import pytest import pytest
from ihatemoney.babel_utils import compile_catalogs
from ihatemoney.currency_convertor import CurrencyConverter from ihatemoney.currency_convertor import CurrencyConverter
from ihatemoney.run import create_app, db from ihatemoney.run import create_app, db
@pytest.fixture(autouse=True, scope="session")
def babel_catalogs():
compile_catalogs()
@pytest.fixture @pytest.fixture
def app(request: pytest.FixtureRequest): def app(request: pytest.FixtureRequest):
"""Create the Flask app with database""" """Create the Flask app with database"""

View file

@ -1,6 +1,6 @@
[build-system] [build-system]
requires = ["setuptools", "setuptools-scm"] requires = ["hatchling"]
build-backend = "setuptools.build_meta" build-backend = "hatchling.build"
[project] [project]
name = "ihatemoney" name = "ihatemoney"
@ -85,5 +85,19 @@ doc = [
[project.scripts] [project.scripts]
ihatemoney = "ihatemoney.manage:cli" ihatemoney = "ihatemoney.manage:cli"
[tool.setuptools] [tool.hatch.build.hooks.custom]
packages = ["ihatemoney"] dependencies = [
# Babel is needed to compile translations catalogs at package build time
"Babel>=2.10.1"
]
[tool.hatch.build]
artifacts = ["ihatemoney/translations/**/*.mo"]
include = [
"ihatemoney/",
"LICENSE",
"CONTRIBUTORS",
"CHANGELOG.md",
"README.md",
"SECURITY.md",
]

View file

@ -1,4 +1,5 @@
[tox] [tox]
isolated_build = true
envlist = py312,py311,py310,py39,py38,py37,lint_docs envlist = py312,py311,py310,py39,py38,py37,lint_docs
skip_missing_interpreters = True skip_missing_interpreters = True