-
Ian's training outlines
last modified October 4, 2006 by ianb
Packaging and setuptools, easy_install, etc.
Overview
- What is setuptools?
- The various parts: setuptools, distutils, Python Eggs, easy_install
- How sys.path and module importing works
- How setuptools modifies sys.path (these last two are important for debugging problems)
- Installation of packages; easy_install and python setup.py
Exercise
- We set up isolated environments. We install some packages. (What packages will we later want?)
Doing stuff
- Creating a package
- Using Paste Script to create a simple package
- Show what all the files mean
- Use Paste Script to create a ZopeSkel package (admire all the files you don't understand yet! -- though there aren't actually that many of them)
Exercise
- We all create HelloWorld packages. We should probably put these somewhere in the repository, as they can provide later practice for doing some subversion tasks and other management things. Maybe in /training/username/HelloWorld
Python Worldview: where to go looking for different types of hammer factories
- I show the Cheese Shop
- I disparage constrained searches like searching SourceForge
- Where to look for Zope/Plone things? I don't actually know.
Overview
- Here's where I give an overview of what's out there in Python
- This is a long list of projects, covered very lightly, with opinions readily offered
- Maybe it should be moved later?
Exercise
- There is no exercise
Advanced Topics
Iterators
- Generators! Yield, piping. Pretend infinite sequences.
- Iterators and the iterator protocol.
- Note generator expressions.
Exercise
- I have to come up with an exercise here. Probably a simple piplining-style task. Also, some novel iterator that can't be written as a generator. Iterators are important and also simple, I want to cover them completely.
Closures
- What's a closure?
- Nested functions -- demonstration
- Setting variables in enclosing scopes (you can't -- demonstration)
- We'll use closures with decorators...
Decorators
- Show a couple decorators: @classmethod, @somethingelse (?), plus the alternate form
- Show a complex form: @something(with_args), plus alternate
- Describe exactly what they do, very exactly.
- Note that @classmethod will be described later (under descriptors)
Exercise
- Write a simple decorator. Something... fun
- Write an annotating decorator. Something... annotationy
- Write a registrating decorator. Something... conversiony
- Write a complex (argument-taking) decorator. Something... optiony
Descriptors
- Descriptors are all around you, but you never knew it! Grainy documentary...
- Show a function, method, and bound method. (Aside: show injection of a method into a class)
- Describe the descriptor protocol in detail.
- Show how functions are already descriptors.
- Show how classmethods are descriptors.
Exercise
- Create a descriptor. Something fun or magic-seeming.
Metaclasses
- Here's where I might not go into a lot of detail.
- Describe type(). Show how you can dynamically create classes.
- If type() is a callable, can any callable work? Somewhat oddly, yes.
- Talk about the Conservative Metaclass, __new__, and __classinit__
- Talk about fancier things, of which I have done only a little. __getattribute__, for instance. Maybe write up some doctests around that, for my own understanding if nothing else.
- Something using __classinit__, somewhat DSLish
Some things that should maybe come earlier in this section...
Magic Methods
- Show all the magic methods.
- Note that they aren't really all that magic.
- Cautionary take on __setattr__ and __getattr__
- Note __call__
- Note that they can be abused. Show SQLBuilder.
- Note no __and__, __not__, etc.
Exercise
- Create a Rational Number class (with a more limited set of methods). I expect this to be a fun/relaxing task for most people.
Pickle (maybe?)
- Describe what it is
- Describe how it works.
- Describe how you override it.
- Caution people on its many challengs
Value Objects
- I don't have a task or idea here, except that I'd like to emphasize this concept to people because I really like this pattern and hope people use it when possible. The Rational class would be an example of this.
Exceptions & Tracebacks
- Note the seldom-used three-argument raise form
- Note __traceback_info__ (a Zope/Paste convention)
Other Functional Tools?
- First-class functions (are they already covered well enough?)
- Dictionary-dispatch
Python 2.5 Features
- I plan to entirely skip these, because we shouldn't consider using them yet. Too bad, but so it goes.
Debugging: reading tracebacks, pdb, etc.
(whit start, ianb advanced topics)
I think I need Whit to outline his part first. I'd consider pdb the advanced stuff, but I don't use it much.
Other testing tools: unittest, py.test or nose.
(ZopeTestCase comes later)
Unittest
- a quick intro (we'll only have discussed doctest so far)
Exercise
- Write a unit test. Convert a doctest we've already used?
py.test & nose
- Show the basic form, the function and the assert
- Show how you run them both
Exercise
- Convert something to py.test and/or nose
py.test & nose compared
- Describe the differences. I should figure out the exact differences too.
Python Web
HTTP client libraries
- urllib, urllib2, httplib: describe the differences.
- Maybe talk about httplib2
- XML/Tag-soup handling. There's several options. Some of them suck and are huge time holes (e.g., HTMLParser).
- I think we should emphasize lxml (or ElementTree if appropriate) and BeautifulSoup (for screen scraping).
- Everyone build lxml? (BS install is a no-brainer, but not so lxml)
- Do some screen-scraping task. Who's screen would we like to scrape?
- Do some web API fetching thing? Maybe Google Calendar? (Though maybe we want to access Google Calendar in a later exercise?)
Other protocols
- XML-RPC, JSON
Exercise
- We need an XML-RPC and JSON protocol we care about. Not sure what those will be. (tagger?)
WSGI and Paste.
I got my presentation/tutorial, but this will be a little more hands-on. The examples will come from that, but we'll be implementing the code as exercises.
The Spec
- Describe the purpose of WSGI, historically and currently
- Describe the spec in detail
- Show a simple application, with doctest
Exercise
- Implement the server side that runs the doctest. This may be a potentially longer exercise, as it covers most of the details of WSGI.
- Put paste.lint aka wsgiref.validate in to get WSGI spec validation that we'll keep track of later.
Fancier WSGI
- We'll start with some different kinds of dispatching strategies (at least PATH_INFO and regex-matches).
Exercise
- Then we'll implement those (should be fairly simple)
Annotating the request
- We'll look at how you can change the request environ on its way in
Exercise
- We'll do an authentication middleware
Intermediaries in WSGI
- We'll look at filtering middleware
Exercise
- We'll do a simple templating middleware (like Deliverance Lite)
Application Development
- Now that we know about WSGI, we should learn practical ways to actually write applications in WSGI (not just middleware)
- We'll be talking about Pylons
- I'll do a quick demo setting up a Pylons application. This will include using ZPT, maybe the server side of a web API
- I'll show some acceptance and unit tests
- We'll show interactive (localhost http) development.
Exercise
- We'll all write small applications. I need a good idea for an app.
Deployment
- We'll maybe look at topp.zwsgi
- And wsgi_intercept
Templating (i.e. TAL / TALES / METAL)
- Start with METAL; describe it
- Then do TALES (the expressions). Maybe stick mostly with "python:" to start, since that will be familiar. We'll circle around to the other parts.
- Talk about TAL, the expression language.
- Come back to TALES and / and ${}, etc.
- Maybe we can start covering this in the Pylons section, assuming we are doing templating there?
zc.buildout
- This is going to be a short presentation, where I talk about what I'm able to figure out about this. This may be complementary to subversion/deployment discussions.