Confessions of
Joe Developer
   Daniel Greenfeld
Daniel Greenfeld
                                                                                 @pydanny




                               Who am I?
                                                 Daniel Greenfeld (@pydanny)
                                                 Pythonista at Cartwheel
                                                 Djangonaut at Revsys
                                                 Co-lead of djangopackages.com
                                                 & Packaginator (Open
                                                 Comparison)
                                                 Fiancé of Audrey Roy

http://www.flickr.com/photos/pydanny/4442245488
Why am I talking?
I’m stupid and lazy
I’m stupid
Daniel Greenfeld
                   @pydanny




I’m stupid
Daniel Greenfeld
                                 @pydanny




            I’m stupid

• Can’t figure things out
Daniel Greenfeld
                                 @pydanny




           I’m stupid

• Can’t figure things out
• Can’t remember things
Daniel Greenfeld
                                                 @pydanny




            I’m stupid

• Can’t figure things out
• Can’t remember things
• Too stupid not to ask stupid questions
Daniel Greenfeld
                               @pydanny




   I’m stupid
Can’t figure things out
Daniel Greenfeld
                                                     @pydanny




             I’m stupid
        Can’t figure things out
• If I get stuck for more than 30 minutes...
Daniel Greenfeld
                                                     @pydanny




             I’m stupid
        Can’t figure things out
• If I get stuck for more than 30 minutes...
 • Find libraries that do it for me
Daniel Greenfeld
                                                     @pydanny




             I’m stupid
        Can’t figure things out
• If I get stuck for more than 30 minutes...
 • Find libraries that do it for me
 • Ask on Twitter for answers
Daniel Greenfeld
                                                     @pydanny




             I’m stupid
        Can’t figure things out
• If I get stuck for more than 30 minutes...
 • Find libraries that do it for me
 • Ask on Twitter for answers
 • Stack Overflow is also good, but watch
    for trolls.
Daniel Greenfeld
                                                      @pydanny




             I’m stupid
        Can’t figure things out
• If I get stuck for more than 30 minutes...
 • Find libraries that do it for me
 • Ask on Twitter for answers
 • Stack Overflow is also good, but watch
    for trolls.
  • IRC can be good, if you get a troll try a
    different channel.
Daniel Greenfeld
                               @pydanny




   I’m stupid
Can’t figure things out
Daniel Greenfeld
                                                                          @pydanny




                                                  I’m stupid
                                     Can’t figure things out

      “Smart” people way
# This sample gleefully taken from https://gist.github.com/973705

import urllib2

gh_url = 'https://api.github.com'
gh_user= 'user'
gh_pass = 'pass'

req = urllib2.Request(gh_url)

password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, gh_url, gh_user, gh_pass)

auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)
opener = urllib2.build_opener(auth_manager)

urllib2.install_opener(opener)

handler = urllib2.urlopen(req)

print handler.getcode()
print handler.headers.getheader('content-type')

# ------
# 200
# 'application/json'
Daniel Greenfeld
                                                                                                                 @pydanny




                                                  I’m stupid
                                     Can’t figure things out

      “Smart” people way                                                     PyDanny way
# This sample gleefully taken from https://gist.github.com/973705
                                                                    # This sample joyfully taken from
import urllib2
                                                                    # https://gist.github.com/973705
gh_url = 'https://api.github.com'
gh_user= 'user'
gh_pass = 'pass'                                                    import requests
req = urllib2.Request(gh_url)
                                                                    r = requests.get('https://api.github.com',
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()                            auth=('user', 'pass'))
password_manager.add_password(None, gh_url, gh_user, gh_pass)

auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)       print r.status_code
opener = urllib2.build_opener(auth_manager)
                                                                    print r.headers['content-type']
urllib2.install_opener(opener)

handler = urllib2.urlopen(req)                                      # ------
                                                                    # 200
print handler.getcode()
print handler.headers.getheader('content-type')                     # 'application/json'
# ------
# 200
# 'application/json'
Daniel Greenfeld
                            @pydanny




I’m stupid
        ‘Smart way’
             aka
          hard way
Daniel Greenfeld
                                                                      @pydanny




                 I’m stupid
# This sample gleefully taken from
# https://gist.github.com/973705
                                          ‘Smart way’
import urllib2
                                               aka
gh_url = 'https://api.github.com'
gh_user= 'user'
gh_pass = 'pass'
                                            hard way
req = urllib2.Request(gh_url)

password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, gh_url, gh_user, gh_pass)

auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)
opener = urllib2.build_opener(auth_manager)

urllib2.install_opener(opener)

handler = urllib2.urlopen(req)

print handler.getcode()
print handler.headers.getheader('content-type')

# ------
# 200
# 'application/json'
Daniel Greenfeld
                                                                                 @pydanny




                            I’m stupid
           # This sample gleefully taken from
           # https://gist.github.com/973705
                                                     ‘Smart way’
 What      import urllib2
                                                          aka
is this?   gh_url = 'https://api.github.com'
           gh_user= 'user'
           gh_pass = 'pass'
                                                       hard way
           req = urllib2.Request(gh_url)

           password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
           password_manager.add_password(None, gh_url, gh_user, gh_pass)

           auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)
           opener = urllib2.build_opener(auth_manager)

           urllib2.install_opener(opener)

           handler = urllib2.urlopen(req)

           print handler.getcode()
           print handler.headers.getheader('content-type')

           # ------
           # 200
           # 'application/json'
