move from setuptools to hatch (#1258)

Co-authored-by: Alexis Métaireau <alexis@notmyidea.org>
This commit is contained in:
Éloi Rivard 2023-12-12 14:20:34 +01:00 committed by GitHub
parent 9f7ecf6614
commit edefb51cfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 53 additions and 15 deletions

View file

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

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
*.pyc
*.egg-info
*.mo
dist
.venv
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
.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
@ -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/

View file

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

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
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"""

View file

@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "ihatemoney"
@ -85,5 +85,19 @@ doc = [
[project.scripts]
ihatemoney = "ihatemoney.manage:cli"
[tool.setuptools]
packages = ["ihatemoney"]
[tool.hatch.build.hooks.custom]
dependencies = [
# Babel is needed to compile translations catalogs at package build time
"Babel>=2.13.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]
isolated_build = true
envlist = py312,py311,py310,py39,py38,py37,lint_docs
skip_missing_interpreters = True