tools for development and debugging in python

32
DISQUS Tools and Stu David Cramer twitter.com/ zeeg Friday, July 15, 2011

Upload: zeeg

Post on 27-Jan-2015

130 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Tools for Development and Debugging in Python

DISQUSTools and Stu!

David Cramertwitter.com/zeeg

Friday, July 15, 2011

Page 2: Tools for Development and Debugging in Python

django-debug-toolbar

Friday, July 15, 2011

Page 3: Tools for Development and Debugging in Python

$ pip install django-debug-toolbar

# settings.pyINSTALLED_APPS = ( 'debug_toolbar',)

MIDDLEWARE_CLASSES = ( 'debug_toolbar.middleware.DebugToolbarMiddleware',)

INTERNAL_IPS = ('127.0.0.1',)

Friday, July 15, 2011

Page 4: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 5: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 6: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 7: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 8: Tools for Development and Debugging in Python

Extending the Toolbar

class SettingsVarsDebugPanel(DebugPanel): """ A panel to display all variables in django.conf.settings """ name = 'SettingsVars' has_content = True

def nav_title(self): return _('Settings')

def title(self): return _('Settings')

def content(self): context = self.context.copy() context.update({ 'settings': get_safe_settings(), }) return as_string('debug_toolbar/panels/settings.html', context)

Friday, July 15, 2011

Page 9: Tools for Development and Debugging in Python

Extending the Toolbar

DEBUG_TOOLBAR_PANELS = ( 'debug_toolbar.panels.version.VersionDebugPanel', 'debug_toolbar.panels.timer.TimerDebugPanel', 'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel', 'debug_toolbar.panels.headers.HeaderDebugPanel', 'debug_toolbar.panels.request_vars.RequestVarsDebugPanel', 'debug_toolbar.panels.template.TemplateDebugPanel', 'debug_toolbar.panels.sql.SQLDebugPanel', 'debug_toolbar.panels.signals.SignalDebugPanel', 'debug_toolbar.panels.logger.LoggingPanel', )

Friday, July 15, 2011

Page 10: Tools for Development and Debugging in Python

Werkzeugw/ django-devserver

Friday, July 15, 2011

Page 11: Tools for Development and Debugging in Python

$ pip install django-devserver

# settings.pyINSTALLED_APPS = ( 'devserver',)

$ python manage.py runserver

Friday, July 15, 2011

Page 12: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 13: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 14: Tools for Development and Debugging in Python

• SQL Queries (Realtime and Summarized)

• Profiling (Execution time, Memory Usage)

• Cache usage summary

• Ajax requests

• Session information

• Write your own!

Friday, July 15, 2011

Page 15: Tools for Development and Debugging in Python

class AjaxDumpModule(DevServerModule): """ Dumps the content of all AJAX responses. """

logger_name = 'ajax' def process_response(self, request, response): if request.is_ajax(): self.logger.info(response.content)

Friday, July 15, 2011

Page 16: Tools for Development and Debugging in Python

Extending the Toolbar

DEVSERVER_MODULES = ( 'devserver.modules.sql.SQLSummaryModule', 'devserver.modules.ajax.AjaxDumpModule’, 'devserver.modules.profile.ProfileSummaryModule', 'devserver.modules.request.SessionInfoModule', 'devserver.modules.profile.MemoryUseModule', 'devserver.modules.profile.LeftOversModule', 'devserver.modules.cache.CacheSummaryModule', )

Friday, July 15, 2011

Page 17: Tools for Development and Debugging in Python

Sentry

Friday, July 15, 2011

Page 18: Tools for Development and Debugging in Python

$ pip install django-sentry

# settings.pyINSTALLED_APPS = ( 'sentry', 'sentry.client',)

Friday, July 15, 2011

Page 19: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 20: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 21: Tools for Development and Debugging in Python

# settings.pyMIDDLEWARE_CLASSES = ( 'sentry.client.middleware.SentryResponseErrorIdMiddleware',)

# 500.html<p>Sorry friends, something’s not working.</p>

{% if request.sentry.id %} <p>If you need assistance, you may reference this error as <strong>{{ request.sentry.id }}</strong>.</p>{% endif %}

Friday, July 15, 2011

Page 22: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 23: Tools for Development and Debugging in Python

• Builtin support for Celery

• Server/Client (clients can be any language)

• 2.x powered by Flask/Redis (no Django)

Friday, July 15, 2011

Page 24: Tools for Development and Debugging in Python

Gargoyle

Friday, July 15, 2011

Page 25: Tools for Development and Debugging in Python

$ pip install gargoyle

# settings.pyINSTALLED_APPS = ( 'gargoyle',)

Friday, July 15, 2011

Page 26: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 27: Tools for Development and Debugging in Python

from gargoyle import gargoyle

def my_view(request): if gargoyle.is_active('awesome', request): return 'new happy version :D' else: return 'old sad version :('

Friday, July 15, 2011

Page 28: Tools for Development and Debugging in Python

class HostConditionSet(ConditionSet): hostname = String()

def can_execute(self, instance): return instance is None def get_field_value(self, instance, field_name): if field_name == 'hostname': return socket.gethostname()

gargoyle.register(HostConditionSet())

Friday, July 15, 2011

Page 29: Tools for Development and Debugging in Python

Friday, July 15, 2011

Page 30: Tools for Development and Debugging in Python

Wrap Up

Friday, July 15, 2011

Page 31: Tools for Development and Debugging in Python

DISQUSQuestions?

psst, we’re [email protected]

Friday, July 15, 2011

Page 32: Tools for Development and Debugging in Python

References

• Debug Toolbarhttps://github.com/django-debug-toolbar/django-debug-toolbar

• Devserverhttps://github.com/dcramer/django-devserver

• Werkzeughttps://github.com/mitsuhiko/werkzeug

• Gargoylehttps://github.com/disqus/gargoyle

• Sentryhttps://github.com/dcramer/django-sentry (1.x)https://github.com/dcramer/sentry (2.x)

code.disqus.com

Friday, July 15, 2011