Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comments on this assumption about running on dev server vs a real instance in app engine (python)?

I'm on an app engine project where I'd like to put in a link to a Javascript test runner that I'd like to only exist when running the development server. I've made some experiments on a local shell with configuration loaded using the technique found in NoseGAE versus live on the 'App Engine Console' [1] and it looks to me like a distinction btw real instance and dev server is the presence of the module google.appengine.tools. Which lead me to this utility function:

def is_dev():
    """
    Tells us if we're running under the development server or not.
    :return:
    ``True`` if the code is running under the development server.
    """
    try:
        from google.appengine import tools
        return True
    except ImportError:
        return False

The question (finally!) would be: is this a bad idea? And in that case, can anyone suggest a better approach?

[1] http://con.appspot.com/console/ (try it! very handy indeed)

like image 267
Jacob Oscarson Avatar asked Aug 24 '26 23:08

Jacob Oscarson


2 Answers

The standard way to test for the development server is as follows:

DEBUG = os.environ['SERVER_SOFTWARE'].startswith("Dev")

Relying on the existence or nonexistence of a particular module - especially an undocumented one - is probably a bad idea.

like image 185
Nick Johnson Avatar answered Aug 26 '26 12:08

Nick Johnson


I'd recommend doing it this way:

import os
def onDevServer():
    return os.environ['SERVER_SOFTWARE'].find('Development') >= 0

This looks at the environment you're running in, and returns true if you're running on the development server. However, its a much cleaner way than checking an import, in my opinion.

like image 40
Joseph Salisbury Avatar answered Aug 26 '26 13:08

Joseph Salisbury