Daniel Greenfeld
                                                                                 @pydanny




                            I’m stupid
           # This sample gleefully taken from
           # https://gist.github.com/973705
                                                     ‘Smart way’
 What      import urllib2
                                                          aka
is this?   gh_url = 'https://api.github.com'
           gh_user= 'user'
           gh_pass = 'pass'
                                                       hard way
           req = urllib2.Request(gh_url)

           password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
           password_manager.add_password(None, gh_url, gh_user, gh_pass)

           auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)
           opener = urllib2.build_opener(auth_manager)
 And       urllib2.install_opener(opener)
 this?     handler = urllib2.urlopen(req)

           print handler.getcode()
           print handler.headers.getheader('content-type')

           # ------
           # 200
           # 'application/json'
Daniel Greenfeld
                                                                                  @pydanny




                            I’m stupid
           # This sample gleefully taken from
           # https://gist.github.com/973705
                                                     ‘Smart way’
 What      import urllib2
                                                          aka
is this?   gh_url = 'https://api.github.com'
           gh_user= 'user'
           gh_pass = 'pass'
                                                       hard way
           req = urllib2.Request(gh_url)

           password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
           password_manager.add_password(None, gh_url, gh_user, gh_pass)

           auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)
           opener = urllib2.build_opener(auth_manager)
 And       urllib2.install_opener(opener)
                                                                    What is an
 this?                                                            install opener?
           handler = urllib2.urlopen(req)

           print handler.getcode()
           print handler.headers.getheader('content-type')

           # ------
           # 200
           # 'application/json'
Daniel Greenfeld
                                                                                  @pydanny




                            I’m stupid
           # This sample gleefully taken from
           # https://gist.github.com/973705
                                                     ‘Smart way’
 What      import urllib2
                                                          aka
is this?   gh_url = 'https://api.github.com'
           gh_user= 'user'
           gh_pass = 'pass'
                                                       hard way
           req = urllib2.Request(gh_url)

           password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
           password_manager.add_password(None, gh_url, gh_user, gh_pass)

           auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)
           opener = urllib2.build_opener(auth_manager)
 And       urllib2.install_opener(opener)
                                                                    What is an
 this?                                                            install opener?
           handler = urllib2.urlopen(req)

           print handler.getcode()
           print handler.headers.getheader('content-type')        Finally we make
           # ------                                                 the request!
           # 200
           # 'application/json'
Daniel Greenfeld
                                     @pydanny




   I’m stupid            ‘Stupid way’
                              aka
Can’t figure things out
                           easy way
Daniel Greenfeld
                                                     @pydanny




         I’m stupid                      ‘Stupid way’
                                              aka
    Can’t figure things out
                                           easy way
# This sample joyfully taken from
# https://gist.github.com/973705

import requests

r = requests.get('https://api.github.com',
            auth=('user', 'pass'))

print r.status_code
print r.headers['content-type']

# ------
# 200
# 'application/json'
Daniel Greenfeld
                                                            @pydanny




                I’m stupid                      ‘Stupid way’
                                                     aka
HTTP       Can’t figure things out
GET                                               easy way
       # This sample joyfully taken from
       # https://gist.github.com/973705

       import requests

       r = requests.get('https://api.github.com',
                   auth=('user', 'pass'))

       print r.status_code
       print r.headers['content-type']

       # ------
       # 200
       # 'application/json'
Daniel Greenfeld
                                                                @pydanny




                    I’m stupid                      ‘Stupid way’
                                                         aka
HTTP           Can’t figure things out
GET                                                   easy way
           # This sample joyfully taken from
           # https://gist.github.com/973705

           import requests

           r = requests.get('https://api.github.com',
Username               auth=('user', 'pass'))
    +
           print r.status_code
Password   print r.headers['content-type']

           # ------
           # 200
           # 'application/json'
Daniel Greenfeld
                                                                                                                 @pydanny




                                                  I’m stupid
                                     Can’t figure things out

      “Smart” people way                                                     PyDanny way
# This sample gleefully taken from https://gist.github.com/973705
                                                                    # This sample joyfully taken from
import urllib2
                                                                    # https://gist.github.com/973705
gh_url = 'https://api.github.com'
gh_user= 'user'
gh_pass = 'pass'                                                    import requests
req = urllib2.Request(gh_url)
                                                                    r = requests.get('https://api.github.com',
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()                            auth=('user', 'pass'))
password_manager.add_password(None, gh_url, gh_user, gh_pass)

auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)       print r.status_code
opener = urllib2.build_opener(auth_manager)
                                                                    print r.headers['content-type']
urllib2.install_opener(opener)

handler = urllib2.urlopen(req)                                      # ------
                                                                    # 200
print handler.getcode()
print handler.headers.getheader('content-type')                     # 'application/json'
# ------
# 200
# 'application/json'
Daniel Greenfeld
                                           @pydanny




           I’m stupid
Too stupid not to ask stupid questions
Daniel Greenfeld
                                           @pydanny




             I’m stupid
Too stupid not to ask stupid questions




 • There are no stupid questions
Daniel Greenfeld
                                                   @pydanny




             I’m stupid
Too stupid not to ask stupid questions




 • There are no stupid questions
 • Don’t try and impress the people around
   you by not asking questions.
Daniel Greenfeld
                                              @pydanny




           I’m stupid
Too stupid not to ask stupid questions


         You are at DjangoCon.

       If you don’t ask the question,
       you are wasting opportunity.
Daniel Greenfeld
                                                     @pydanny




             I’m stupid
