Repository: spiral-project/ihatemoney (language: python)

Issue:
Cannot install in dev mode with python 3.12
Example here in CI: https://github.com/spiral-project/ihatemoney/actions/runs/8425553353/job/23071914274

Copy of the error in case the job disappears:

```
tox -e lint
lint: install_deps> python -I -m pip install -e '.[dev]'
  error: subprocess-exited-with-error
  
  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [38 lines of output]
      Traceback (most recent call last):
        File "/home/runner/work/ihatemoney/ihatemoney/.tox/lint/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 167, in prepare_metadata_for_build_editable
          hook = backend.prepare_metadata_for_build_editable
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      AttributeError: module 'hatchling.build' has no attribute 'prepare_metadata_for_build_editable'
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/tmp/pip-build-env-4_xmhj5h/normal/lib/python3.12/site-packages/babel/messages/setuptools_frontend.py", line 7, in <module>
          from setuptools import Command
      ModuleNotFoundError: No module named 'setuptools'
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/home/runner/work/ihatemoney/ihatemoney/.tox/lint/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/runner/work/ihatemoney/ihatemoney/.tox/lint/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/runner/work/ihatemoney/ihatemoney/.tox/lint/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 176, in prepare_metadata_for_build_editable
          whl_basename = build_hook(metadata_directory, config_settings)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-4_xmhj5h/overlay/lib/python3.12/site-packages/hatchling/build.py", line 83, in build_editable
          return os.path.basename(next(builder.build(directory=wheel_directory, versions=['editable'])))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-4_xmhj5h/overlay/lib/python3.12/site-packages/hatchling/builders/plugin/interface.py", line 147, in build
          build_hook.initialize(version, build_data)
        File "/home/runner/work/ihatemoney/ihatemoney/hatch_build.py", line 9, in initialize
          from babel_utils import compile_catalogs
        File "/home/runner/work/ihatemoney/ihatemoney/ihatemoney/babel_utils.py", line 3, in <module>
          from babel.messages.frontend import compile_catalog
        File "/tmp/pip-build-env-4_xmhj5h/normal/lib/python3.12/site-packages/babel/messages/frontend.py", line 1121, in __getattr__
          from babel.messages import setuptools_frontend
        File "/tmp/pip-build-env-4_xmhj5h/normal/lib/python3.12/site-packages/babel/messages/setuptools_frontend.py", line 15, in <module>
          from distutils.cmd import Command
      ModuleNotFoundError: No module named 'distutils'
```


Discussion / hints:
@azmeuk  It looks like an issue with hatchling and/or babel, could you have a look?

In the meantime I am disabling the failing python 3.12 job in our CI.
Ah yes, we met [this in wtforms too](https://github.com/wtforms/wtforms/pull/824) because Babel 2.14 does not rely on setuptools anymore. The solution was to add a special setuptools dependency for python 3.12.

[Related Babel changelog entry](https://github.com/python-babel/babel/blob/40e60a1f6cf178d9f57fcc14f157ea1b2ab77361/CHANGES.rst?plain=1#L22-L24)

> Babel no longer directly depends on either distutils or setuptools; if you had been
using the Babel setuptools command extensions, you would need to explicitly depend on setuptools –
though given you're running setup.py you probably already do.

@zorun do you want me to open a PR?
Nice, thanks. Yes, a PR would be appreciated. You can re-enable the disabled CI test in the same PR (look at "exclude:")

Out of curiosity, why does it work with older Python versions? Maybe they were bundling setuptools?
Yes, the [Python 3.12 changelog](https://docs.python.org/3/whatsnew/3.12.html) mentions it:

> [PEP 632](https://peps.python.org/pep-0632/): Remove the distutils package. See [the migration guide](https://peps.python.org/pep-0632/#migration-advice) for advice replacing the APIs it provided. The third-party [Setuptools](https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html) package continues to provide distutils, if you still require it in Python 3.12 and beyond.

Fix patch:
diff --git a/pyproject.toml b/pyproject.toml
index bf2de70b1..cc6199a0d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -88,7 +88,13 @@ ihatemoney = "ihatemoney.manage:cli"
 [tool.hatch.build.hooks.custom]
 dependencies = [
     # Babel is needed to compile translations catalogs at package build time
-    "Babel>=2.13.1"
+    "Babel>=2.13.1",
+
+    # Babel 2.14 does not directly depend on setuptools
+    # https://github.com/python-babel/babel/blob/40e60a1f6cf178d9f57fcc14f157ea1b2ab77361/CHANGES.rst?plain=1#L22-L24
+    # and neither python 3.12 due to PEP 632
+    # https://peps.python.org/pep-0632/
+    "setuptools; python_version>='3.12'",
 ]
 
 [tool.hatch.build]


Test patch:
diff --git a/.github/workflows/lint-and-tests.yml b/.github/workflows/lint-and-tests.yml
index 23f71fdc5..4e30ff86f 100644
--- a/.github/workflows/lint-and-tests.yml
+++ b/.github/workflows/lint-and-tests.yml
@@ -56,11 +56,6 @@ jobs:
         python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
         dependencies: [normal]
         database: [sqlite]
-        # Installation breaks with python 3.12, see https://github.com/spiral-project/ihatemoney/issues/1297
-        exclude:
-          - python-version: "3.12"
-            dependencies: normal
-            database: sqlite
         # Test other databases with only a few versions of Python (Debian bullseye has 3.9, bookworm has 3.11)
         include:
           - python-version: 3.9