#20344 closed Bug (duplicate)
Allow django to discover management commands from namespace packages.
Reported by: | James Reynolds | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | bhuztez@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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:
site-packages/namespace/space/package1 site-packages/namespace/space/package2
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.
Branch is here: https://github.com/eire1130/django/tree/namespace_management_imports
Commit is here: https://github.com/eire1130/django/commit/3d495addc567e617eaef2b107fea6edaad161288
If approved, I will send the pull request.
Change History (4)
comment:1 by , 12 years ago
follow-up: 4 comment:2 by , 12 years ago
It does appear to be a dup, though I prefer my fix.
For what it's worth, I agree with you on namespace packages, but some of us need to use namespace packages for reasons that are out of control.
comment:3 by , 11 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:4 by , 11 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
Replying to eire1130:
It does appear to be a dup, though I prefer my fix.
For what it's worth, I agree with you on namespace packages, but some of us need to use namespace packages for reasons that are out of control.
the docstring says
Determines the path to the management module for the given app_name,
without actually importing the application or the management module.
obviously, your patch would import application module
Isn't this a duplicate of #14087?
(IMO using namespace packages is just asking for trouble; I forbid their use; I'm at best -0 on this change.)