0

I have written a django app to store some data in a database, display, filter and export the data. I have written a few additional python routines to extract the source data (from DICOM files) and insert it into the database.

I've placed these routines as a module in a folder within my app, and they start off by putting the project directory on sys.path and setting the value of DJANGO_SETTINGS_MODULE to point to the project settings.py file. They can be called from the shell or from within another python routine.

I then packaged up my app as per the Advanced tutorial on reusable apps, and installed it on a different server using pip. The app gets installed to the site-packages directory. I can then add the app to the INSTALLED_APPS list of a new project and I can view my app in a web browser etc.

I can't work out how to insert into my additional python scripts the name and location of the project.

I tried to get round it using pip install -t projectfolder app.tar.gz, manually setting the project name and assuming the project path is two folders above my script, which works.

However, I can't then upgrade the app when I have a new version, as pip just tries to write to the existing folder and fails as it expects it not to be there. It also doesn't list it as an installed app.

Additionally, if my scripts are hidden away in python site-packages, whilst I can import the module easily, I can't easily call it from the command line (or in a shell script).

I have searched and searched for an answer. Most tutorials, answers and blog posts seem to favour checking out a version of the project (including the app) from vcs, but my users aren't necessarily going to be known to me, and I'd rather package the app for them to download and use.

One thing that does seem like it might hold part of the answer is Fabric, possibly by using it to create the django project in the first place and therefore knowing what it is called and where it is installed. However, I think this might restrict me to *nix OSs and I'd like my users to be able to install on Windows.

Any help, suggestions, pointers to where the information is already out there gratefully received.

  • does your project also have a setup.py? – ashwoods Jul 21 '13 at 18:01
  • @ashwoods I created a setup.py modeled on the example in [the tutorial point 5](https://docs.djangoproject.com/en/1.5/intro/reusable-apps/#packaging-your-app) - is this what you are referring to? – Ed McDonagh Jul 21 '13 at 20:33
  • No. not the apps, the project itself? – ashwoods Jul 22 '13 at 09:34
  • @ashwoods Then the answer is no. I had thought I would only package the app, and the end user would create their own project before adding my app to the `INSTALLED_APPS` list in settings.py. Should I be looking along the lines of packaging the whole project? – Ed McDonagh Jul 22 '13 at 11:09
  • why do you need to know the project location? – ashwoods Jul 22 '13 at 15:33
  • To be able to put it on the path and load the db settings etc from my importer module. – Ed McDonagh Jul 22 '13 at 16:08
  • if you are just publishing a resusable app, you should let the users manage the packaging, python path, etc... of the project. If you are distributing a functional project, then make your project a python module and have them install that. – ashwoods Jul 22 '13 at 16:13
  • @ashwoods can you please add an answer to this question based on your last comment? It was the information I needed to move forward with my project, so I'd like to be able to mark it as such! – Ed McDonagh Jul 29 '13 at 22:19

1 Answers1

-1

Quoting @ashwoods:

If you are just publishing a resusable app, you should let the users manage the packaging, python path, etc... of the project. If you are distributing a functional project, then make your project a python module and have them install that.