Multiple custom modules with hatchling and tryton_dev

Hi,

I’d like to share my experience developing multiple custom modules with the latest Tryton development version (8.3) and the new hatchling packaging.

I always develop my custom modules on Tryton dev and then graft the necessary changes onto the lower branches.

Until now (with setuptools), I created symlinks of my custom modules in trytond/modules (the same approach as for the standard Tryton modules), so I could import a custom module this way:
from trytond.modules.custom_module import ...

To use my modules in a lower branch, I simply ran:
pip install -e custom_module --use-pep517
which installed all the dependencies.

But now, with the new hatchling system, I’m running into problems when using several custom modules that depend on one another: the import paths of custom modules are no longer valid in some branches (8.2).

Here’s my solution:

  • First, use the latest cookiecutter template to create your custom module with hatchling (and the symlink if your module name is prefixed):
    cookiecutter --output-dir tryton_custo cookiecutter-module
  • If you develop on Tryton dev, install your custom module in editable mode with the --no-deps option:
    pip install -e custom_module --use-pep517 --no-deps
  • If you need to import a custom module inside another custom module, use:
    from prefix_custom_module.module_file import model

Hope this helps. Feel free to share your own approach! :slight_smile:

This is because hatchling does not support “dev mode” with a path rewrite that is not replaced in the package directory.
This is why the cookiecutter template adds a “loolback” symlink for module with prefix to provide the same path rewrite.
We did not make such symlink in the standard module because usually core developers use the .hooks/link_modules script. And also because the symlink would need to be trytond/modules/<module name>.

1 Like