Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top