Cleanup the top-level astropy namespace

Fixes #1207.

Removes things like os, sys from the top-level astropy namespace.  For the most part, this is done by putting things inside of a function and then calling that function so that we don't have to keep track of what needs to be deleted later.