def _extract_package(deps_dir, pkg_path):
if pkg_path.endswith('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>zf = None<EOL>zf = zipfile.ZipFile(pkg_path, '<STR_LIT:r>')<EOL>for zi in zf.infolist():<EOL><INDENT>if not zi.filename.startswith('<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>data = _extract_info(zf, zi)<EOL>if data is not None:<EOL><INDENT>dst_path = os.path.join(deps_dir, zi.filename[<NUM_LIT:8>:])<EOL>dst_dir = os.path.dirname(dst_path)<EOL>if not os.path.exists(dst_dir):<EOL><INDENT>os.makedirs(dst_dir)<EOL><DEDENT>with open(dst_path, '<STR_LIT:wb>') as f:<EOL><INDENT>f.write(data)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>if zf:<EOL><INDENT>zf.close()<EOL><DEDENT><DEDENT>return<EOL><DEDENT>if pkg_path.endswith('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>zf = None<EOL>zf = zipfile.ZipFile(pkg_path, '<STR_LIT:r>')<EOL>zf.extractall(deps_dir)<EOL><DEDENT>finally:<EOL><INDENT>if zf:<EOL><INDENT>zf.close()<EOL><DEDENT><DEDENT>return<EOL><DEDENT>try:<EOL><INDENT>ar = None<EOL>ar = _open_archive(pkg_path)<EOL>pkg_name = None<EOL>base_path = _archive_single_dir(ar) or '<STR_LIT>'<EOL>if len(base_path):<EOL><INDENT>if '<STR_LIT:->' in base_path:<EOL><INDENT>pkg_name, _ = base_path.split('<STR_LIT:->', <NUM_LIT:1>)<EOL><DEDENT>base_path += '<STR_LIT:/>'<EOL><DEDENT>base_pkg_path = None<EOL>if pkg_name is not None:<EOL><INDENT>base_pkg_path = base_path + pkg_name + '<STR_LIT:/>'<EOL><DEDENT>src_path = base_path + '<STR_LIT>'<EOL>members = []<EOL>for info in _list_archive_members(ar):<EOL><INDENT>fn = _info_name(info)<EOL>if base_pkg_path is not None and fn.startswith(base_pkg_path):<EOL><INDENT>dst_path = fn[len(base_pkg_path) - len(pkg_name) - <NUM_LIT:1>:]<EOL>members.append((info, dst_path))<EOL>continue<EOL><DEDENT>if fn.startswith(src_path):<EOL><INDENT>members.append((info, fn[len(src_path):]))<EOL>continue<EOL><DEDENT><DEDENT>for info, path in members:<EOL><INDENT>info_data = _extract_info(ar, info)<EOL>if info_data is not None:<EOL><INDENT>dst_path = os.path.join(deps_dir, path)<EOL>dst_dir = os.path.dirname(dst_path)<EOL>if not os.path.exists(dst_dir):<EOL><INDENT>os.makedirs(dst_dir)<EOL><DEDENT>with open(dst_path, '<STR_LIT:wb>') as f:<EOL><INDENT>f.write(info_data)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>if ar:<EOL><INDENT>ar.close()<EOL><DEDENT><DEDENT>
Extract a .whl, .zip, .tar.gz or .tar.bz2 into a package path to
use when running CI tasks

:param deps_dir:
    A unicode string of the directory the package should be extracted to

:param pkg_path:
    A unicode string of the path to the archive