Too stupid not to ask stupid questions


         You are at DjangoCon.

    A positive trait good tech leads often
   look for is the ability to ask questions.
Daniel Greenfeld
                              @pydanny




   I’m stupid
Can’t remember things
Daniel Greenfeld
                                           @pydanny




          I’m stupid
      Can’t remember things


• Documentation makes me look good
Daniel Greenfeld
                                           @pydanny




          I’m stupid
      Can’t remember things


• Documentation makes me look good
• Docstrings are awesome
Daniel Greenfeld
                                           @pydanny




          I’m stupid
      Can’t remember things


• Documentation makes me look good
• Docstrings are awesome
• Learn you some Restructured Text
Daniel Greenfeld
                                             @pydanny




           I’m stupid
       Can’t remember things


• Documentation makes me look good
• Docstrings are awesome
• Learn you some Restructured Text
• Write down even the slide bullets!
Daniel Greenfeld
                                                           @pydanny




               I’m stupid
         Can’t remember things


• Documentation makes me look good
• Docstrings are awesome
• Learn you some Restructured Text
• Write down even the slide bullets!
•   https://github.com/pydanny/pydanny-event-notes
Daniel Greenfeld



        Joe Developer
                                                     @pydanny




          Resources
      Where the code examples live!


https://github.com/pydanny/django-party-pack

      http://django-party-pack.rtfd.org/
Daniel Greenfeld
                                                      @pydanny




            I’m stupid




http://readthedocs.org/docs/django-party-pack
Daniel Greenfeld
                                                          @pydanny




                I’m stupid

Sphinx
makes
  me
 look
good!



    http://readthedocs.org/docs/django-party-pack
Daniel Greenfeld
                                                   @pydanny




   Docs/Sphinx Basics

• pip install sphinx
• make a docs directory
• sphinx-quickstart
• Follow instructions
• Starting over is just removing your docs
Daniel Greenfeld
                                                                                                @pydanny




                        I’m stupid
        Sphinx makes me look good!
 =============
 Installation
 =============

 .. note:: For things with **font like this** it means type it at the command line and hit enter.

 The Basics
 ===========

 0.   **git clone https://pydanny@github.com/pydanny/django-party-pack.git**
 1.   Make sure you have virtualenv installed.
 2.   change directory to the directory that contains this README.rst file.
 3.   **virtualenv pollaxe** and then **source pollaxe/bin/activate**
 4.   **pip install -r requirements.txt**
 5.   **mkdir pollaxe/coverage**

 Building the sphinx docs
 =========================

 1. change directory to docs
 2. **make html**

 Running django-coverage
 ========================

 1. python manage.py test




http://readthedocs.org/docs/django-party-pack/en/latest/_sources/install.txt
Daniel Greenfeld
                                                                                                         @pydanny




 page
header
                                 I’m stupid
                 Sphinx makes me look good!
          =============
          Installation
          =============

          .. note:: For things with **font like this** it means type it at the command line and hit enter.

          The Basics
          ===========

          0.   **git clone https://pydanny@github.com/pydanny/django-party-pack.git**
          1.   Make sure you have virtualenv installed.
          2.   change directory to the directory that contains this README.rst file.
          3.   **virtualenv pollaxe** and then **source pollaxe/bin/activate**
          4.   **pip install -r requirements.txt**
          5.   **mkdir pollaxe/coverage**

          Building the sphinx docs
          =========================

          1. change directory to docs
          2. **make html**

          Running django-coverage
          ========================

          1. python manage.py test




         http://readthedocs.org/docs/django-party-pack/en/latest/_sources/install.txt
Daniel Greenfeld
                                                                                                         @pydanny




 page
header
                                 I’m stupid
                 Sphinx makes me look good!
          =============
note      Installation
          =============

block     .. note:: For things with **font like this** it means type it at the command line and hit enter.

          The Basics
          ===========

          0.   **git clone https://pydanny@github.com/pydanny/django-party-pack.git**
          1.   Make sure you have virtualenv installed.
          2.   change directory to the directory that contains this README.rst file.
          3.   **virtualenv pollaxe** and then **source pollaxe/bin/activate**
          4.   **pip install -r requirements.txt**
          5.   **mkdir pollaxe/coverage**

          Building the sphinx docs
          =========================

          1. change directory to docs
          2. **make html**

          Running django-coverage
          ========================

          1. python manage.py test




         http://readthedocs.org/docs/django-party-pack/en/latest/_sources/install.txt
Daniel Greenfeld
                                                                                                          @pydanny




 page
header
                                  I’m stupid
                  Sphinx makes me look good!
           =============
note       Installation
           =============

block      .. note:: For things with **font like this** it means type it at the command line and hit enter.

           The Basics
           ===========

           0.   **git clone https://pydanny@github.com/pydanny/django-party-pack.git**
           1.   Make sure you have virtualenv installed.

section    2.
           3.
                change directory to the directory that contains this README.rst file.
                **virtualenv pollaxe** and then **source pollaxe/bin/activate**

headers
           4.   **pip install -r requirements.txt**
           5.   **mkdir pollaxe/coverage**

           Building the sphinx docs
           =========================

           1. change directory to docs
           2. **make html**

           Running django-coverage
           ========================

           1. python manage.py test




          http://readthedocs.org/docs/django-party-pack/en/latest/_sources/install.txt
Daniel Greenfeld
                                                      @pydanny




            I’m stupid




