Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Restructuring ideas #28

Open
kaedroho opened this issue Feb 24, 2015 · 3 comments
Open

Restructuring ideas #28

kaedroho opened this issue Feb 24, 2015 · 3 comments

Comments

@kaedroho
Copy link
Contributor

In this template, we put all the projects code in a subdirectory. This is a nice way to separate code from configuration. Making the project easier to browse (especially for people who are unfamilar with the project).

Theres a couple of issues though...

  • PYTHONPATH needs to be set to a subdirectory of the project. Configuration managment systems and PaaS services need to know about this.
  • The settings are deeply nested in a quite redundant-looking path.

I propose that we make two changes:

Make python run in the root directory (instead of the subdirectory)

  • The subdirectory will still exist and contain all the apps for the project
  • This would make setting the PYTHONPATH variable easy as the configuration management system would not need to be aware of the internal structure of the project. It will also make projects work nicely (without any extra configuration) on heroku/dokku/etc
  • This is how python packages are structured
  • This would require imports between the apps in the project be prefixed with project_name.

Move settings/urls/wsgi one level up

  • We currently have a subfolder inside the code directory named after the project for settings, urls.py, wsgi.py, etc.
  • I think we should move all of these files into the main code directory (so settings is found at project_name/settings).

Example:

├── docs
│   └── ...
└── vagrant
│   └── ...
├── {{ project_name }}
│   ├── app1
│   │   └── ...
│   ├── app2
│   │   └── ...
│   ├── static
│   │   └── ...
│   ├── templates
│   │   └── ...
│   ├── settings
│   │   ├── base.py
│   │   ├── dev.py
│   │   └── production.py
│   ├── urls.py
│   └── wsgi.py
├── fabfile.py
├── requirements.txt
└── manage.py

The biggest change this would mean for developers is the import paths for their apps would all change. For example, if you wanted to import the model Foo from the app app1, you'd have to do from my_project.app1.models import Foo. I personally dont think this is a bad thing for the following reasons:

  • Importing between apps is uncommon
  • Namespacing apps like this can be good as apps often have generic names which may clash with installed packages
@balazs-endresz
Copy link
Member

Where would urls.py, wsgi.py and manage.py be in this layout?

@kaedroho
Copy link
Contributor Author

manage.py would be in the root alongsite fabfile.py, requirements.txt, etc

urls.py and wsgi.py would be in the project folder (/project_name/{urls,wsgi}.py)

@kaedroho
Copy link
Contributor Author

Just added an example to the above post to hopefully better illustrate the structure...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants