Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#11147 closed (invalid)

manage.py doesn't work with settings directory in pydev

Reported by: Leo Shklovskii Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The fix for #9751 - r10751 - completely broken manage.py for our configuration (things are set up this way for pydev):

/src/
 |-- app1
 |   |-- __init__.py
 |   |-- models.py
 |-- app2
 |   |-- __init__.py
 |   |-- models.py
 |-- manage.py
 |-- settings
 |   |-- __init__.py
 |   |-- settings_dev.py
 |   |-- settings_prod.py
 `-- urls.py

I now get the following failure - it looks like django is trying to go up a directory too high:

Traceback (most recent call last):
  File "C:\ws\fuzzy\EvoHeart2\src\manage.py", line 12, in <module>
    execute_manager(settings)
  File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line 360, in execute_manager
    setup_environ(settings_mod)
  File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line 343, in setup_environ
    project_module = import_module(project_name)
  File "C:\Python25\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named src

PyDev doesn't put an __init__.py in the root src directory and it seems like there shouldn't be one there (it's a directory on the PYTHONPATH).

Change History (8)

comment:1 by Leo Shklovskii, 16 years ago

To clarify, this happens when I try to do manage.py runserver

comment:2 by dc, 16 years ago

Resolution: invalid
Status: newclosed

Django project is a normal python module and you must have init.py in it.

Please don't use trac for asking for the support questions, use either #django on freenode or django-users mailing list.

comment:3 by Leo Shklovskii, 16 years ago

Resolution: invalid
Status: closedreopened

This isn't a support question. Running without a project module is perfectly normal and even advocated by James Bennett - http://www.b-list.org/weblog/2007/nov/09/projects/

The change mentioned in the ticket breaks the ability to do this, hence its a regression, hence this ticket.

comment:4 by Ramiro Morales, 16 years ago

Replying to Leo:

This isn't a support question. Running without a project module is perfectly normal and even advocated by James Bennett - http://www.b-list.org/weblog/2007/nov/09/projects/

Problem is that if you are using manage.py then you are using a project.

If you really don't want to use a project do what that article (and other similar blog posts) suggest: Set up things manually so all you apps, your settings and your main URL map (usually urls.py) are in you Python path and use you Django's django-admin (or similar home-made script) instead.

The change mentioned in the ticket breaks the ability to do this, hence its a regression, hence this ticket.

I'd say that if that worked before it was a another problem and the r10751 corrected it.

comment:5 by Jacob, 16 years ago

Resolution: invalid
Status: reopenedclosed

I'm fairly sure this is a PyDev bug because looking at the code there's no way it'll step up *two* directories (it just calls os.path.dirname).

comment:6 by Karen Tracey, 16 years ago

Leo, I don't understand why you can't just put an __init__.py in the src directory? Fine, so Pydev doesn't do it automagically but it's easy enough to add one. Then everything works. I also don't see that this structure is mandated by Pydev -- you do not have to use the Eclipse/Pydev default src directory structure, it's just the default. You can easily override and use your own source tree structure. But given that you want to use that structure, what's the problem with putting an __init__.py file in the root?

__init__.py wasn't needed in the root when you used a settings directory prior to r10751 because the code was incorrectly figuring the 'project' dir WAS the settings dir. And things like startapp would create subdirectories in the settings dir, instead of the root project dir. Now the project dir is being figured out correctly, it needs an __init__.py file.

comment:7 by Leo Shklovskii, 16 years ago

Thanks for all of the feedback. The workaround suggested by kmtracey is fine for now. From an more theoretical standpoint, its just a bandaid, since 'src' is already on the pythonpath and is not an importable package (/lib/site-packages wouldn't have an __init__.py either) but that's just a handwavy argument.

jacob: It doesn't actually go up two directories. It assumes 'src' is the project name and attempts to import it (which doesn't work in the existing case since its a root pythonpath and not a package).

What ramiro says makes a lot of sense here, since I'm not using a project I shouldn't expect manage.py to work - although it would be nice if it did :-)

The one small qualm I have here is that if we assume a project layout, manage.py will always be in the project directory and that directory is available on the pythonpath since its the cwd when manage.py is run. There's probably use cases that I'm totally not aware of but from the ones I understand there's no need to explicitly import the project package.

Regardless, I'm fine with either abandoning manage.py going forward (since we're not using projects) or putting the __init__.py files in for now.

Thanks again for the comments.

comment:8 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top