http://readthedocs.org/docs/django-party-pack
Daniel Greenfeld
                                                          @pydanny




                I’m stupid

Sphinx
makes
  me
 look
good!



    http://readthedocs.org/docs/django-party-pack
Daniel Greenfeld
                                                                                     @pydanny




                    I’m stupid
     Sphinx makes me look good!




http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
Daniel Greenfeld
                                                                                     @pydanny




                    I’m stupid
      Sphinx makes me look good!




http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
Daniel Greenfeld
                                                                                             @pydanny




                      I’m stupid
      Sphinx makes me look good!
        ========================
        Reference for Polls App
        ========================

        The polls app is a copy of the Django tutorial with some mild PEP-8 cleanup.

        ``polls.models``
        =================
        .. automodule:: polls.models
            :members:

        ``polls.views``
        =================
        .. automodule:: polls.views
            :members:

        ``polls.tests``
        =================
        .. automodule:: polls.tests.test_models
            :members:
            :undoc-members:

        .. automodule:: polls.tests.test_views
            :members:
            :undoc-members:




http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
Daniel Greenfeld
                                                                                                      @pydanny




                               I’m stupid
               Sphinx makes me look good!
                 ========================

 page            Reference for Polls App
                 ========================

header           The polls app is a copy of the Django tutorial with some mild PEP-8 cleanup.

                 ``polls.models``
                 =================
                 .. automodule:: polls.models
                     :members:

                 ``polls.views``
                 =================
                 .. automodule:: polls.views
                     :members:

                 ``polls.tests``
                 =================
                 .. automodule:: polls.tests.test_models
                     :members:
                     :undoc-members:

                 .. automodule:: polls.tests.test_views
                     :members:
                     :undoc-members:




         http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
Daniel Greenfeld
                                                                                                      @pydanny




                               I’m stupid
               Sphinx makes me look good!
                 ========================

 page            Reference for Polls App
                 ========================

header           The polls app is a copy of the Django tutorial with some mild PEP-8 cleanup.

                 ``polls.models``
                 =================

auto-
                 .. automodule:: polls.models
                     :members:


model            ``polls.views``
                 =================
                 .. automodule:: polls.views
                     :members:

                 ``polls.tests``
                 =================
                 .. automodule:: polls.tests.test_models
                     :members:
                     :undoc-members:

                 .. automodule:: polls.tests.test_views
                     :members:
                     :undoc-members:




         http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
Daniel Greenfeld
                                                                                                      @pydanny




                               I’m stupid
               Sphinx makes me look good!
                 ========================

 page            Reference for Polls App
                 ========================

header           The polls app is a copy of the Django tutorial with some mild PEP-8 cleanup.

                 ``polls.models``
                 =================

auto-
                 .. automodule:: polls.models
                     :members:


model            ``polls.views``
                 =================
                 .. automodule:: polls.views
                     :members:
                                                                         auto-model
                 ``polls.tests``
                 =================
                                                                     for undocumented
                 .. automodule:: polls.tests.test_models
                     :members:
                                                                            items
                     :undoc-members:

                 .. automodule:: polls.tests.test_views
                     :members:
                     :undoc-members:




         http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
Daniel Greenfeld
                                                                                     @pydanny




                    I’m stupid
     Sphinx makes me look good!




http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
Daniel Greenfeld
                                                                                     @pydanny




                    I’m stupid
      Sphinx makes me look good!




http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
Daniel Greenfeld
                                                                          @pydanny




         Sphinx walk-through

http://audreyr.posterous.com/how-to-create-sphinx-docs-the-python-github-r


                                   or

          http://bit.ly/audreyr-sphinx
I’m lazy
Daniel Greenfeld
                 @pydanny




I’m lazy
Daniel Greenfeld
                                        @pydanny




             I’m lazy

• Don’t wanna do anything twice
Daniel Greenfeld
                                               @pydanny




             I’m lazy

• Don’t wanna do anything twice
• Don’t wanna debug code when I had it
  working before
Daniel Greenfeld
                                                   @pydanny




             I’m lazy

• Don’t wanna do anything twice
• Don’t wanna debug code when I had it
  working before
• Don’t wanna upload zip files per document
  change
Daniel Greenfeld
                                      @pydanny




        I’m lazy
Don’t wanna do anything twice
Daniel Greenfeld
                                                         @pydanny




               I’m lazy
   Don’t wanna do anything twice

• If I write the same code twice I stick it in a
  function
Daniel Greenfeld
                                                         @pydanny




               I’m lazy
   Don’t wanna do anything twice

• If I write the same code twice I stick it in a
  function
• Then I stick the function into a util module.
Daniel Greenfeld
                                                         @pydanny




               I’m lazy
   Don’t wanna do anything twice

• If I write the same code twice I stick it in a
  function
• Then I stick the function into a util module.
• Then I put it on Github so I don’t lose it.
Daniel Greenfeld
                                                         @pydanny




               I’m lazy
   Don’t wanna do anything twice

• If I write the same code twice I stick it in a
  function
• Then I stick the function into a util module.
• Then I put it on Github so I don’t lose it.
• Isn’t this kinda the whole thing behind Open
  Source?
Daniel Greenfeld
                                                    @pydanny




                  I’m Lazy
Don’t wanna debug code when I had it working before
Daniel Greenfeld
                                                           @pydanny




                   I’m Lazy
Don’t wanna debug code when I had it working before

     • Manually testing code by watching it run is
        hard...
Daniel Greenfeld
                                                           @pydanny




                    I’m Lazy
