Packages lambda data for deployment into a zip

def package(self):
        """Packages lambda data for deployment into a zip"""
        logger.info('Packaging lambda {}'.format(self.lambda_name))
        zfh = io.BytesIO()

        if os.path.exists(os.path.join(self.lambda_dir, '.env')):
            logger.warn(
                'A .env file exists in your Lambda directory - be '
                'careful that it does not contain any secrets you '
                'don\'t want uploaded to AWS!'
            )

        with zipfile.ZipFile(zfh, 'w') as zf:
            self.add_directory_to_zip(self.lambda_dir, zf)

            # Construct a .env file in the archive with our
            # needed envrionment variables.
            envinfo = zipfile.ZipInfo('.env')
            envinfo.external_attr = 0644 << 16L
            zf.writestr(
                envinfo,
                '\n'.join(
                    '{} = {}'.format(key, yaep.env(key))
                    for key in self.env_vars
                )
            )

            if 'requirements.txt' in os.listdir(self.lambda_dir):
                with TemporaryDirectory() as temp_dir:
                    pip_args = [
                        'install',
                        '-r',
                        os.path.join(self.lambda_dir, 'requirements.txt'),
                        '-t',
                        temp_dir
                    ]

                    # Do pip install to temporary dir
                    if pip.main(pip_args) == 0:
                        self.add_directory_to_zip(temp_dir, zf)
                    else:
                        if sys.platform == 'darwin':
                            logger.error(
                                'A DistutilsOptionError about the prefix '
                                'can occur when you are on OS X and '
                                'installed Python via Homebrew.\nIf this '
                                'is you, please look at https://github.com'
                                '/Homebrew/brew/blob/master/share/doc/'
                                'homebrew/Homebrew-and-Python.md'
                                '#note-on-pip-install---user\n'
                                'If this is not you, please contact us '
                                ' for support.'
                            )
                        raise DependencyInstallationError(
                            'Failed to install dependencies of {}'.format(
                                self.lambda_name
                            )
                        )

        zfh.seek(0)

        return zfh