provide a development flag for applications

11 views
Skip to first unread message

rctay

unread,
Jan 28, 2009, 7:23:22 AM1/28/09
to web2py Web Framework
Hi,

what do you guys think of providing a global variable (at application-
level), say, WEB2PY_APP_IS_DEVELOPING?

it would be useful for applications yet to enter production, so that
one could enable various functionality/code that would be useful for
developing applications.

eg.
if (WEB2PY_APP_IS_DEVELOPING):
reload(module)

you could control this with a command-line option like --
developingapps app1,app2,...

rctay

unread,
Jan 28, 2009, 8:44:27 AM1/28/09
to web2py Web Framework
here's a simple patch that does this.

execute web2py with this option:

--developingapps APP[,APP...]

anywhere in your application, you can use the boolean variable
WEB2PY_APP_IS_DEVELOPING.

---cut below this line---

Index: compileapp.py
===================================================================
--- compileapp.py (revision 680)
+++ compileapp.py (working copy)
@@ -86,6 +86,7 @@
environment['SQLField']=SQLField
environment['SQLFORM']=SQLFORM
environment['SQLTABLE']=SQLTABLE
+ environment['WEB2PY_APP_IS_DEVELOPING']=request.application in
request.env.devingapps
response._view_environment=copy.copy(environment)
return environment

Index: widget.py
===================================================================
--- widget.py (revision 680)
+++ widget.py (working copy)
@@ -305,6 +305,9 @@
parser.add_option('-D', '--debug',
dest='debuglevel', default=30, type='int',
help='set debug output level (0-100, 0 means all,
100 means none, default is 30)')
+ parser.add_option('', '--developingapps',
+ dest='devingapps', metavar='APP
[,APP...]',type='string',
+ help='set the python variable
WEB2PY_APP_IS_DEVELOPING in environments of APP[,APP...]'),
parser.add_option('-S', '--shell',
dest='shell', metavar='APPNAME',
help='run web2py in interactive shell or IPython(if
installed) with specified appname')
@@ -356,6 +359,10 @@
print 'default applications are now installed'
else:
print 'default applications appear to be installed already'
+ if options.devingapps:
+ options.devingapps = options.devingapps.split(',')
+ else:
+ options.devingapps = []
return options, args

def start():
@@ -422,6 +429,9 @@
options.password=raw_input('choose a password:')
if not options.password:
print 'no password, no admin interface'
+ ### if --developmentapps
+ if len(options.devingapps):
+ print 'the following apps have been flagged as under
development:\n\t%s' % '\n\t'.join(options.devingapps)
### start server
ip,port=options.ip,int(options.port)
print 'please visit:'
@@ -437,6 +447,7 @@
request_queue_size=options.request_queue_size,
timeout=options.timeout,
shutdown_timeout=options.shutdown_timeout,
- path=options.folder)
+ path=options.folder,
+ devingapps=options.devingapps)
try: server.start()
except KeyboardInterrupt: server.stop()
Index: main.py
===================================================================
--- main.py (revision 680)
+++ main.py (working copy)
@@ -289,9 +289,10 @@
else: file.write('password=None\n')
file.close()

-def appfactory
(wsgiapp=wsgibase,logfilename='httpsever.log',web2py_path=web2py_path):
+def appfactory
(wsgiapp=wsgibase,logfilename='httpsever.log',web2py_path=web2py_path,devingapps=None):
def app_with_logging(environ, responder):
environ['web2py_path']=web2py_path
+ environ['devingapps']=devingapps
status_headers=[]
def responder2(s,h):
status_headers.append(s)
@@ -318,7 +319,8 @@
request_queue_size=5,
timeout=10,
shutdown_timeout=5,
- path=web2py_path):
+ path=web2py_path,
+ devingapps=None):
"""
starts the web server.
"""
@@ -328,7 +330,7 @@
logging.info('starting web server...')
from contrib.wsgihooks import ExecuteOnCompletion2, callback
self.server=wsgiserver.CherryPyWSGIServer((ip, port),
- appfactory(ExecuteOnCompletion2
(wsgibase,callback),log_filename,web2py_path=path),
+ appfactory(ExecuteOnCompletion2
(wsgibase,callback),log_filename,web2py_path=path,devingapps=devingapps),
numthreads=int(numthreads),
server_name=server_name,
request_queue_size=int(request_queue_size),
timeout=int(timeout),

achipa

unread,
Jan 29, 2009, 9:15:34 AM1/29/09
to web2py Web Framework
I usually just set a constant in a models/conf.py (along with DB and
other params which vary on the development and the deployment setup)
and check for that.

rctay

unread,
Jan 29, 2009, 9:25:41 AM1/29/09
to web2py Web Framework
Hmm, you don't sound like you're using any VCS/SCM.

anyway, by using that flag, you could minimize the possibility of
human error (ie. the possibility that you forgot to update that
variable on either setup while moving code between both).

you could also debug your deployment setup quickly by turning on that
flag.

achipa

unread,
Jan 29, 2009, 9:58:25 AM1/29/09
to web2py Web Framework
I'm using svn and bzr. The conf.py file is usually on an ignore list
and I provide a conf.example.py file (commented example entries) for
reference. That way I have no live config data in the versioning
system, and update/commit does not change the config file, so all is
well (this is actually not web2py related, I use a similar setup in my
other projects, too). If the config file needs to be changed on situ,
I can do that via the web2py interface which is preferred to me
(restarting apache being the other option if I need to change command
line parameters).

rctay

unread,
Jan 29, 2009, 10:10:51 AM1/29/09
to web2py Web Framework
Oh i see.

Well what I'm proposing is that such a workflow (ie with a development
flag) is shared with web2py users, not just among ourselves. :)

mdipierro

unread,
Jan 29, 2009, 10:22:34 AM1/29/09
to web2py Web Framework
This would be considered a web2py level configuration flag and that is
against to web2py phylosophy (no configuration).

You should be able to mimic it anyway.

you can set a environment variable (before starting web2py) and you
should be able to see it in request.env.your_environment_variable.

Massimo

Robin B

unread,
Jan 29, 2009, 11:33:12 AM1/29/09
to web2py Web Framework
Maybe web2py could endorse a 'standard' env variable, so people do not
have to set more than one:

WEB2PY_ENV_MODE = DEVELOPMENT | PRODUCTION | TEST | BENCHMARK

I think environment modes are important especially for performance.
If your app spends <1% of requests in development, and >99% in
production, it makes sense to set production mode so you can cache
aggressively, avoid reading the disk/reloading, and avoid doing
redundant operations on >99% of your requests.

Robin

mdipierro

unread,
Jan 29, 2009, 12:47:25 PM1/29/09
to web2py Web Framework
OK let's just use WEB2PY_MODE than and it will appear in

request.env.web2py_mode

Notice we aready have

request.env.web2py_path
request.env.web2py_version

Massimo
Reply all
Reply to author
Forward
0 new messages