Don’t wanna debug code when I had it working before

     • Manually testing code by watching it run is
        hard...
     • ...and boring...
Daniel Greenfeld
                                                           @pydanny




                   I’m Lazy
Don’t wanna debug code when I had it working before

     • Manually testing code by watching it run is
        hard...
     • ...and boring...
     • ...and hence is error prone.
Daniel Greenfeld
                                                           @pydanny




                   I’m Lazy
Don’t wanna debug code when I had it working before

     • Manually testing code by watching it run is
        hard...
     • ...and boring...
     • ...and hence is error prone.
     • Meaning you have to do more work.
Daniel Greenfeld
                                @pydanny




    I’m Lazy
Are you testing enough?
Daniel Greenfeld
                                                @pydanny




                    I’m Lazy
                Are you testing enough?




 Stick even
 the ‘basic
stuff’ in the
    docs!
Daniel Greenfeld
                                @pydanny




    I’m Lazy
Are you testing enough?
Daniel Greenfeld
                                                          @pydanny




                    I’m Lazy
               Are you testing enough?




Yeah, some of the configuration is off. Will be fixed soon.
Daniel Greenfeld
                                                  @pydanny




         Coverage Tricks

• coverage.py is great
• django-coverage runs coverage.py for Django
• But you only want to test your own apps
Daniel Greenfeld



settings.py
                                                                        @pydanny



              import os.path

              PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

              PREREQ_APPS = (
                  'django.contrib.auth',
                  'django.contrib.contenttypes',
                  'django.contrib.sessions',
                  'django.contrib.sites',
                  'django.contrib.messages',
                  'django.contrib.admin',
                  'django-debug-toolbar’,
              )

              PROJECT_APPS = (
                  'polls',
              )

              INSTALLED_APPS = PREREQ_APPS + PROJECT_APPS

              COVERAGE_MODULE_EXCLUDES = [
                  'tests$', 'settings$', 'urls$', 'locale$',
                  'migrations', 'fixtures', 'admin$',
              ]
              COVERAGE_MODULE_EXCLUDES += PREREQ_APPS

              COVERAGE_REPORT_HTML_OUTPUT_DIR = "coverage"
              HTML_OUTPUT_DIR = os.path.join(PROJECT_ROOT, "coverage")

              TEST_RUNNER = 'testrunner.OurCoverageRunner'

