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 18, 2023
1 parent d1382a6 commit 5cea431
Show file tree
Hide file tree
Showing 43 changed files with 49 additions and 13 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
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
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.
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 @@ -84,5 +84,18 @@ doc = [
[project.scripts]
ihatemoney = "ihatemoney.manage:cli"

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

[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 = py311,py310,py39,py38,py37,lint_docs
skip_missing_interpreters = True

Expand Down

0 comments on commit 5cea431

Please sign in to comment.