Allow django to discover management commands from namespace packages.
|Reported by:||eire1130||Owned by:||nobody|
|Component:||Core (Management commands)||Version:||master|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Certain third party package maintainers may desire to have their apps in a namespace package. If those packages contain management commands, Django might not be able to discover them.
For example, if you have a namespace package that looks something like this:
Django will not be able to discover the packages during management registration (and in fact, could raise errors depending on the management command). If Django fails to locate a package during this process, it fails silently, which could be confusing for some developers.
Package discovery fails for one primary reason:
- 1. Namespace and namespace/space directories above do not necessarily need init.py files located in their directory.
So for demonstration, import namespace.space.package1 works while import namspace and import namespace.space will not work.
The workaround here is just to allow for a direct import (if it succeeds) and take the path from that module for django to register the management command.
This solution should work in most situations where the namespace package is installed "normally" and can be found in the python path.
If approved, I will send the pull request.
Change History (4)
comment:1 Changed 3 years ago by aaugustin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:3 Changed 3 years ago by kmtracey
- Resolution set to duplicate
- Status changed from new to closed