Search code examples
pythongitvirtualenvpyramidorganization

Organising project files for a Python webapp with database functionality


I'd like some advice on how to organise the files for a database-driven web application.

The main components of the project are:

  • An SQLite database
  • A web application written with the Pyramid framework, which reads from the database
  • A set of Python applications which download data and add it to the database
  • Documentation

I'd like to track all source files of all the components (including the documentation) using git.

Does the following seem like a good structure for the project?

Main_Project_Directory
+-- virtualenv
|   +-- bin, lib, include, man
|   +-- PyramidApplication
|   |   +-- setup.py
|   |   +-- development.ini
|   |   +-- Application
|   |   |   +-- __init__.py
|   |   |   +-- ...
|   |   +-- ...
|   +-- DatabaseWritingApp1
|   |   +-- __init__.py
|   |   +-- ...
|   +-- DatabaseWritingApp2
|   |   +-- __init__.py
|   |   +-- ...
|   +-- database.sqlite
+-- documentation

How should I initialise git repositories here? Would it be good to have one git repository in the top directory to track the pyramid app, other apps, and the documentation? Or would multiple git repositories be preferable? I am the sole developer on this project.

Also, is there some file in the virtualenv which lists all the installed packages and their versions, so that the bin, lib, etc. directories can be rebuilt from it? If so, would it be good to include that file in a git repository so that the virtualenv can easily be rebuilt after a pull?

Thanks for any assistance.


Solution

  • you don't need all your projects in the virtualenv directory. I like to put all my files in ~/Workspace to keep it clean. Just make sure you run . virtualenv_directory/bin/activate before you run your pyramids application.

    I don't know if you're trying to be modular with your code or not. In other words, do you plan on using DatabaseWritingApp* outside of PyramidApplication? If so, I would do what you're doing and split them up into different folders and have a GitHub repository for each, regardless of how many developers you have. On the other hand, if you don't plan on using DatabaseWritingApp* separately, I would just lump everything in PyramidApplication and use one GitHub repository.

    For bins and lib for virtualenv, what I do is make sure all the libraries I need are in the setup.py file, and just run python setup.py develop before running the Pyramid application. This will make sure your virtualenv has all the necessary libraries, assuming they're all from easy_install or pip.