Management module imports project_module, considered evil
|Reported by:||patrys||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||no|
I think Django's core.management.setup_environ should stop trying to import the project dir as if it was a module.
Currently lines 337-341 read:
# Import the project module. We add the parent directory to PYTHONPATH to # avoid some of the path errors new users can have. sys.path.append(os.path.join(project_directory, os.pardir)) project_module = import_module(project_name) sys.path.pop()
There is no explanation as to why it's useful to treat the project as a module. Also it assumes that:
- there is no and will never be a python module using the same name in any of the current sys.path directories;
- the directory name is a valid python module
I see no value in treating a mere container dir as a module. If there is one, it could be clarified in the comment, currently it just states what the code does while not really explaining why.
I actually have projects where the dir only contains settings.py and an empty __init__.py just to keep Django from crashing. If you don't import apps using your project name as a prefix, the __init__.py file is useless and you should be free to use any directory name you want. If you do use the project prefix, Python will already happily parse the top-level __init__.py for you and I see no point in importing it earlier in core.management.
Change History (12)
comment:1 Changed 5 years ago by chad@…
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Version changed from 1.0 to SVN