'Set up the build environment.'

def load_env(self):

    if self.env:
        return
    if (not self.freshenv):
        try:
            self.info(bold('loading    pickled    environment...    '), nonl=True)
            self.env = BuildEnvironment.frompickle(self.config, path.join(self.doctreedir, ENV_PICKLE_FILENAME))
            self.info('done')
        except Exception as err:
            if ((type(err) is IOError) and (err.errno == 2)):
                self.info('not    found')
            else:
                self.info(('failed:    %s' % err))
            self.env = BuildEnvironment(self.srcdir, self.doctreedir, self.config)
            self.env.find_files(self.config)
    else:
        self.env = BuildEnvironment(self.srcdir, self.doctreedir, self.config)
        self.env.find_files(self.config)
    self.env.set_warnfunc(self.warn)
