'Initialize the environment for installing Python packages.  The class is called during the initial
download stage when installing packages, so the value of initial_download will generally be True.
However, the parameter value allows this class to also be used in the second stage of the installation,
although it may never be necessary.  If initial_download is True, the recipe steps will be filtered
and returned and the installation directory (i.e., dir) will be defined and returned.  If we\'re not
in the initial download stage, these actions will not occur, and None values will be returned for them.'

def execute_step(self, tool_dependency, package_name, actions, action_dict, filtered_actions, env_file_builder, install_environment, work_dir, current_dir=None, initial_download=False):

    dir = None
    if initial_download:
        filtered_actions = actions[1:]
    env_shell_file_paths = action_dict.get('env_shell_file_paths', None)
    if (env_shell_file_paths is None):
        log.debug('Missing    Python    environment,    make    sure    your    specified    Python    installation    exists.')
        if initial_download:
            return (tool_dependency, filtered_actions, dir)
        return (tool_dependency, None, None)
    else:
        install_environment.add_env_shell_file_paths(env_shell_file_paths)
    log.debug(('Handling    setup_python_environment    for    tool    dependency    %s    with    install_environment.env_shell_file_paths:\n%s' % (str(tool_dependency.name), str(install_environment.env_shell_file_paths))))
    dir = os.path.curdir
    current_dir = os.path.abspath(os.path.join(work_dir, dir))
    with lcd(current_dir):
        with settings(warn_only=True):
            python_package_tups = action_dict.get('python_package_tups', [])
            for python_package_tup_dict in python_package_tups:
                python_package_tup = python_package_tup_dict['package']
                (package, package_version) = python_package_tup
                package_path = os.path.join(install_environment.tool_shed_repository_install_dir, package)
                if os.path.isfile(package_path):
                    package_to_install = package_path
                elif (package.find('://') != (-1)):
                    url = package
                    package_name = url.split('/')[(-1)]
                    checksums = python_package_tup_dict.get('checksums', {})
                    self.url_download(work_dir, package_name, url, extract=False, checksums=checksums)
                    package_to_install = os.path.join(work_dir, package_name)
                else:
                    pass
                archive = CompressedFile(package_to_install)
                uncompressed_path = archive.extract(work_dir)
                cmd = ('PATH=$PYTHONHOME/bin:$PATH;    export    PATH;\n                                                                                                                mkdir    -p    $INSTALL_DIR/lib/python;\n                                                                                                                export    PYTHONPATH=$INSTALL_DIR/lib/python:$PYTHONPATH;\n                                                                                                                cd    %s;\n                                                                                                                python    setup.py    install    --install-lib    $INSTALL_DIR/lib/python    --install-scripts    $INSTALL_DIR/bin\n                                                                                                ' % uncompressed_path)
                cmd = install_environment.build_command(basic_util.evaluate_template(cmd, install_environment))
                return_code = install_environment.handle_command(tool_dependency=tool_dependency, cmd=cmd, return_output=False, job_name=package_name)
                if return_code:
                    if initial_download:
                        return (tool_dependency, filtered_actions, dir)
                    return (tool_dependency, None, None)
            env_file_builder.handle_action_shell_file_paths(action_dict)
            env_file_builder.append_line(name='PYTHONPATH', action='prepend_to', value=os.path.join(install_environment.install_dir, 'lib', 'python'))
            env_file_builder.append_line(name='PYTHONPATH', action='prepend_to', value=os.path.join(install_environment.install_dir))
            env_file_builder.append_line(name='PATH', action='prepend_to', value=os.path.join(install_environment.install_dir, 'bin'))
            return_code = env_file_builder.return_code
            if return_code:
                if initial_download:
                    return (tool_dependency, filtered_actions, dir)
                return (tool_dependency, None, None)
    if initial_download:
        return (tool_dependency, filtered_actions, dir)
    return (tool_dependency, None, None)