Confessions of Joe Developer

  • 1.
  • 2.
    Daniel Greenfeld @pydanny Who am I? Daniel Greenfeld (@pydanny) Pythonista at Cartwheel Djangonaut at Revsys Co-lead of djangopackages.com & Packaginator (Open Comparison) Fiancé of Audrey Roy http://www.flickr.com/photos/pydanny/4442245488
  • 3.
    Why am Italking?
  • 4.
  • 6.
  • 7.
    Daniel Greenfeld @pydanny I’m stupid
  • 8.
    Daniel Greenfeld @pydanny I’m stupid • Can’t figure things out
  • 9.
    Daniel Greenfeld @pydanny I’m stupid • Can’t figure things out • Can’t remember things
  • 10.
    Daniel Greenfeld @pydanny I’m stupid • Can’t figure things out • Can’t remember things • Too stupid not to ask stupid questions
  • 11.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out
  • 12.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out • If I get stuck for more than 30 minutes...
  • 13.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out • If I get stuck for more than 30 minutes... • Find libraries that do it for me
  • 14.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out • If I get stuck for more than 30 minutes... • Find libraries that do it for me • Ask on Twitter for answers
  • 15.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out • If I get stuck for more than 30 minutes... • Find libraries that do it for me • Ask on Twitter for answers • Stack Overflow is also good, but watch for trolls.
  • 16.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out • If I get stuck for more than 30 minutes... • Find libraries that do it for me • Ask on Twitter for answers • Stack Overflow is also good, but watch for trolls. • IRC can be good, if you get a troll try a different channel.
  • 17.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out
  • 18.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out “Smart” people way # This sample gleefully taken from https://gist.github.com/973705 import urllib2 gh_url = 'https://api.github.com' gh_user= 'user' gh_pass = 'pass' req = urllib2.Request(gh_url) password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, gh_url, gh_user, gh_pass) auth_manager = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(auth_manager) urllib2.install_opener(opener) handler = urllib2.urlopen(req) print handler.getcode() print handler.headers.getheader('content-type') # ------ # 200 # 'application/json'
  • 19.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out “Smart” people way PyDanny way # This sample gleefully taken from https://gist.github.com/973705 # This sample joyfully taken from import urllib2 # https://gist.github.com/973705 gh_url = 'https://api.github.com' gh_user= 'user' gh_pass = 'pass' import requests req = urllib2.Request(gh_url) r = requests.get('https://api.github.com', password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() auth=('user', 'pass')) password_manager.add_password(None, gh_url, gh_user, gh_pass) auth_manager = urllib2.HTTPBasicAuthHandler(password_manager) print r.status_code opener = urllib2.build_opener(auth_manager) print r.headers['content-type'] urllib2.install_opener(opener) handler = urllib2.urlopen(req) # ------ # 200 print handler.getcode() print handler.headers.getheader('content-type') # 'application/json' # ------ # 200 # 'application/json'
  • 20.
    Daniel Greenfeld @pydanny I’m stupid ‘Smart way’ aka hard way
  • 21.
    Daniel Greenfeld @pydanny I’m stupid # This sample gleefully taken from # https://gist.github.com/973705 ‘Smart way’ import urllib2 aka gh_url = 'https://api.github.com' gh_user= 'user' gh_pass = 'pass' hard way req = urllib2.Request(gh_url) password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, gh_url, gh_user, gh_pass) auth_manager = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(auth_manager) urllib2.install_opener(opener) handler = urllib2.urlopen(req) print handler.getcode() print handler.headers.getheader('content-type') # ------ # 200 # 'application/json'
  • 22.
    Daniel Greenfeld @pydanny I’m stupid # This sample gleefully taken from # https://gist.github.com/973705 ‘Smart way’ What import urllib2 aka is this? gh_url = 'https://api.github.com' gh_user= 'user' gh_pass = 'pass' hard way req = urllib2.Request(gh_url) password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, gh_url, gh_user, gh_pass) auth_manager = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(auth_manager) urllib2.install_opener(opener) handler = urllib2.urlopen(req) print handler.getcode() print handler.headers.getheader('content-type') # ------ # 200 # 'application/json'
  • 23.
    Daniel Greenfeld @pydanny I’m stupid # This sample gleefully taken from # https://gist.github.com/973705 ‘Smart way’ What import urllib2 aka is this? gh_url = 'https://api.github.com' gh_user= 'user' gh_pass = 'pass' hard way req = urllib2.Request(gh_url) password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, gh_url, gh_user, gh_pass) auth_manager = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(auth_manager) And urllib2.install_opener(opener) this? handler = urllib2.urlopen(req) print handler.getcode() print handler.headers.getheader('content-type') # ------ # 200 # 'application/json'
  • 24.
    Daniel Greenfeld @pydanny I’m stupid # This sample gleefully taken from # https://gist.github.com/973705 ‘Smart way’ What import urllib2 aka is this? gh_url = 'https://api.github.com' gh_user= 'user' gh_pass = 'pass' hard way req = urllib2.Request(gh_url) password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, gh_url, gh_user, gh_pass) auth_manager = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(auth_manager) And urllib2.install_opener(opener) What is an this? install opener? handler = urllib2.urlopen(req) print handler.getcode() print handler.headers.getheader('content-type') # ------ # 200 # 'application/json'
  • 25.
    Daniel Greenfeld @pydanny I’m stupid # This sample gleefully taken from # https://gist.github.com/973705 ‘Smart way’ What import urllib2 aka is this? gh_url = 'https://api.github.com' gh_user= 'user' gh_pass = 'pass' hard way req = urllib2.Request(gh_url) password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, gh_url, gh_user, gh_pass) auth_manager = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(auth_manager) And urllib2.install_opener(opener) What is an this? install opener? handler = urllib2.urlopen(req) print handler.getcode() print handler.headers.getheader('content-type') Finally we make # ------ the request! # 200 # 'application/json'
  • 26.
    Daniel Greenfeld @pydanny I’m stupid ‘Stupid way’ aka Can’t figure things out easy way
  • 27.
    Daniel Greenfeld @pydanny I’m stupid ‘Stupid way’ aka Can’t figure things out easy way # This sample joyfully taken from # https://gist.github.com/973705 import requests r = requests.get('https://api.github.com', auth=('user', 'pass')) print r.status_code print r.headers['content-type'] # ------ # 200 # 'application/json'
  • 28.
    Daniel Greenfeld @pydanny I’m stupid ‘Stupid way’ aka HTTP Can’t figure things out GET easy way # This sample joyfully taken from # https://gist.github.com/973705 import requests r = requests.get('https://api.github.com', auth=('user', 'pass')) print r.status_code print r.headers['content-type'] # ------ # 200 # 'application/json'
  • 29.
    Daniel Greenfeld @pydanny I’m stupid ‘Stupid way’ aka HTTP Can’t figure things out GET easy way # This sample joyfully taken from # https://gist.github.com/973705 import requests r = requests.get('https://api.github.com', Username auth=('user', 'pass')) + print r.status_code Password print r.headers['content-type'] # ------ # 200 # 'application/json'
  • 30.
    Daniel Greenfeld @pydanny I’m stupid Can’t figure things out “Smart” people way PyDanny way # This sample gleefully taken from https://gist.github.com/973705 # This sample joyfully taken from import urllib2 # https://gist.github.com/973705 gh_url = 'https://api.github.com' gh_user= 'user' gh_pass = 'pass' import requests req = urllib2.Request(gh_url) r = requests.get('https://api.github.com', password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() auth=('user', 'pass')) password_manager.add_password(None, gh_url, gh_user, gh_pass) auth_manager = urllib2.HTTPBasicAuthHandler(password_manager) print r.status_code opener = urllib2.build_opener(auth_manager) print r.headers['content-type'] urllib2.install_opener(opener) handler = urllib2.urlopen(req) # ------ # 200 print handler.getcode() print handler.headers.getheader('content-type') # 'application/json' # ------ # 200 # 'application/json'
  • 31.
    Daniel Greenfeld @pydanny I’m stupid Too stupid not to ask stupid questions
  • 32.
    Daniel Greenfeld @pydanny I’m stupid Too stupid not to ask stupid questions • There are no stupid questions
  • 33.
    Daniel Greenfeld @pydanny I’m stupid Too stupid not to ask stupid questions • There are no stupid questions • Don’t try and impress the people around you by not asking questions.
  • 34.
    Daniel Greenfeld @pydanny I’m stupid Too stupid not to ask stupid questions You are at DjangoCon. If you don’t ask the question, you are wasting opportunity.
  • 35.
    Daniel Greenfeld @pydanny I’m stupid Too stupid not to ask stupid questions You are at DjangoCon. A positive trait good tech leads often look for is the ability to ask questions.
  • 36.
    Daniel Greenfeld @pydanny I’m stupid Can’t remember things
  • 37.
    Daniel Greenfeld @pydanny I’m stupid Can’t remember things • Documentation makes me look good
  • 38.
    Daniel Greenfeld @pydanny I’m stupid Can’t remember things • Documentation makes me look good • Docstrings are awesome
  • 39.
    Daniel Greenfeld @pydanny I’m stupid Can’t remember things • Documentation makes me look good • Docstrings are awesome • Learn you some Restructured Text
  • 40.
    Daniel Greenfeld @pydanny I’m stupid Can’t remember things • Documentation makes me look good • Docstrings are awesome • Learn you some Restructured Text • Write down even the slide bullets!
  • 41.
    Daniel Greenfeld @pydanny I’m stupid Can’t remember things • Documentation makes me look good • Docstrings are awesome • Learn you some Restructured Text • Write down even the slide bullets! • https://github.com/pydanny/pydanny-event-notes
  • 42.
    Daniel Greenfeld Joe Developer @pydanny Resources Where the code examples live! https://github.com/pydanny/django-party-pack http://django-party-pack.rtfd.org/
  • 43.
    Daniel Greenfeld @pydanny I’m stupid http://readthedocs.org/docs/django-party-pack
  • 44.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! http://readthedocs.org/docs/django-party-pack
  • 45.
    Daniel Greenfeld @pydanny Docs/Sphinx Basics • pip install sphinx • make a docs directory • sphinx-quickstart • Follow instructions • Starting over is just removing your docs
  • 46.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! ============= Installation ============= .. note:: For things with **font like this** it means type it at the command line and hit enter. The Basics =========== 0. **git clone https://pydanny@github.com/pydanny/django-party-pack.git** 1. Make sure you have virtualenv installed. 2. change directory to the directory that contains this README.rst file. 3. **virtualenv pollaxe** and then **source pollaxe/bin/activate** 4. **pip install -r requirements.txt** 5. **mkdir pollaxe/coverage** Building the sphinx docs ========================= 1. change directory to docs 2. **make html** Running django-coverage ======================== 1. python manage.py test http://readthedocs.org/docs/django-party-pack/en/latest/_sources/install.txt
  • 47.
    Daniel Greenfeld @pydanny page header I’m stupid Sphinx makes me look good! ============= Installation ============= .. note:: For things with **font like this** it means type it at the command line and hit enter. The Basics =========== 0. **git clone https://pydanny@github.com/pydanny/django-party-pack.git** 1. Make sure you have virtualenv installed. 2. change directory to the directory that contains this README.rst file. 3. **virtualenv pollaxe** and then **source pollaxe/bin/activate** 4. **pip install -r requirements.txt** 5. **mkdir pollaxe/coverage** Building the sphinx docs ========================= 1. change directory to docs 2. **make html** Running django-coverage ======================== 1. python manage.py test http://readthedocs.org/docs/django-party-pack/en/latest/_sources/install.txt
  • 48.
    Daniel Greenfeld @pydanny page header I’m stupid Sphinx makes me look good! ============= note Installation ============= block .. note:: For things with **font like this** it means type it at the command line and hit enter. The Basics =========== 0. **git clone https://pydanny@github.com/pydanny/django-party-pack.git** 1. Make sure you have virtualenv installed. 2. change directory to the directory that contains this README.rst file. 3. **virtualenv pollaxe** and then **source pollaxe/bin/activate** 4. **pip install -r requirements.txt** 5. **mkdir pollaxe/coverage** Building the sphinx docs ========================= 1. change directory to docs 2. **make html** Running django-coverage ======================== 1. python manage.py test http://readthedocs.org/docs/django-party-pack/en/latest/_sources/install.txt
  • 49.
    Daniel Greenfeld @pydanny page header I’m stupid Sphinx makes me look good! ============= note Installation ============= block .. note:: For things with **font like this** it means type it at the command line and hit enter. The Basics =========== 0. **git clone https://pydanny@github.com/pydanny/django-party-pack.git** 1. Make sure you have virtualenv installed. section 2. 3. change directory to the directory that contains this README.rst file. **virtualenv pollaxe** and then **source pollaxe/bin/activate** headers 4. **pip install -r requirements.txt** 5. **mkdir pollaxe/coverage** Building the sphinx docs ========================= 1. change directory to docs 2. **make html** Running django-coverage ======================== 1. python manage.py test http://readthedocs.org/docs/django-party-pack/en/latest/_sources/install.txt
  • 50.
    Daniel Greenfeld @pydanny I’m stupid http://readthedocs.org/docs/django-party-pack
  • 51.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! http://readthedocs.org/docs/django-party-pack
  • 52.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
  • 53.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
  • 54.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! ======================== Reference for Polls App ======================== The polls app is a copy of the Django tutorial with some mild PEP-8 cleanup. ``polls.models`` ================= .. automodule:: polls.models :members: ``polls.views`` ================= .. automodule:: polls.views :members: ``polls.tests`` ================= .. automodule:: polls.tests.test_models :members: :undoc-members: .. automodule:: polls.tests.test_views :members: :undoc-members: http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
  • 55.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! ======================== page Reference for Polls App ======================== header The polls app is a copy of the Django tutorial with some mild PEP-8 cleanup. ``polls.models`` ================= .. automodule:: polls.models :members: ``polls.views`` ================= .. automodule:: polls.views :members: ``polls.tests`` ================= .. automodule:: polls.tests.test_models :members: :undoc-members: .. automodule:: polls.tests.test_views :members: :undoc-members: http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
  • 56.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! ======================== page Reference for Polls App ======================== header The polls app is a copy of the Django tutorial with some mild PEP-8 cleanup. ``polls.models`` ================= auto- .. automodule:: polls.models :members: model ``polls.views`` ================= .. automodule:: polls.views :members: ``polls.tests`` ================= .. automodule:: polls.tests.test_models :members: :undoc-members: .. automodule:: polls.tests.test_views :members: :undoc-members: http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
  • 57.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! ======================== page Reference for Polls App ======================== header The polls app is a copy of the Django tutorial with some mild PEP-8 cleanup. ``polls.models`` ================= auto- .. automodule:: polls.models :members: model ``polls.views`` ================= .. automodule:: polls.views :members: auto-model ``polls.tests`` ================= for undocumented .. automodule:: polls.tests.test_models :members: items :undoc-members: .. automodule:: polls.tests.test_views :members: :undoc-members: http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
  • 58.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
  • 59.
    Daniel Greenfeld @pydanny I’m stupid Sphinx makes me look good! http://readthedocs.org/docs/django-party-pack/en/latest/reference_polls.html
  • 60.
    Daniel Greenfeld @pydanny Sphinx walk-through http://audreyr.posterous.com/how-to-create-sphinx-docs-the-python-github-r or http://bit.ly/audreyr-sphinx
  • 61.
  • 62.
    Daniel Greenfeld @pydanny I’m lazy
  • 63.
    Daniel Greenfeld @pydanny I’m lazy • Don’t wanna do anything twice
  • 64.
    Daniel Greenfeld @pydanny I’m lazy • Don’t wanna do anything twice • Don’t wanna debug code when I had it working before
  • 65.
    Daniel Greenfeld @pydanny I’m lazy • Don’t wanna do anything twice • Don’t wanna debug code when I had it working before • Don’t wanna upload zip files per document change
  • 66.
    Daniel Greenfeld @pydanny I’m lazy Don’t wanna do anything twice
  • 67.
    Daniel Greenfeld @pydanny I’m lazy Don’t wanna do anything twice • If I write the same code twice I stick it in a function
  • 68.
    Daniel Greenfeld @pydanny I’m lazy Don’t wanna do anything twice • If I write the same code twice I stick it in a function • Then I stick the function into a util module.
  • 69.
    Daniel Greenfeld @pydanny I’m lazy Don’t wanna do anything twice • If I write the same code twice I stick it in a function • Then I stick the function into a util module. • Then I put it on Github so I don’t lose it.
  • 70.
    Daniel Greenfeld @pydanny I’m lazy Don’t wanna do anything twice • If I write the same code twice I stick it in a function • Then I stick the function into a util module. • Then I put it on Github so I don’t lose it. • Isn’t this kinda the whole thing behind Open Source?
  • 71.
    Daniel Greenfeld @pydanny I’m Lazy Don’t wanna debug code when I had it working before
  • 72.
    Daniel Greenfeld @pydanny I’m Lazy Don’t wanna debug code when I had it working before • Manually testing code by watching it run is hard...
  • 73.
    Daniel Greenfeld @pydanny I’m Lazy Don’t wanna debug code when I had it working before • Manually testing code by watching it run is hard... • ...and boring...
  • 74.
    Daniel Greenfeld @pydanny I’m Lazy Don’t wanna debug code when I had it working before • Manually testing code by watching it run is hard... • ...and boring... • ...and hence is error prone.
  • 75.
    Daniel Greenfeld @pydanny I’m Lazy Don’t wanna debug code when I had it working before • Manually testing code by watching it run is hard... • ...and boring... • ...and hence is error prone. • Meaning you have to do more work.
  • 76.
    Daniel Greenfeld @pydanny I’m Lazy Are you testing enough?
  • 77.
    Daniel Greenfeld @pydanny I’m Lazy Are you testing enough? Stick even the ‘basic stuff’ in the docs!
  • 78.
    Daniel Greenfeld @pydanny I’m Lazy Are you testing enough?
  • 79.
    Daniel Greenfeld @pydanny I’m Lazy Are you testing enough? Yeah, some of the configuration is off. Will be fixed soon.
  • 80.
    Daniel Greenfeld @pydanny Coverage Tricks • coverage.py is great • django-coverage runs coverage.py for Django • But you only want to test your own apps
  • 81.
    Daniel Greenfeld settings.py @pydanny import os.path PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) PREREQ_APPS = (     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.sites',     'django.contrib.messages',     'django.contrib.admin', 'django-debug-toolbar’, ) PROJECT_APPS = (     'polls', ) INSTALLED_APPS = PREREQ_APPS + PROJECT_APPS COVERAGE_MODULE_EXCLUDES = [     'tests$', 'settings$', 'urls$', 'locale$',     'migrations', 'fixtures', 'admin$', ] COVERAGE_MODULE_EXCLUDES += PREREQ_APPS COVERAGE_REPORT_HTML_OUTPUT_DIR = "coverage" HTML_OUTPUT_DIR = os.path.join(PROJECT_ROOT, "coverage") TEST_RUNNER = 'testrunner.OurCoverageRunner'