Trytond modules typically use a “flat” repo, where the Python-modules of the package reside in the repo root:
<repo>/__init__.py. The down-side of this approach is that all other .py files in the repo are considered part of the package, too, will be put into the bdist and will be installed. E.g. the test package. Another example: I keep a
_zest_release_hooks.py in the repo to support my release-process, which should not be installed.
A common approach to circumvent packaging unwanted files would be to move the trytond module package into a
src directory and make setuptools pick it up from there, like PyPA describes.
Anyhow, this work-around does not work for trytond modules in develop-mode (
pip install -e . or
python setup.py develop):
- trytond modules are namespace modules (trytond.modules.mymodule), which - when using the “flat” repo layout - are not imported properly anyway. This is why
trytond.modulesimplements a work-around:
trytond.modules.import_module(), if normal import fails, falls back on searching the module on sys.path and in the module entry-point’s location (
Extend the already existing work-around in
trytond.modules.import_module() to use
<repo>/<package-name> if it exists.
This would allow to have a “src directory”-like repo layout:
<repo>/mymodule/__init__.py. This restricts the directory name to be the last part of the fully-qualified trytond module name (trytond.modules.mymodule), OTOH, this would allow to have several modules in the same repo.
Patch see below, adding three lines of code.
--- trytond/modules/__init__.py.orig +++ trytond/modules/__init__.py @@ -66,9 +66,14 @@ if os.path.isdir(os.path.join(path, name)): break else: - # When testing modules from setuptools location is the - # module directory - path = os.path.dirname(ep.dist.location) + # Check for a "src"-like repository (<repo>/<package>) + # installed in "develop" mode + path = os.path.join( + ep.dist.location, ep.module_name.split('.')[-1]) + if not os.path.isdir(path): + # When testing modules from setuptools location is the + # module directory + path = os.path.dirname(ep.dist.location) spec = FileFinder( path, (SourceFileLoader, SOURCE_SUFFIXES) ).find_spec(fullname)