Is it possible to have a Procfile file and a manage.py file on a different folder level?

Introduction:

  • I follow the quick guide Getting started with Django on Heroku .

  • I intend to apply two schemes of the philosophy of Django's book on working with virtualenvs and projects. Audrey Roy and Daniel Greenfeld (authors) would like to put all environments in one directory and all projects in another.

  • I also intend to apply two schemes of Django's philosophy of placing what is generated by the django-admin.py startproject management team inside another directory, which serves as the root of the git repository (aka three-level approach ).

Layout at the highest level:

 repository_root/ django_project_root/ configuration_root/ 


Locally:

OS X 10.8.4
pip == 1.4.1
virtualenv == 1.10.1
virtualenvwrapper == 4.1.1
wsgiref == 0.1.2
.bashrc contains:

 export WORKON_HOME=$HOME/Envs export PROJECT_HOME=$HOME/Projects 

~ / Envs
~ / Projects


Inside hellodjango_venv:

Django == 1.5.2
DJ Database URL == 0.2.2
DJ-static == 0.0.5
Django-Toolbelt == 0.0.1
gunicorn == 18.0
psycopg2 == 2.5.1
static == 0.4


From terminal:

 mac-pol:~ oubiga$ mkdir -p Projects/hellodjango_rep/hellodjango mac-pol:~ oubiga$ cd Projects/hellodjango_rep/hellodjango mac-pol:hellodjango oubiga$ mkvirtualenv hellodjango_venv New python executable in hellodjango_venv/bin/python2.7 Also creating executable in hellodjango_venv/bin/python Installing Setuptools.................................. ... ..................................................done. (hellodjango_venv)mac-pol:hellodjango oubiga$ pip install django-toolbelt ... Successfully installed django-toolbelt django psycopg2 gunicorn dj-database-url dj-static static Cleaning up... (hellodjango_venv)mac-pol:hellodjango oubiga$ django-admin.py startproject hellodjango . (hellodjango_venv)mac-pol:hellodjango oubiga$ touch Procfile && open Procfile 

Edit Procfile:

web: gunicorn hellodjango.wsgi

Run the process:

 (hellodjango_venv)mac-pol:hellodjango oubiga$ foreman start 01:30:37 web.1 | started with pid 638 01:30:37 web.1 | 2013-09-04 01:30:37 [638] [INFO] Starting gunicorn 18.0 01:30:37 web.1 | 2013-09-04 01:30:37 [638] [INFO] Listening at: http://0.0.0.0:5000 (638) 01:30:37 web.1 | 2013-09-04 01:30:37 [638] [INFO] Using worker: sync 01:30:37 web.1 | 2013-09-04 01:30:37 [641] [INFO] Booting worker with pid: 641 CTRL+C 

So far so good.

Currently, my project tree:

 ~/Projects/ hellodjango_rep/ hellodjango/ cwd manage.py Procfile hellodjango/ __init__.py settings/ urls.py wsgi.py 

and my Virtualenvs tree:

 ~/Envs/ get_env_details initialize postactivate postdeactivate postmkproject postmkvirtualenv postrmproject postrmvirtualenv preactivate predeactivate premkproject premkvirtualenv prermproject prermvirtualenv hellodjango_venv/ bin/ include/ lib/ 

But do you remember the three-level approach ? How can i achieve this?

I'm sure hellodjango_rep / later will contain at least: .git, .gitignore and requirements.txt


Study:

On IRC # django, Jacob Kaplan-Moss replied:

... Procfile should be at the top level of your git repository

Neil Middleton, an engineer from Heroku, answered this question: "Procfile declares types → (none) in Heroku" in SO:

... your Procfile should be at the root of your git repository, which is pushed to Herok ...

From the Geroku Deva Center:

... Process types are declared through a file called Procfile, placed at the root of your application ...


As a first attempt:

I move Procfile one level folder.

 (hellodjango_venv)mac-pol:hellodjango oubiga$ cd .. 

Currently, my project tree:

 ~/Projects/ hellodjango_rep/ cwd Procfile hellodjango/ manage.py hellodjango/ __init__.py settings/ urls.py wsgi.py 

I start the process again:

 (hellodjango_venv)mac-pol:hellodjango_rep oubiga$ foreman start 

I will get ImportError: there is no module named hellodjango.wsgi


Debugging:

ImportError seems to come from /Users/oubiga/Envs/hellodjango_venv/lib/python2.7/site-packages/gunicorn/util.py

 def import_app(module): parts = module.split(":", 1) if len(parts) == 1: module, obj = module, "application" else: module, obj = parts[0], parts[1] try: __import__(module) # <-- line 354 except ImportError: if module.endswith(".py") and os.path.exists(module): raise ImportError("Failed to find application, did " "you mean '%s:%s'?" % (module.rsplit(".", 1)[0], obj)) else: raise ... 

There is no module named hellodjango.wsgi


Like a second attempt:

Procfile returns to the previous level. Procfile and manage.py merge again.

 (hellodjango_venv)mac-pol:hellodjango_rep oubiga$ foreman start 

I will get ERROR: Procfile does not exist. It is obvious why this is happening.


Hypothesis:

From the Django documentation:

... manage.py is automatically created in every Django project. manage.py is a thin shell around django-admin.py that takes care of two things for you before delegating django-admin.py:
- He puts your projects on sys.path.
- It sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your settings.py settings file ...

I am not sure if the problem is related to this.


So:

Is it possible to have a Procfile file and a manage.py file on a different folder level?
What is wrong with this approach?


Thank you in advance.

+6
source share
2 answers

Firstly, I must say that I did not conduct such a wide study and used Heroku three times. But:

(Your secret call):

Procfile really should be in the top level directory. If you move the Procfile, then a deeper gunner will not be able to find it.

(Your first attempt):

And having your Procfile in the top level directory, you must specify the path to wsgi. This is not yet possible. Thus, you shoud create the __init__.py file in the first directory “hellodjango” to mark it as “module”. Then you shoud change the path in Procfile to: hellodjango.hellodjango.wsgi

Hope this helps.

+4
source

I came across this using the “Two Matches” layout, and my solution was to save the standard layout ( Procfile in repository_root , manage.py in project_root ) and make Procfile a script that changes the directory to project_root before launching the weapon.

for example in Procfile :

 web: sh -c 'cd ./mysite/ && exec gunicorn mysite.wsgi --log-file -' 

You could have a Procfile call to an external script:

 web: bash scripts/heroku_run 

I prefer this to add additional paths to the module, as this can ruin the import in settings.py and urls.py , etc.

+2
source

Source: https://habr.com/ru/post/953181/


All Articles