def get_stranger_info(self, *, user_id, no_cache=False):

return super().__getattr__('<STR_LIT>')(user_id=user_id, no_cache=no_cache)<EOL>


return super().__getattr__('<STR_LIT>')()<EOL>


def get_group_member_info(self, *, group_id, user_id, no_cache=False):

return super().__getattr__('<STR_LIT>')(group_id=group_id, user_id=user_id, no_cache=no_cache)<EOL>

获取群成员信息

------------

:param int group_id: 群号
:param int user_id: QQ 号（不可以是登录号）
:param bool no_cache: 是否不使用缓存（使用缓存可能更新不及时，但响应更快）
:return: { "group_id": (群号: int), "user_id": (QQ 号: int), "nickname": (昵称: str), "card": (群名片/备注: str), "sex": (性别: str in ['male', 'female', 'unknown']), "age": (年龄: int), "area": (地区: str), "join_time": (加群时间戳: int), "last_sent_time": (最后发言时间戳: int), "level": (成员等级: str), "role": (角色: str in ['owner', 'admin', 'member']), "unfriendly": (是否不良记录成员: bool), "title": (专属头衔: str), "title_expire_time": (专属头衔过期时间戳: int), "card_changeable": (是否允许修改群名片: bool) }
:rtype: dict[ str, int | str | bool ]

------------

========  ===================  ======================================
    响应数据
---------------------------------------------------------------------
数据类型  字段名               说明
========  ===================  ======================================
int       group_id             群号
int       user_id              QQ 号
str       nickname             昵称
str       card                 群名片/备注
str       sex                  性别，`male` 或 `female` 或 `unknown`
int       age                  年龄
str       area                 地区
int       join_time            加群时间戳
int       last_sent_time       最后发言时间戳
str       level                成员等级
str       role                 角色，`owner` 或 `admin` 或 `member`
bool      unfriendly           是否不良记录成员
str       title                专属头衔
int       title_expire_time    专属头衔过期时间戳
bool      card_changeable      是否允许修改群名片
========  ===================  ======================================


def get_group_member_list(self, *, group_id):

return super().__getattr__('<STR_LIT>')(group_id=group_id)<EOL>

获取群成员列表

------------

:param int group_id: 群号
:return: [{ "group_id": (群号: int), "user_id": (QQ 号: int), "nickname": (昵称: str), "card": (群名片/备注: str), "sex": (性别: str in ['male', 'female', 'unknown']), "age": (年龄: int), "area": (地区: str), "join_time": (加群时间戳: int), "last_sent_time": (最后发言时间戳: int), "level": (成员等级: str), "role": (角色: str in ['owner', 'admin', 'member']), "unfriendly": (是否不良记录成员: bool), "title": (专属头衔: str), "title_expire_time": (专属头衔过期时间戳: int), "card_changeable": (是否允许修改群名片: bool) }, ...]
:rtype: list[ dict[ str, int | str | bool ] ]

------------

响应数据以 **列表** 包装的字典的形式提供。`( List[ Dict[ ...] ] )`

========  ===================  ======================================
    响应数据
---------------------------------------------------------------------
数据类型  字段名               说明
========  ===================  ======================================
int       group_id             群号
int       user_id              QQ 号
str       nickname             昵称
str       card                 群名片/备注
str       sex                  性别，`male` 或 `female` 或 `unknown`
int       age                  年龄
str       area                 地区
int       join_time            加群时间戳
int       last_sent_time       最后发言时间戳
str       level                成员等级
str       role                 角色，`owner` 或 `admin` 或 `member`
bool      unfriendly           是否不良记录成员
str       title                专属头衔
int       title_expire_time    专属头衔过期时间戳
bool      card_changeable      是否允许修改群名片
========  ===================  ======================================

**备注:** 响应内容为包含字典的列表 *( List[ Dict[] ] )* ，每个元素的内容和 `get_group_member_info` 接口相同，但对于同一个群组的同一个成员，获取列表时和获取单独的成员信息时，某些字段可能有所不同，例如 `area`、`title` 等字段在获取列表时无法获得，具体应以单独的成员信息为准。


def get_record(self, *, file, out_format):

return super().__getattr__('<STR_LIT>')(file=file, out_format=out_format)<EOL>


获取插件运行状态

------------

:return: { "good": (正常运行: bool), "app_initialized": (插件已初始化: bool), "app_enabled": (插件已启用: bool), "online": (当前QQ在线: bool), "http_service_good": (HTTP服务正常运行: bool), "ws_service_good": (WebSocket服务正常运行: bool), "ws_reverse_service_good": (反向WebSocket服务正常运行: bool) }
:rtype: dict[ str, bool ]

------------

========  ========================  ====================================
响应数据
------------------------------------------------------------------------
数据类型  字段名                    说明
========  ========================  ====================================
bool      good                      插件状态符合预期，意味着插件已初始化，需要启动的服务都在正常运行，且 QQ 在线
bool      app_initialized           插件已初始化
bool      app_enabled               插件已启用
bool      online                    当前 QQ 在线
bool      http_service_good         `use_http` 配置项为 `yes` 时有此字段，表示 HTTP 服务正常运行
bool      ws_service_good           `use_ws` 配置项为 `yes` 时有此字段，表示 WebSocket 服务正常运行
bool      ws_reverse_service_good   `use_ws_reverse` 配置项为 `yes` 时有此字段，表示反向 WebSocket 服务正常运行
========  ========================  ====================================


获取酷 Q 及 HTTP API 插件的版本信息

------------

:return: { "coolq_directory": (酷Q根目录路径: str), "coolq_edition": (酷Q版本: str in ['air', 'pro']), "plugin_version": (API插件版本: str), "plugin_build_number": (API插件build号: int), "plugin_build_configuration": (API插件编译配置: str in ['debug', 'release']) }
:rtype: dict[ str, int | str ]

------------

========  ==========================  ===============================
响应数据
---------------------------------------------------------------------
数据类型  字段名                      说明
========  ==========================  ===============================
str       coolq_directory             酷 Q 根目录路径
str       coolq_edition               酷 Q 版本，`air` 或 `pro`
str       plugin_version              HTTP API 插件版本，例如 2.1.3
int       plugin_build_number         HTTP API 插件 build 号
str       plugin_build_configuration  HTTP API 插件编译配置，`debug` 或 `release`
========  ==========================  ===============================


重启酷 Q，并以当前登录号自动登录（需勾选快速登录）

------------

:return: None
:rtype: None


重启 HTTP API 插件

------------

:return: None
:rtype: None

------------

由于重启插件同时需要重启 API 服务，这意味着当前的 API 请求会被中断，因此这个接口会延迟 2 秒重启插件，接口返回的 status 是 async。

**在Python SDK中返回 None 。**


return super().__getattr__('<STR_LIT>')(data_dir=data_dir)<EOL>

清理数据目录

------------

:param str data_dir: 收到清理的目录名，支持 `image`、`record`、`show`、`bface`
:return: None
:rtype: None

------------

用于清理积攒了太多旧文件的数据目录，如 `image`。

HTTP API v3.3.4 新增


def clean_data_dir_async(self, *, data_dir):

清理数据目录 (异步版本)

------------

:param str data_dir: 收到清理的目录名，支持 `image`、`record`、`show`、`bface`
:return: None
:rtype: None

------------

用于清理积攒了太多旧文件的数据目录，如 `image`。

HTTP API v3.3.4 新增


def send(self, context, message, **kwargs):

context = context.copy()<EOL>context['<STR_LIT:message>'] = message<EOL>context.update(kwargs)<EOL>if '<STR_LIT>' not in context:<EOL><INDENT>if '<STR_LIT>' in context:<EOL><INDENT>context['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>elif '<STR_LIT>' in context:<EOL><INDENT>context['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>elif '<STR_LIT>' in context:<EOL><INDENT>context['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT><DEDENT>return super().__getattr__('<STR_LIT>')(**context)<EOL>

便捷回复。会根据传入的context自动判断回复对象
------------
:param dict context: 事件收到的content
:return: None
:rtype: None
------------


func.__doc__ = doc<EOL>


__import__(name)<EOL>return sys.modules[name]<EOL>

Import module, returning the module after the last dot.


setattr(_MovedItems, move.name, move)<EOL>


try:<EOL><INDENT>delattr(_MovedItems, name)<EOL><DEDENT>except AttributeError:<EOL><INDENT>try:<EOL><INDENT>del moves.__dict__[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise AttributeError("<STR_LIT>" % (name,))<EOL><DEDENT><DEDENT>


return iter(getattr(d, _iterkeys)(**kw))<EOL>

Return an iterator over the keys of a dictionary.


return iter(getattr(d, _itervalues)(**kw))<EOL>

Return an iterator over the values of a dictionary.


return iter(getattr(d, _iteritems)(**kw))<EOL>

Return an iterator over the (key, value) pairs of a dictionary.


return iter(getattr(d, _iterlists)(**kw))<EOL>

Return an iterator over the (key, [values]) pairs of a dictionary.


return meta("<STR_LIT>", bases, {})<EOL>


def wrapper(cls):<EOL><INDENT>orig_vars = cls.__dict__.copy()<EOL>orig_vars.pop('<STR_LIT>', None)<EOL>orig_vars.pop('<STR_LIT>', None)<EOL>for slots_var in orig_vars.get('<STR_LIT>', ()):<EOL><INDENT>orig_vars.pop(slots_var)<EOL><DEDENT>return metaclass(cls.__name__, cls.__bases__, orig_vars)<EOL><DEDENT>return wrapper<EOL>

Class decorator for creating a class with a metaclass.


ALLOWED_SCHEMES = '''<STR_LIT>'''.split()<EOL>settings_overrides = {<EOL>"<STR_LIT>": <NUM_LIT:0>,  <EOL>"<STR_LIT>": <NUM_LIT:0>,  <EOL>"<STR_LIT>": <NUM_LIT:2>,  <EOL>"<STR_LIT>": <NUM_LIT:5>,  <EOL>}<EOL>old_stderr = sys.stderr<EOL>sys.stderr = s = io.StringIO()<EOL>parts = None<EOL>try:<EOL><INDENT>document = publish_doctree(source=source,<EOL>settings_overrides=settings_overrides)<EOL>for node in document.traverse():<EOL><INDENT>if node.tagname == '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>if node.hasattr('<STR_LIT>'):<EOL><INDENT>uri = node['<STR_LIT>']<EOL><DEDENT>elif node.hasattr('<STR_LIT>'):<EOL><INDENT>uri = node['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT>o = urllib.parse.urlparse(uri)<EOL>if o.scheme not in ALLOWED_SCHEMES:<EOL><INDENT>raise TransformError('<STR_LIT>')<EOL><DEDENT><DEDENT>reader = readers.doctree.Reader(parser_name='<STR_LIT:null>')<EOL>pub = Publisher(reader, source=io.DocTreeInput(document),<EOL>destination_class=io.StringOutput)<EOL>pub.set_writer('<STR_LIT:html>')<EOL>pub.process_programmatic_settings(None, settings_overrides, None)<EOL>pub.set_destination(None, None)<EOL>pub.publish()<EOL>parts = pub.writer.parts<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>sys.stderr = old_stderr<EOL>if parts is None or len(s.getvalue()) > <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>return parts['<STR_LIT:body>']<EOL><DEDENT>

Copied (and slightly adapted) from pypi.description_tools


try:<EOL><INDENT>ownerUid = os.stat('<STR_LIT>' + str(pid)).st_uid<EOL><DEDENT>except:<EOL><INDENT>return None<EOL><DEDENT>try:<EOL><INDENT>ownerName = pwd.getpwuid(ownerUid).pw_name<EOL><DEDENT>except:<EOL><INDENT>ownerName = None<EOL><DEDENT>return {<EOL>'<STR_LIT>' : ownerUid,<EOL>'<STR_LIT:name>' : ownerName<EOL>}<EOL>

getProcessOwner - Get the process owner of a pid

@param pid <int> - process id

@return - None if process not found or can't be determined. Otherwise, a dict:
    {
        uid  - Owner UID
        name - Owner name, or None if one cannot be determined
    }


ownerInfo = getProcessOwner(pid)<EOL>if ownerInfo:<EOL><INDENT>if ownerInfo['<STR_LIT:name>']:<EOL><INDENT>owner = ownerInfo['<STR_LIT:name>']<EOL><DEDENT>else:<EOL><INDENT>owner = str(ownerInfo['<STR_LIT>'])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>owner = '<STR_LIT>'<EOL><DEDENT>return owner<EOL>

getProcessOwner - Get Process owner of a pid as a string instead of components (#getProcessOwner)

@return - Returns username if it can be determined, otherwise uid, otherwise "unknown"


try:<EOL><INDENT>with open('<STR_LIT>' %(int(pid),), '<STR_LIT:r>') as f:<EOL><INDENT>cmdline = f.read()<EOL><DEDENT>return cmdline.replace('<STR_LIT:\x00>', '<STR_LIT:U+0020>')<EOL><DEDENT>except:<EOL><INDENT>return None<EOL><DEDENT>

getProcessCommandLineStr - Gets a the commandline (program + arguments) of a given pid

@param pid <int> - Process ID

@return - None if process not found or can't be determined. Otherwise a string of commandline.

@note Caution, args may have spaces in them, and you cannot surmise from this method. If you care (like trying to replay a command), use getProcessCommandLineList instead


try:<EOL><INDENT>with open('<STR_LIT>' %(int(pid),), '<STR_LIT:r>') as f:<EOL><INDENT>cmdline = f.read()<EOL><DEDENT>return cmdline.split('<STR_LIT:\x00>')<EOL><DEDENT>except:<EOL><INDENT>return None<EOL><DEDENT>

getProcessCommandLineList - Gets the commandline (program + argumentS) of a given pid as a list.

@param pid <int> - Process ID

@return - None if process not found or can't be determined. Otherwise a list representing argv. First argument is process name, remainder are arguments.

@note - Use this if you care about whether a process had a space in the commands


try:<EOL><INDENT>cwd = os.readlink('<STR_LIT>' %(int(pid), ))<EOL>return cwd<EOL><DEDENT>except:<EOL><INDENT>return None<EOL><DEDENT>

getProcessCwd - Gets the cwd (current working directory) of a given pid

@param pid <int> - Process ID

@return <str/None> - None if process not found or can't be determined. Otherwise, a string of the CWD


return [int(x) for x in os.listdir('<STR_LIT>') if x.isdigit()]<EOL>

getAllRunningPids - Gets list of all pids that are running on a given system

@return <list<int>> - A list of pids (process IDs).


def scanProcessForCwd(pid, searchPortion, isExactMatch=False):

try:   <EOL><INDENT>try:<EOL><INDENT>pid = int(pid)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>sys.stderr.write('<STR_LIT>' %(str(type(pid)),))<EOL>raise e<EOL><DEDENT>cwd = getProcessCwd(pid)<EOL>if not cwd:<EOL><INDENT>return None<EOL><DEDENT>isMatch = False<EOL>if isExactMatch is True:<EOL><INDENT>if searchPortion == cwd:<EOL><INDENT>isMatch = True<EOL><DEDENT>else:<EOL><INDENT>if searchPortion.endswith('<STR_LIT:/>') and searchPortion[:-<NUM_LIT:1>] == cwd:<EOL><INDENT>isMatch = True<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if searchPortion in cwd:<EOL><INDENT>isMatch = True<EOL><DEDENT>else:<EOL><INDENT>if searchPortion.endswith('<STR_LIT:/>') and searchPortion[:-<NUM_LIT:1>] in cwd:<EOL><INDENT>isMatch = True<EOL><DEDENT><DEDENT><DEDENT>if not isMatch:<EOL><INDENT>return None<EOL><DEDENT>cmdline = getProcessCommandLineStr(pid)<EOL>owner   = getProcessOwnerStr(pid)<EOL>return {<EOL>'<STR_LIT>' : searchPortion,<EOL>'<STR_LIT>'           : pid,<EOL>'<STR_LIT>'         : owner,<EOL>'<STR_LIT>'       : cmdline,<EOL>'<STR_LIT>'           : cwd,<EOL>}<EOL><DEDENT>except OSError:<EOL><INDENT>return None<EOL><DEDENT>except IOError:<EOL><INDENT>return None<EOL><DEDENT>except FileNotFoundError:<EOL><INDENT>return None<EOL><DEDENT>except PermissionError:<EOL><INDENT>return None<EOL><DEDENT>

scanProcessForCwd - Searches a given pid's cwd for a given pattern

    @param pid <int> - A running process ID on this system
    @param searchPortion <str> - Any portion of directory to search
    @param isExactMatch <bool> Default False - If match should be exact, otherwise a partial match is performed.

    @return <dict> - If result is found, the following dict is returned. If no match found on the given pid, or pid is not found running, None is returned.
        {
            'searchPortion' : The passed search pattern
            'pid'           : The passed pid (as an integer)
            'owner'         : String of process owner, or uid if no mapping can be found, or "unknown" if neither could be determined.
            'cmdline'       : Commandline string
            'cwd'           : The exact cwd of matched process
        }


pids = getAllRunningPids()<EOL>cwdResults = [scanProcessForCwd(pid, searchPortion, isExactMatch) for pid in pids]<EOL>ret = {}<EOL>for i in range(len(pids)):<EOL><INDENT>if cwdResults[i] is not None:<EOL><INDENT>ret[pids[i]] = cwdResults[i]<EOL><DEDENT><DEDENT>return ret<EOL>

scanAllProcessesForCwd - Scans all processes on the system for a given search pattern.

    @param searchPortion <str> - Any portion of directory to search
    @param isExactMatch <bool> Default False - If match should be exact, otherwise a partial match is performed.

@return - <dict> - A dictionary of pid -> cwdResults for each pid that matched the search pattern. For format of "cwdResults", @see scanProcessForCwd


def scanProcessForMapping(pid, searchPortion, isExactMatch=False, ignoreCase=False):

try:   <EOL><INDENT>try:<EOL><INDENT>pid = int(pid)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>sys.stderr.write('<STR_LIT>' %(str(type(pid)),))<EOL>raise e<EOL><DEDENT>with open('<STR_LIT>' %(pid,), '<STR_LIT:r>') as f:<EOL><INDENT>contents = f.read()<EOL><DEDENT>lines = contents.split('<STR_LIT:\n>')<EOL>matchedMappings = []<EOL>if isExactMatch is True:<EOL><INDENT>if ignoreCase is False:<EOL><INDENT>isMatch = lambda searchFor, searchIn : bool(searchFor == searchIn)<EOL><DEDENT>else:<EOL><INDENT>isMatch = lambda searchFor, searchIn : bool(searchFor.lower() == searchIn.lower())<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if ignoreCase is False:<EOL><INDENT>isMatch = lambda searchFor, searchIn : bool(searchFor in searchIn)<EOL><DEDENT>else:<EOL><INDENT>isMatch = lambda searchFor, searchIn : bool(searchFor.lower() in searchIn.lower())<EOL><DEDENT><DEDENT>for line in lines:<EOL><INDENT>portion = '<STR_LIT:U+0020>'.join(line.split('<STR_LIT:U+0020>')[<NUM_LIT:5>:]).lstrip()<EOL>if isMatch(searchPortion, portion):<EOL><INDENT>matchedMappings.append('<STR_LIT:\t>' + line)<EOL><DEDENT><DEDENT>if len(matchedMappings) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>cmdline = getProcessCommandLineStr(pid)<EOL>owner   = getProcessOwnerStr(pid)<EOL>return {<EOL>'<STR_LIT>' : searchPortion,<EOL>'<STR_LIT>'           : pid,<EOL>'<STR_LIT>'         : owner,<EOL>'<STR_LIT>'       : cmdline,<EOL>'<STR_LIT>' : matchedMappings,<EOL>}<EOL><DEDENT>except OSError:<EOL><INDENT>return None<EOL><DEDENT>except IOError:<EOL><INDENT>return None<EOL><DEDENT>except FileNotFoundError:<EOL><INDENT>return None<EOL><DEDENT>except PermissionError:<EOL><INDENT>return None<EOL><DEDENT>

scanProcessForMapping - Searches a given pid's mappings for a certain pattern.

    @param pid <int> - A running process ID on this system
    @param searchPortion <str> - A mapping for which to search, example: libc or python or libz.so.1. Give empty string to return all mappings.
    @param isExactMatch <bool> Default False - If match should be exact, otherwise a partial match is performed.
    @param ignoreCase <bool> Default False - If True, search will be performed case-insensitively

    @return <dict> - If result is found, the following dict is returned. If no match found on the given pid, or pid is not found running, None is returned.
        {
            'searchPortion' : The passed search pattern
            'pid'           : The passed pid (as an integer)
            'owner'         : String of process owner, or uid if no mapping can be found, or "unknown" if neither could be determined.
            'cmdline'       : Commandline string
            'matchedMappings' : All mappings likes that matched the given search pattern
        }


def scanAllProcessesForMapping(searchPortion, isExactMatch=False, ignoreCase=False):

pids = getAllRunningPids()<EOL>mappingResults = [scanProcessForMapping(pid, searchPortion, isExactMatch, ignoreCase) for pid in pids]<EOL>ret = {}<EOL>for i in range(len(pids)):<EOL><INDENT>if mappingResults[i] is not None:<EOL><INDENT>ret[pids[i]] = mappingResults[i]<EOL><DEDENT><DEDENT>return ret<EOL>

scanAllProcessesForMapping - Scans all processes on the system for a given search pattern.

    @param searchPortion <str> - A mapping for which to search, example: libc or python or libz.so.1. Give empty string to return all mappings.
    @param isExactMatch <bool> Default False - If match should be exact, otherwise a partial match is performed.
    @param ignoreCase <bool> Default False - If True, search will be performed case-insensitively

@return - <dict> - A dictionary of pid -> mappingResults for each pid that matched the search pattern. For format of "mappingResults", @see scanProcessForMapping


def scanProcessForOpenFile(pid, searchPortion, isExactMatch=True, ignoreCase=False):

try:<EOL><INDENT>try:<EOL><INDENT>pid = int(pid)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>sys.stderr.write('<STR_LIT>' %(str(type(pid)),))<EOL>raise e<EOL><DEDENT>prefixDir = "<STR_LIT>" % (pid,)<EOL>processFDs = os.listdir(prefixDir)<EOL>matchedFDs = []<EOL>matchedFilenames = []<EOL>if isExactMatch is True:<EOL><INDENT>if ignoreCase is False:<EOL><INDENT>isMatch = lambda searchFor, totalPath : bool(searchFor == totalPath)<EOL><DEDENT>else:<EOL><INDENT>isMatch = lambda searchFor, totalPath : bool(searchFor.lower() == totalPath.lower())<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if ignoreCase is False:<EOL><INDENT>isMatch = lambda searchFor, totalPath : bool(searchFor in totalPath)<EOL><DEDENT>else:<EOL><INDENT>isMatch = lambda searchFor, totalPath : bool(searchFor.lower() in totalPath.lower())<EOL><DEDENT><DEDENT>for fd in processFDs:<EOL><INDENT>fdPath = os.readlink(prefixDir + '<STR_LIT:/>' + fd)<EOL>if isMatch(searchPortion, fdPath):<EOL><INDENT>matchedFDs.append(fd)<EOL>matchedFilenames.append(fdPath)<EOL><DEDENT><DEDENT>if len(matchedFDs) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>cmdline = getProcessCommandLineStr(pid)<EOL>owner   = getProcessOwnerStr(pid)<EOL>return {<EOL>'<STR_LIT>' : searchPortion,<EOL>'<STR_LIT>'           : pid,<EOL>'<STR_LIT>'         : owner,<EOL>'<STR_LIT>'       : cmdline,<EOL>'<STR_LIT>'           : matchedFDs,<EOL>'<STR_LIT>'     : matchedFilenames, <EOL>}<EOL><DEDENT>except OSError:<EOL><INDENT>return None<EOL><DEDENT>except IOError:<EOL><INDENT>return None<EOL><DEDENT>except FileNotFoundError:<EOL><INDENT>return None<EOL><DEDENT>except PermissionError:<EOL><INDENT>return None<EOL><DEDENT>

scanProcessForOpenFile - Scans open FDs for a given pid to see if any are the provided searchPortion

    @param searchPortion <str> - Filename to check
    @param isExactMatch <bool> Default True - If match should be exact, otherwise a partial match is performed.
    @param ignoreCase <bool> Default False - If True, search will be performed case-insensitively

@return -  If result is found, the following dict is returned. If no match found on the given pid, or the pid is not found running, None is returned.
        {
            'searchPortion' : The search portion provided
            'pid'           : The passed pid (as an integer)
            'owner'         : String of process owner, or "unknown" if one could not be determined
            'cmdline'       : Commandline string
            'fds'           : List of file descriptors assigned to this file (could be mapped several times)
            'filenames'     : List of the filenames matched
        }


def scanAllProcessesForOpenFile(searchPortion, isExactMatch=True, ignoreCase=False):

pids = getAllRunningPids()<EOL>mappingResults = [scanProcessForOpenFile(pid, searchPortion, isExactMatch, ignoreCase) for pid in pids]<EOL>ret = {}<EOL>for i in range(len(pids)):<EOL><INDENT>if mappingResults[i] is not None:<EOL><INDENT>ret[pids[i]] = mappingResults[i]<EOL><DEDENT><DEDENT>return ret<EOL>

scanAllProcessessForOpenFile - Scans all processes on the system for a given filename

    @param searchPortion <str> - Filename to check
    @param isExactMatch <bool> Default True - If match should be exact, otherwise a partial match is performed.
    @param ignoreCase <bool> Default False - If True, search will be performed case-insensitively

@return - <dict> - A dictionary of pid -> mappingResults for each pid that matched the search pattern. For format of "mappingResults", @see scanProcessForOpenFile


global database<EOL>if database is None:<EOL><INDENT>database = Database()<EOL><DEDENT>return database<EOL>

make sure you have only one instance of Database

    :return: DataBase's instance


try:<EOL><INDENT>assert type(urls) in VALIDATE_URLS<EOL><DEDENT>except AssertionError:<EOL><INDENT>error_message('<STR_LIT>')<EOL><DEDENT>if len(urls):<EOL><INDENT>for i in range(self.main_thread_number):<EOL><INDENT>self.append_main_thread()<EOL><DEDENT>for url in urls:<EOL><INDENT>self.main_queue.put(url)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>error_message('<STR_LIT>')<EOL><DEDENT>

:param urls: url you want to fetch
:return: None


thread = MainThread(main_queue=self.main_queue,<EOL>main_spider=self.main_spider,<EOL>branch_spider=self.branch_spider)<EOL>thread.daemon = True<EOL>thread.start()<EOL>

create & start main thread

        :return: None


config = config_creator()<EOL>debug = config.debug<EOL>branch_thread_sleep = config.branch_thread_sleep<EOL>while <NUM_LIT:1>:<EOL><INDENT>url = self.branch_queue.get()<EOL>if debug:<EOL><INDENT>print('<STR_LIT>'.format(url))<EOL><DEDENT>branch_spider = self.branch_spider(url)<EOL>sleep(random.randrange(*branch_thread_sleep))<EOL>branch_spider.request_page()<EOL>if debug:<EOL><INDENT>print('<STR_LIT>'.format(url))<EOL><DEDENT>self.branch_queue.task_done()<EOL><DEDENT>

run your main spider here
        as for branch spider result data, you can return everything or do whatever with it
        in your own code

        :return: None


global existed_urls_list<EOL>config = config_creator()<EOL>debug = config.debug<EOL>main_thread_sleep = config.main_thread_sleep<EOL>branch_thread_num = config.branch_thread_num<EOL>while <NUM_LIT:1>:<EOL><INDENT>url = self.main_queue.get()<EOL>if debug:<EOL><INDENT>print('<STR_LIT>'.format(url))<EOL><DEDENT>main_spider = self.main_spider(url)<EOL>sleep(random.randrange(*main_thread_sleep))<EOL>links = main_spider.request_urls()<EOL>try:<EOL><INDENT>assert type(links) in VALIDATE_URLS<EOL><DEDENT>except AssertionError:<EOL><INDENT>error_message('<STR_LIT>')<EOL>links = list()<EOL><DEDENT>branch_queue = queue.Queue(branch_thread_num)<EOL>for i in range(branch_thread_num):<EOL><INDENT>branch_thread = BranchThread(branch_queue=branch_queue,<EOL>branch_spider=self.branch_spider)<EOL>branch_thread.daemon = True<EOL>branch_thread.start()<EOL><DEDENT>for link in links:<EOL><INDENT>if link not in existed_urls_list:<EOL><INDENT>existed_urls_list.append(link)<EOL>branch_queue.put(link)<EOL><DEDENT><DEDENT>branch_queue.join()<EOL>if debug:<EOL><INDENT>print('<STR_LIT>'.format(url))<EOL><DEDENT>self.main_queue.task_done()<EOL><DEDENT>

run your main spider here, and get a list/tuple of url as result
        then make the instance of branch thread

        :return: None


return color + text + Fore.RESET<EOL>

make target text colorful

    :param text: target text
    :param color
    :return: colored text


print(colorful_text(message, Fore.RED))<EOL>

print the error message in red color

    :param message: error message
    :return: None


user = self.request.user<EOL>user.is_authenticated.return_value = is_authenticated<EOL>user.is_authenticated.__bool__ = lambda self: is_authenticated<EOL>user.is_authenticated.__nonzero__ = lambda self: is_authenticated<EOL>

Set whether user is authenticated in the request.


return getattr(func, '<STR_LIT>', False)<EOL>

Returns whether a view is public or not (ie/ has the STRONGHOLD_IS_PUBLIC
attribute set)


setattr(func, '<STR_LIT>', True)<EOL>

Set the STRONGHOLD_IS_PUBLIC attribute on a given function to True


try:<EOL><INDENT>return user.is_authenticated()<EOL><DEDENT>except TypeError:<EOL><INDENT>return user.is_authenticated<EOL><DEDENT>


orig_func = function<EOL>while isinstance(orig_func, partial):<EOL><INDENT>orig_func = orig_func.func<EOL><DEDENT>set_view_func_public(orig_func)<EOL>return function<EOL>

Decorator for public views that do not require authentication
Sets an attribute in the fuction STRONGHOLD_IS_PUBLIC to True


sanitizer = self.sanitizer<EOL>if not sanitizer:<EOL><INDENT>default_sanitizer = settings.CONFIG.get(self.SANITIZER_KEY)<EOL>field_settings = getattr(self, '<STR_LIT>', None)<EOL>if isinstance(field_settings, six.string_types):<EOL><INDENT>profiles = settings.CONFIG.get(self.SANITIZER_PROFILES_KEY, {})<EOL>sanitizer = profiles.get(field_settings, default_sanitizer)<EOL><DEDENT>else:<EOL><INDENT>sanitizer = default_sanitizer<EOL><DEDENT><DEDENT>if isinstance(sanitizer, six.string_types):<EOL><INDENT>sanitizer = import_string(sanitizer)<EOL><DEDENT>return sanitizer or noop<EOL>

Get the field sanitizer.

The priority is the first defined in the following order:
- A sanitizer provided to the widget.
- Profile (field settings) specific sanitizer, if defined in settings.
- Global sanitizer defined in settings.
- Simple no-op sanitizer which just returns the provided value.


field_settings = None<EOL>if self.field_settings:<EOL><INDENT>if isinstance(self.field_settings, six.string_types):<EOL><INDENT>profiles = settings.CONFIG.get(self.PROFILE_KEY, {})<EOL>field_settings = profiles.get(self.field_settings)<EOL><DEDENT>else:<EOL><INDENT>field_settings = self.field_settings<EOL><DEDENT><DEDENT>return field_settings<EOL>

Get the field settings, if the configured setting is a string try
to get a 'profile' from the global config.


def value_from_datadict(self, *args, **kwargs):

value = super(RichTextWidget, self).value_from_datadict(<EOL>*args, **kwargs)<EOL>if value is not None:<EOL><INDENT>value = self.get_sanitizer()(value)<EOL><DEDENT>return value<EOL>

Pass the submitted value through the sanitizer before returning it.


value = self.to_python(value)<EOL>if value is not None:<EOL><INDENT>value = self.get_sanitizer()(value)<EOL><DEDENT>self.validate(value, model_instance)<EOL>self.run_validators(value)<EOL>return value<EOL>

Convert the value's type, sanitize it, and run validation. Validation
errors from to_python() and validate() are propagated. Return the
correct value if no error is raised.


mold = mold or "<STR_LIT>"  <EOL>tmpdir = os.path.join(tempfile.gettempdir(), "<STR_LIT>")<EOL>if os.path.isdir('<STR_LIT>'):<EOL><INDENT>pass<EOL><DEDENT>if os.path.isdir(tmpdir):<EOL><INDENT>shutil.rmtree(tmpdir)<EOL><DEDENT>if os.path.exists(mold):<EOL><INDENT>shutil.copytree(mold, tmpdir, ignore=shutil.ignore_patterns(<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>))<EOL><DEDENT>else:<EOL><INDENT>ctx.run("<STR_LIT>".format(mold, tmpdir))<EOL><DEDENT>shutil.copy2("<STR_LIT>", tmpdir)<EOL>with pushd('<STR_LIT:..>'):<EOL><INDENT>ctx.run("<STR_LIT>".format(tmpdir))<EOL><DEDENT>if os.path.exists('<STR_LIT>'):<EOL><INDENT>ctx.run("<STR_LIT>")<EOL><DEDENT>

Refresh the project from the original cookiecutter template.


@task(help={<EOL>'<STR_LIT>': "<STR_LIT>",<EOL>})  <EOL>def ci(ctx):

opts = ['<STR_LIT>']<EOL>if os.environ.get('<STR_LIT>', '<STR_LIT>').lower() == '<STR_LIT:true>':<EOL><INDENT>opts += ['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>opts += ['<STR_LIT>']<EOL><DEDENT>ctx.run("<STR_LIT>".format('<STR_LIT:U+0020>'.join(opts)))<EOL>


lexer = MarkdownLexer()<EOL>for alias in lexer.aliases:<EOL><INDENT>app.add_lexer(alias, lexer)<EOL><DEDENT>return dict(version=__version__)<EOL>

Initializer for Sphinx extension API.

        See http://www.sphinx-doc.org/en/stable/extdev/index.html#dev-extensions.


return os.path.join(*((project_root,) + args))<EOL>


<EOL>expected_keys = ('<STR_LIT:url>', '<STR_LIT:version>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>metadata = {}<EOL>with io.open(srcfile('<STR_LIT:src>', package_name, '<STR_LIT>'), encoding='<STR_LIT:utf-8>') as handle:<EOL><INDENT>pkg_init = handle.read()<EOL>metadata['<STR_LIT>'] = re.search(r'<STR_LIT>', pkg_init, re.DOTALL|re.MULTILINE).group(<NUM_LIT:1>)<EOL>for line in pkg_init.splitlines():<EOL><INDENT>match = re.match(r"""<STR_LIT>""".format('<STR_LIT:|>'.join(expected_keys)), line)<EOL>if match:<EOL><INDENT>metadata[match.group(<NUM_LIT:1>)] = match.group(<NUM_LIT:3>)<EOL><DEDENT><DEDENT><DEDENT>if not all(i in metadata for i in expected_keys):<EOL><INDENT>raise RuntimeError("<STR_LIT>"<EOL>.format(name, '<STR_LIT:U+002CU+0020>'.join(sorted(set(expected_keys) - set(metadata.keys()))),))<EOL><DEDENT>text = metadata['<STR_LIT>'].strip()<EOL>if text:<EOL><INDENT>metadata['<STR_LIT:description>'], text = text.split('<STR_LIT:.>', <NUM_LIT:1>)<EOL>metadata['<STR_LIT:description>'] = '<STR_LIT:U+0020>'.join(metadata['<STR_LIT:description>'].split()).strip() + '<STR_LIT:.>' <EOL>metadata['<STR_LIT>'] = textwrap.dedent(text).strip()<EOL><DEDENT>metadata['<STR_LIT>'] = metadata['<STR_LIT>'].replace('<STR_LIT:U+002C>', '<STR_LIT:U+0020>').strip().split()<EOL>requirements_files = dict(<EOL>install = '<STR_LIT>',<EOL>setup = '<STR_LIT>',<EOL>test = '<STR_LIT>',<EOL>)<EOL>requires = {}<EOL>for key, filename in requirements_files.items():<EOL><INDENT>requires[key] = []<EOL>if os.path.exists(srcfile(filename)):<EOL><INDENT>with io.open(srcfile(filename), encoding='<STR_LIT:utf-8>') as handle:<EOL><INDENT>for line in handle:<EOL><INDENT>line = line.strip()<EOL>if line and not line.startswith('<STR_LIT:#>'):<EOL><INDENT>if any(line.startswith(i) for i in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>line = line.split('<STR_LIT>')[<NUM_LIT:1>]<EOL><DEDENT>requires[key].append(line)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if not any('<STR_LIT>' == re.split('<STR_LIT>', i.lower())[<NUM_LIT:0>] for i in requires['<STR_LIT:test>']):<EOL><INDENT>requires['<STR_LIT:test>'].append('<STR_LIT>') <EOL><DEDENT>console_scripts = []<EOL>for path, dirs, files in os.walk(srcfile('<STR_LIT:src>', package_name)):<EOL><INDENT>dirs = [i for i in dirs if not i.startswith('<STR_LIT:.>')]<EOL>if '<STR_LIT>' in files:<EOL><INDENT>path = path[len(srcfile('<STR_LIT:src>') + os.sep):]<EOL>appname = path.split(os.sep)[-<NUM_LIT:1>]<EOL>with io.open(srcfile('<STR_LIT:src>', path, '<STR_LIT>'), encoding='<STR_LIT:utf-8>') as handle:<EOL><INDENT>for line in handle.readlines():<EOL><INDENT>match = re.match(r"""<STR_LIT>""", line)<EOL>if match:<EOL><INDENT>appname = match.group(<NUM_LIT:2>)<EOL><DEDENT><DEDENT><DEDENT>console_scripts.append('<STR_LIT>'.format(appname, path.replace(os.sep, '<STR_LIT:.>')))<EOL><DEDENT><DEDENT>candidate_files = [<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>]<EOL>data_files = defaultdict(list)<EOL>for filename in candidate_files:<EOL><INDENT>if os.path.exists(srcfile(filename)):<EOL><INDENT>data_files['<STR_LIT>'].append(filename)<EOL><DEDENT><DEDENT>classifiers = []<EOL>for classifiers_txt in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>classifiers_txt = srcfile(classifiers_txt)<EOL>if os.path.exists(classifiers_txt):<EOL><INDENT>with io.open(classifiers_txt, encoding='<STR_LIT:utf-8>') as handle:<EOL><INDENT>classifiers = [i.strip() for i in handle if i.strip() and not i.startswith('<STR_LIT:#>')]<EOL><DEDENT>break<EOL><DEDENT><DEDENT>entry_points.setdefault('<STR_LIT>', []).extend(console_scripts)<EOL>metadata.update(dict(<EOL>name = name,<EOL>package_dir = {'<STR_LIT>': '<STR_LIT:src>'},<EOL>packages = find_packages(srcfile('<STR_LIT:src>'), exclude=['<STR_LIT>']),<EOL>data_files = data_files.items(),<EOL>zip_safe = False,<EOL>include_package_data = True,<EOL>install_requires = requires['<STR_LIT>'],<EOL>setup_requires = requires['<STR_LIT>'],<EOL>tests_require =  requires['<STR_LIT:test>'],<EOL>classifiers = classifiers,<EOL>cmdclass = dict(<EOL>test = PyTest,<EOL>),<EOL>entry_points = entry_points,<EOL>))<EOL>return metadata<EOL>


if "<STR_LIT>" not in parsed_beta_allele.gene:<EOL><INDENT>raise ValueError("<STR_LIT>" % parsed_beta_allele)<EOL><DEDENT>return "<STR_LIT>" % (<EOL>parsed_beta_allele.gene,<EOL>parsed_beta_allele.allele_family,<EOL>parsed_beta_allele.allele_code)<EOL>

Assume that we're dealing with a human DRB allele
which NetMHCIIpan treats differently because there is
little population diversity in the DR-alpha gene


parsed_alleles = parse_classi_or_classii_allele_name(allele_name)<EOL>if len(parsed_alleles) == <NUM_LIT:1>:<EOL><INDENT>allele = parsed_alleles[<NUM_LIT:0>]<EOL>if allele.species == "<STR_LIT>":<EOL><INDENT>return "<STR_LIT>" % (<EOL>allele.species,<EOL>allele.gene,<EOL>allele.allele_code)<EOL><DEDENT>return self._prepare_drb_allele_name(allele)<EOL><DEDENT>else:<EOL><INDENT>alpha, beta = parsed_alleles<EOL>if "<STR_LIT>" in alpha.gene:<EOL><INDENT>return self._prepare_drb_allele_name(beta)<EOL><DEDENT>return "<STR_LIT>" % (<EOL>alpha.gene,<EOL>alpha.allele_family,<EOL>alpha.allele_code,<EOL>beta.gene,<EOL>beta.allele_family,<EOL>beta.allele_code)<EOL><DEDENT>

netMHCIIpan has some unique requirements for allele formats,
expecting the following forms:
 - DRB1_0101 (for non-alpha/beta pairs)
 - HLA-DQA10501-DQB10636 (for alpha and beta pairs)

Other than human class II alleles, the only other alleles that
netMHCIIpan accepts are the following mouse alleles:
 - H-2-IAb
 - H-2-IAd


<EOL>from mhcflurry import Class1AffinityPredictor<EOL>BasePredictor.__init__(<EOL>self,<EOL>alleles=alleles,<EOL>default_peptide_lengths=default_peptide_lengths,<EOL>min_peptide_length=<NUM_LIT:8>,<EOL>max_peptide_length=<NUM_LIT:15>)<EOL>if predictor:<EOL><INDENT>self.predictor = predictor<EOL><DEDENT>elif models_path:<EOL><INDENT>logging.info("<STR_LIT>" % models_path)<EOL>self.predictor = Class1AffinityPredictor.load(models_path)<EOL><DEDENT>else:<EOL><INDENT>self.predictor = Class1AffinityPredictor.load()<EOL><DEDENT>for allele in self.alleles:<EOL><INDENT>if allele not in self.predictor.supported_alleles:<EOL><INDENT>raise UnsupportedAllele(allele)<EOL><DEDENT><DEDENT>

Parameters
-----------
predictor : mhcflurry.Class1AffinityPredictor (optional)
    MHCflurry predictor to use

models_path : string
    Models dir to use if predictor argument is None


<EOL>from mhcflurry.encodable_sequences import EncodableSequences<EOL>binding_predictions = []<EOL>encodable_sequences = EncodableSequences.create(peptides)<EOL>for allele in self.alleles:<EOL><INDENT>predictions_df = self.predictor.predict_to_dataframe(<EOL>encodable_sequences, allele=allele)<EOL>for (_, row) in predictions_df.iterrows():<EOL><INDENT>binding_prediction = BindingPrediction(<EOL>allele=allele,<EOL>peptide=row.peptide,<EOL>affinity=row.prediction,<EOL>percentile_rank=(<EOL>row.prediction_percentile<EOL>if '<STR_LIT>' in row else nan),<EOL>prediction_method_name="<STR_LIT>"<EOL>)<EOL>binding_predictions.append(binding_prediction)<EOL><DEDENT><DEDENT>return BindingPredictionCollection(binding_predictions)<EOL>


<EOL>with open(os.devnull, '<STR_LIT:w>') as devnull:<EOL><INDENT>help_output = check_output([program_name, "<STR_LIT>"], stderr=devnull)<EOL><DEDENT>help_output_str = help_output.decode("<STR_LIT:ascii>", "<STR_LIT:ignore>")<EOL>substring_to_netmhc_class = {<EOL>"<STR_LIT>": NetMHC4,<EOL>"<STR_LIT>": NetMHC3,<EOL>}<EOL>successes = []<EOL>for substring, netmhc_class in substring_to_netmhc_class.items():<EOL><INDENT>if substring in help_output_str:<EOL><INDENT>successes.append(netmhc_class)<EOL><DEDENT><DEDENT>if len(successes) > <NUM_LIT:1>:<EOL><INDENT>raise SystemError("<STR_LIT>"<EOL>"<STR_LIT>" % program_name)<EOL><DEDENT>if len(successes) == <NUM_LIT:0>:<EOL><INDENT>raise SystemError("<STR_LIT>"<EOL>% program_name)<EOL><DEDENT>netmhc_class = successes[<NUM_LIT:0>]<EOL>return netmhc_class(<EOL>alleles=alleles,<EOL>default_peptide_lengths=default_peptide_lengths,<EOL>program_name=program_name)<EOL>

This function wraps NetMHC3 and NetMHC4 to automatically detect which class
to use. Currently based on running the '-h' command and looking for
discriminating substrings between the versions.


with tempfile.NamedTemporaryFile(suffix="<STR_LIT>", mode="<STR_LIT:w>") as input_fd:<EOL><INDENT>for (i, sequence) in enumerate(sequences):<EOL><INDENT>input_fd.write("<STR_LIT>" % i)<EOL>input_fd.write(sequence)<EOL>input_fd.write("<STR_LIT:\n>")<EOL><DEDENT>input_fd.flush()<EOL>try:<EOL><INDENT>output = subprocess.check_output(["<STR_LIT>", input_fd.name])<EOL><DEDENT>except subprocess.CalledProcessError as e:<EOL><INDENT>logging.error("<STR_LIT>" % (e, e.output))<EOL>raise<EOL><DEDENT><DEDENT>parsed = self.parse_netchop(output)<EOL>assert len(parsed) == len(sequences),"<STR_LIT>" % (<EOL>len(sequences), len(parsed))<EOL>assert [len(x) for x in parsed] == [len(x) for x in sequences]<EOL>return parsed<EOL>

Return netChop predictions for each position in each sequence.

Parameters
-----------
sequences : list of string
    Amino acid sequences to predict cleavage for

Returns
-----------
list of list of float

The i'th list corresponds to the i'th sequence. Each list gives
the cleavage probability for each position in the sequence.


line_iterator = iter(netchop_output.decode().split("<STR_LIT:\n>"))<EOL>scores = []<EOL>for line in line_iterator:<EOL><INDENT>if "<STR_LIT>" in line and '<STR_LIT>' in line and '<STR_LIT>' in line:<EOL><INDENT>scores.append([])<EOL>if "<STR_LIT>" not in next(line_iterator):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>line = next(line_iterator)<EOL>while '<STR_LIT>' not in line:<EOL><INDENT>score = float(line.split()[<NUM_LIT:3>])<EOL>scores[-<NUM_LIT:1>].append(score)<EOL>line = next(line_iterator)<EOL><DEDENT><DEDENT><DEDENT>return scores<EOL>


if group_by_length:<EOL><INDENT>peptide_lengths = {len(p) for p in peptides}<EOL>peptide_groups = {l: [] for l in peptide_lengths}<EOL>for p in peptides:<EOL><INDENT>peptide_groups[len(p)].append(p)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>peptide_groups = {"<STR_LIT>": peptides}<EOL><DEDENT>file_names = []<EOL>for key, group in peptide_groups.items():<EOL><INDENT>n_peptides = len(group)<EOL>if not max_peptides_per_file:<EOL><INDENT>max_peptides_per_file = n_peptides<EOL><DEDENT>input_file = None<EOL>for i, p in enumerate(group):<EOL><INDENT>if i % max_peptides_per_file == <NUM_LIT:0>:<EOL><INDENT>if input_file is not None:<EOL><INDENT>file_names.append(input_file.name)<EOL>input_file.close()<EOL><DEDENT>input_file = make_writable_tempfile(<EOL>prefix_number=i // max_peptides_per_file,<EOL>prefix_name=key,<EOL>suffix="<STR_LIT>")<EOL><DEDENT>input_file.write("<STR_LIT>" % p)<EOL><DEDENT>if input_file is not None:<EOL><INDENT>file_names.append(input_file.name)<EOL>input_file.close()<EOL><DEDENT><DEDENT>return file_names<EOL>

Creates one or more files containing one peptide per line,
returns names of files.


<EOL>if invalid_affinity(affinity) and np.isfinite(log_affinity):<EOL><INDENT>affinity = <NUM_LIT> ** (-log_affinity + <NUM_LIT:1>)<EOL><DEDENT>if invalid_affinity(affinity):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % (<EOL>affinity,<EOL>peptide,<EOL>allele))<EOL><DEDENT>if invalid_percentile_rank(percentile_rank):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % (<EOL>percentile_rank, peptide, allele))<EOL><DEDENT>self.source_sequence_name = source_sequence_name<EOL>self.offset = offset<EOL>self.allele = allele<EOL>self.peptide = peptide<EOL>self.affinity = affinity<EOL>self.percentile_rank = percentile_rank<EOL>self.prediction_method_name = prediction_method_name<EOL>

Parameters
----------
peptide : str
    Short amino acid sequence

allele : str
    HLA allele, e.g. HLA-A*02:01

affinity : float
    Predicted binding affinity

percentile_rank : float
    Percentile rank of the binding affinity for that allele

source_sequence_name : str
    Name of sequence from which peptide was extracted

offset : int
    Base0 starting position in source sequence that all epitopes were
    extracted from

log_affinity : float, optional
    NetMHC sometimes gives invalid IC50 values but we can still
    reconstruct the value from its (1.0 - log_50000(IC50)) score.

prediction_method_name : str, optional
    Name of predictor used to generate this prediction.


fields_dict = self.to_dict()<EOL>fields_dict.update(kwargs)<EOL>return BindingPrediction(**fields_dict)<EOL>

Returns new BindingPrediction with updated fields


return len(self.peptide)<EOL>

Length of peptide, preserved for backwards compatibility


return self.affinity<EOL>

Alias for affinity preserved for backwards compatibility


assert len(args) > <NUM_LIT:0><EOL>start_time = time.time()<EOL>process = AsyncProcess(args, **kwargs)<EOL>process.wait()<EOL>elapsed_time = time.time() - start_time<EOL>logger.info("<STR_LIT>", args[<NUM_LIT:0>], elapsed_time)<EOL>

Given a list whose first element is a command name, followed by arguments,
execute it and show timing info.


assert len(multiple_args_dict) > <NUM_LIT:0><EOL>assert all(len(args) > <NUM_LIT:0> for args in multiple_args_dict.values())<EOL>assert all(hasattr(f, '<STR_LIT:name>') for f in multiple_args_dict.keys())<EOL>if process_limit < <NUM_LIT:0>:<EOL><INDENT>logger.debug("<STR_LIT>" % cpu_count())<EOL>process_limit = cpu_count()<EOL><DEDENT>start_time = time.time()<EOL>processes = Queue(maxsize=process_limit)<EOL>def add_to_queue(process):<EOL><INDENT>process.start()<EOL>if print_commands:<EOL><INDENT>handler = logging.FileHandler(process.redirect_stdout_file.name)<EOL>handler.setLevel(logging.DEBUG)<EOL>logger.addHandler(handler)<EOL>logger.debug("<STR_LIT:U+0020>".join(process.args))<EOL>logger.removeHandler(handler)<EOL><DEDENT>processes.put(process)<EOL><DEDENT>for f, args in multiple_args_dict.items():<EOL><INDENT>p = AsyncProcess(<EOL>args,<EOL>redirect_stdout_file=f,<EOL>**kwargs)<EOL>if not processes.full():<EOL><INDENT>add_to_queue(p)<EOL><DEDENT>else:<EOL><INDENT>while processes.full():<EOL><INDENT>to_remove = []<EOL>for possibly_done in processes.queue:<EOL><INDENT>if possibly_done.poll() is not None:<EOL><INDENT>possibly_done.wait()<EOL>to_remove.append(possibly_done)<EOL><DEDENT><DEDENT>if to_remove:<EOL><INDENT>for process_to_remove in to_remove:<EOL><INDENT>processes.queue.remove(process_to_remove)<EOL><DEDENT>break<EOL><DEDENT>time.sleep(polling_freq)<EOL><DEDENT>add_to_queue(p)<EOL><DEDENT><DEDENT>while not processes.empty():<EOL><INDENT>processes.get().wait()<EOL><DEDENT>elapsed_time = time.time() - start_time<EOL>logger.info(<EOL>"<STR_LIT>",<EOL>len(multiple_args_dict),<EOL>elapsed_time)<EOL>

Run multiple shell commands in parallel, write each of their
stdout output to files associated with each command.

Parameters
----------
multiple_args_dict : dict
    A dictionary whose keys are files and values are args list.
    Run each args list as a subprocess and write stdout to the
    corresponding file.

print_commands : bool
    Print shell commands before running them.

process_limit : int
    Limit the number of concurrent processes to this number. 0
    if there is no limit, -1 to use max number of processors

polling_freq : int
    Number of seconds between checking for done processes, if
    we have a process limit


if self.process is None:<EOL><INDENT>self.start()<EOL><DEDENT>return self.process.poll()<EOL>

Peeks at whether the process is done or not, without
waiting for it. Leaves exception handling and such to wait().


if len(response) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>df = pd.read_csv(io.BytesIO(response), delim_whitespace=True, header=<NUM_LIT:0>)<EOL>assert type(df) == pd.DataFrame<EOL>df = pd.DataFrame(df)<EOL>if len(df) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % (response,))<EOL><DEDENT>required_columns = [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT:start>",<EOL>"<STR_LIT:end>",<EOL>]<EOL>for column in required_columns:<EOL><INDENT>if column not in df.columns:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (<EOL>column,<EOL>df.ix[<NUM_LIT:0>],<EOL>response))<EOL><DEDENT><DEDENT>df = df.rename(columns={<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>"})<EOL>return df<EOL>

Take the binding predictions returned by IEDB's web API
    and parse them into a DataFrame

    Expect response to look like:
    allele  seq_num start   end length  peptide ic50   percentile_rank
    HLA-A*01:01 1   2   10  9   LYNTVATLY   2145.70 3.7
    HLA-A*01:01 1   5   13  9   TVATLYCVH   2216.49 3.9
    HLA-A*01:01 1   7   15  9   ATLYCVHQR   2635.42 5.1
    HLA-A*01:01 1   4   12  9   NTVATLYCV   6829.04 20
    HLA-A*01:01 1   1   9   9   SLYNTVATL   8032.38 24
    HLA-A*01:01 1   8   16  9   TLYCVHQRI   8853.90 26
    HLA-A*01:01 1   3   11  9   YNTVATLYC   9865.62 29
    HLA-A*01:01 1   6   14  9   VATLYCVHQ   27575.71    58
    HLA-A*01:01 1   10  18  9   YCVHQRIDV   48929.64    74
    HLA-A*01:01 1   9   17  9   LYCVHQRID   50000.00    75


data = urlencode(request_values)<EOL>req = Request(url, data.encode("<STR_LIT:ascii>"))<EOL>response = urlopen(req).read()<EOL>return _parse_iedb_response(response)<EOL>

Call into IEDB's web API for MHC binding prediction using request dictionary
with fields:
    - "method"
    - "length"
    - "sequence_text"
    - "allele"

Parse the response into a DataFrame.


def predict_subsequences(self, sequence_dict, peptide_lengths=None):

sequence_dict = check_sequence_dictionary(sequence_dict)<EOL>peptide_lengths = self._check_peptide_lengths(peptide_lengths)<EOL>binding_predictions = []<EOL>expected_peptides = set([])<EOL>normalized_alleles = []<EOL>for key, amino_acid_sequence in sequence_dict.items():<EOL><INDENT>for l in peptide_lengths:<EOL><INDENT>for i in range(len(amino_acid_sequence) - l + <NUM_LIT:1>):<EOL><INDENT>expected_peptides.add(amino_acid_sequence[i:i + l])<EOL><DEDENT><DEDENT>self._check_peptide_inputs(expected_peptides)<EOL>for allele in self.alleles:<EOL><INDENT>allele = normalize_allele_name(allele, omit_dra1=True)<EOL>normalized_alleles.append(allele)<EOL>request = self._get_iedb_request_params(<EOL>amino_acid_sequence, allele)<EOL>logger.info(<EOL>"<STR_LIT>",<EOL>self.url,<EOL>request)<EOL>response_df = _query_iedb(request, self.url)<EOL>for _, row in response_df.iterrows():<EOL><INDENT>binding_predictions.append(<EOL>BindingPrediction(<EOL>source_sequence_name=key,<EOL>offset=row['<STR_LIT:start>'] - <NUM_LIT:1>,<EOL>allele=row['<STR_LIT>'],<EOL>peptide=row['<STR_LIT>'],<EOL>affinity=row['<STR_LIT>'],<EOL>percentile_rank=row['<STR_LIT>'],<EOL>prediction_method_name="<STR_LIT>" + self.prediction_method))<EOL><DEDENT><DEDENT><DEDENT>self._check_results(<EOL>binding_predictions,<EOL>alleles=normalized_alleles,<EOL>peptides=expected_peptides)<EOL>return BindingPredictionCollection(binding_predictions)<EOL>

Given a dictionary mapping unique keys to amino acid sequences,
        run MHC binding predictions on all candidate epitopes extracted from
        sequences and return a EpitopeCollection.

        Parameters
        ----------
        fasta_dictionary : dict or string
            Mapping of protein identifiers to protein amino acid sequences.
            If string then converted to dictionary.


require_string(program_name, "<STR_LIT>")<EOL>self.program_name = program_name<EOL>if supported_alleles_flag is not None:<EOL><INDENT>require_string(supported_alleles_flag, "<STR_LIT>")<EOL><DEDENT>self.supported_alleles_flag = supported_alleles_flag<EOL>require_string(input_file_flag, "<STR_LIT>")<EOL>self.input_file_flag = input_file_flag<EOL>require_string(length_flag, "<STR_LIT>")<EOL>self.length_flag = length_flag<EOL>require_string(allele_flag, "<STR_LIT>")<EOL>self.allele_flag = allele_flag<EOL>require_iterable_of(peptide_mode_flags, string_types)<EOL>self.peptide_mode_flags = peptide_mode_flags<EOL>if tempdir_flag is not None:<EOL><INDENT>require_string(tempdir_flag, "<STR_LIT>")<EOL><DEDENT>self.tempdir_flag = tempdir_flag<EOL>require_iterable_of(extra_flags, string_types)<EOL>self.extra_flags = extra_flags<EOL>require_integer(<EOL>max_peptides_per_file,<EOL>"<STR_LIT>")<EOL>self.max_peptides_per_file = max_peptides_per_file<EOL>require_integer(process_limit, "<STR_LIT>")<EOL>self.process_limit = process_limit<EOL>self.parse_output_fn = parse_output_fn<EOL>if isinstance(default_peptide_lengths, int):<EOL><INDENT>default_peptide_lengths = [default_peptide_lengths]<EOL><DEDENT>self.group_peptides_by_length = group_peptides_by_length<EOL>if self.supported_alleles_flag:<EOL><INDENT>valid_alleles = self._determine_supported_alleles(<EOL>self.program_name,<EOL>self.supported_alleles_flag)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>run_command([self.program_name])<EOL><DEDENT>except:<EOL><INDENT>raise SystemError("<STR_LIT>" % self.program_name)<EOL><DEDENT>valid_alleles = None<EOL><DEDENT>try:<EOL><INDENT>BasePredictor.__init__(<EOL>self,<EOL>alleles=alleles,<EOL>valid_alleles=valid_alleles,<EOL>default_peptide_lengths=default_peptide_lengths,<EOL>min_peptide_length=min_peptide_length,<EOL>max_peptide_length=max_peptide_length)<EOL><DEDENT>except UnsupportedAllele as e:<EOL><INDENT>if self.supported_alleles_flag:<EOL><INDENT>additional_message = (<EOL>"<STR_LIT>" % (<EOL>self.program_name,<EOL>self.supported_alleles_flag))<EOL><DEDENT>else:<EOL><INDENT>additional_message = "<STR_LIT>"<EOL><DEDENT>raise UnsupportedAllele(str(e) + additional_message)<EOL><DEDENT>

Parameters
----------
program_name : str
    Name of prediction program to run
    (e.g. "netMHCcons" or "netMHCIIpan")

alleles : list of str
    MHC alleles

supported_alleles_flag : str
    Flag to pass to the predictor to get a list of supported alleles
    (e.g. "-A", "-list", "-listMHC")

parse_output_fn : fn
    Takes the stdout string from the predictor and returns a collection
    of BindingPrediction objects

input_file_flag : str
    How to specify the input FASTA file of source sequences (e.g. "-f")

length_flag : str
    How to specify the desired predicted peptide length (e.g. "-length")

allele_flag : str
    How to specify the allele we want predictions for (e.g. "-a")

peptide_mode_flags : list of str
    How to switch from the default FASTA subsequences input mode to
    where peptides are explicitly given one per line of a text file.

tempdir_flag : str, optional
    How to specify the predictor's temporary directory (e.g. "-tdir")

extra_flags : list of str
    Extra flags to pass to the predictor

max_peptides_per_file : int, optional
    Maximum number of lines per file when predicting peptides directly.

process_limit : int, optional
    Maximum number of parallel processes to start
    (0 for no limit, -1 for use all available processors)

default_peptide_lengths : list of int, optional
    When making predictions across subsequences of protein sequences,
    what peptide lengths to predict for.

group_peptides_by_length : bool
    Run commandline predictor on groups of peptides of equal length

min_peptide_length : int
    Shortest peptide this predictor can handle

max_peptide_length : int
    Longest peptide this predictor can handle


try:<EOL><INDENT>supported_alleles_output = check_output([<EOL>command, supported_allele_flag<EOL>])<EOL>supported_alleles_str = supported_alleles_output.decode("<STR_LIT:ascii>", "<STR_LIT:ignore>")<EOL>assert len(supported_alleles_str) > <NUM_LIT:0>,'<STR_LIT>' % command<EOL>supported_alleles = set([])<EOL>for line in supported_alleles_str.split("<STR_LIT:\n>"):<EOL><INDENT>line = line.strip()<EOL>if not line.startswith('<STR_LIT:#>') and len(line) > <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>supported_alleles.add(normalize_allele_name(line))<EOL><DEDENT>except AlleleParseError as error:<EOL><INDENT>logger.info("<STR_LIT>", line, error)<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>if len(supported_alleles) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return supported_alleles<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.exception(e)<EOL>raise SystemError("<STR_LIT>" % (<EOL>command,<EOL>supported_allele_flag))<EOL><DEDENT>

Try asking the commandline predictor (e.g. netMHCpan)
which alleles it supports.


return allele_name.replace("<STR_LIT:*>", "<STR_LIT>")<EOL>

How does the predictor expect to see allele names?


<EOL>if isinstance(alleles, string_types):<EOL><INDENT>alleles = alleles.split('<STR_LIT:U+002C>')<EOL><DEDENT>self.alleles = self._check_hla_alleles(alleles, valid_alleles)<EOL>if isinstance(default_peptide_lengths, int):<EOL><INDENT>default_peptide_lengths = [default_peptide_lengths]<EOL><DEDENT>require_iterable_of(default_peptide_lengths, int)<EOL>self.default_peptide_lengths = default_peptide_lengths<EOL>self.min_peptide_length = min_peptide_length<EOL>self.max_peptide_length = max_peptide_length<EOL>self.allow_X_in_peptides = allow_X_in_peptides<EOL>self.allow_lowercase_in_peptides = allow_lowercase_in_peptides<EOL>

Parameters
----------
alleles : list
    List of strings containing names of HLA alleles we're
    making predictions for. Example:
        ["HLA-A*02:01", "HLA-B*07:02"]

valid_alleles : list, optional
    If given, constrain HLA alleles to be contained within
    this set.

default_peptide_lengths : list of int, optional
    When making predictions across subsequences of protein sequences,
    what peptide lengths to predict for.

min_peptide_length : int
    Shortest peptide this predictor can handle

max_peptide_length : int
    Longest peptide this predictor can handle

allow_X_in_peptides : bool
    Allow unknown amino acids in peptide sequences

allow_lowercase_in_peptides : bool
    Allow lowercase letters in peptide sequences


raise NotImplementedError("<STR_LIT>" % (<EOL>self.__class__.__name__))<EOL>

Given a list of peptide sequences, returns a BindingPredictionCollection


if not peptide_lengths:<EOL><INDENT>peptide_lengths = self.default_peptide_lengths<EOL><DEDENT>if not peptide_lengths:<EOL><INDENT>raise ValueError(<EOL>("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL><DEDENT>if isinstance(peptide_lengths, int):<EOL><INDENT>peptide_lengths = [peptide_lengths]<EOL><DEDENT>require_iterable_of(peptide_lengths, int)<EOL>for peptide_length in peptide_lengths:<EOL><INDENT>if (self.min_peptide_length is not None and<EOL>peptide_length < self.min_peptide_length):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % (<EOL>peptide_length,<EOL>self.min_peptide_length))<EOL><DEDENT>elif (self.max_peptide_length is not None and<EOL>peptide_length > self.max_peptide_length):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % (<EOL>peptide_length,<EOL>self.max_peptide_length))<EOL><DEDENT><DEDENT>return peptide_lengths<EOL>

If peptide lengths not specified, then try using the default
lengths associated with this predictor object. If those aren't
a valid non-empty sequence of integers, then raise an exception.
Otherwise return the peptide lengths.


require_iterable_of(peptides, string_types)<EOL>check_X = not self.allow_X_in_peptides<EOL>check_lower = not self.allow_lowercase_in_peptides<EOL>check_min_length = self.min_peptide_length is not None<EOL>min_length = self.min_peptide_length<EOL>check_max_length = self.max_peptide_length is not None<EOL>max_length = self.max_peptide_length<EOL>for p in peptides:<EOL><INDENT>if not p.isalpha():<EOL><INDENT>raise ValueError("<STR_LIT>" % p)<EOL><DEDENT>elif check_X and "<STR_LIT:X>" in p:<EOL><INDENT>raise ValueError("<STR_LIT>" % p)<EOL><DEDENT>elif check_lower and not p.isupper():<EOL><INDENT>raise ValueError("<STR_LIT>" % p)<EOL><DEDENT>elif check_min_length and len(p) < min_length:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % (<EOL>p, len(p), min_length))<EOL><DEDENT>elif check_max_length and len(p) > max_length:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % (<EOL>p, len(p), max_length))<EOL><DEDENT><DEDENT>

Check peptide sequences to make sure they are valid for this predictor.


if isinstance(sequence_dict, string_types):<EOL><INDENT>sequence_dict = {"<STR_LIT>": sequence_dict}<EOL><DEDENT>elif isinstance(sequence_dict, (list, tuple)):<EOL><INDENT>sequence_dict = {seq: seq for seq in sequence_dict}<EOL><DEDENT>peptide_lengths = self._check_peptide_lengths(peptide_lengths)<EOL>peptide_set = set([])<EOL>peptide_to_name_offset_pairs = defaultdict(list)<EOL>for name, sequence in sequence_dict.items():<EOL><INDENT>for peptide_length in peptide_lengths:<EOL><INDENT>for i in range(len(sequence) - peptide_length + <NUM_LIT:1>):<EOL><INDENT>peptide = sequence[i:i + peptide_length]<EOL>peptide_set.add(peptide)<EOL>peptide_to_name_offset_pairs[peptide].append((name, i))<EOL><DEDENT><DEDENT><DEDENT>peptide_list = sorted(peptide_set)<EOL>binding_predictions = self.predict_peptides(peptide_list)<EOL>results = []<EOL>for binding_prediction in binding_predictions:<EOL><INDENT>for name, offset in peptide_to_name_offset_pairs[<EOL>binding_prediction.peptide]:<EOL><INDENT>results.append(binding_prediction.clone_with_updates(<EOL>source_sequence_name=name,<EOL>offset=offset))<EOL><DEDENT><DEDENT>self._check_results(<EOL>results,<EOL>peptides=peptide_set,<EOL>alleles=self.alleles)<EOL>return BindingPredictionCollection(results)<EOL>

Given a dictionary mapping sequence names to amino acid strings,
and an optional list of peptide lengths, returns a
BindingPredictionCollection.


require_iterable_of(alleles, string_types, "<STR_LIT>")<EOL>alleles = {<EOL>normalize_allele_name(allele.strip().upper())<EOL>for allele in alleles<EOL>}<EOL>if valid_alleles:<EOL><INDENT>missing_alleles = [<EOL>allele<EOL>for allele in alleles<EOL>if allele not in valid_alleles<EOL>]<EOL>if len(missing_alleles) > <NUM_LIT:0>:<EOL><INDENT>raise UnsupportedAllele(<EOL>"<STR_LIT>" % missing_alleles)<EOL><DEDENT><DEDENT>return list(alleles)<EOL>

Given a list of HLA alleles and an optional list of valid
HLA alleles, return a set of alleles that we will pass into
the MHC binding predictor.


if isinstance(obj, string_classes):<EOL><INDENT>return obj<EOL><DEDENT>elif isinstance(obj, (list, tuple)):<EOL><INDENT>return sep.join([str(x) for x in obj])<EOL><DEDENT>else:<EOL><INDENT>return str(obj)<EOL><DEDENT>

Given a sequence convert it to a comma separated string.
If, however, the argument is a single object, return its string
representation.


args = parse_args(args_list)<EOL>binding_predictions = run_predictor(args)<EOL>df = binding_predictions.to_dataframe()<EOL>logger.info('<STR_LIT>', df)<EOL>if args.output_csv:<EOL><INDENT>df.to_csv(args.output_csv, index=False)<EOL>print("<STR_LIT>" % args.output_csv)<EOL><DEDENT>

Script to make pMHC binding predictions from amino acid sequences.

Usage example:
    mhctools
        --sequence SFFPIQQQQQAAALLLI \
        --sequence SILQQQAQAQQAQAASSSC \
        --extract-subsequences \
        --mhc-predictor netmhc \
        --mhc-alleles HLA-A0201 H2-Db \
        --mhc-predictor netmhc \
        --output-csv epitope.csv


integers = []<EOL>for comma_part in string.split("<STR_LIT:U+002C>"):<EOL><INDENT>for substring in comma_part.split("<STR_LIT:U+0020>"):<EOL><INDENT>if len(substring) == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>if "<STR_LIT:->" in substring:<EOL><INDENT>left, right = substring.split("<STR_LIT:->")<EOL>left_val = int(left.strip())<EOL>right_val = int(right.strip())<EOL>integers.extend(range(left_val, right_val + <NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>integers.append(int(substring.strip()))<EOL><DEDENT><DEDENT><DEDENT>return integers<EOL>

Parses a string of numbers and ranges into a list of integers. Ranges
are separated by dashes and inclusive of both the start and end number.

Example:
    parse_int_list("8 9 10,11-13") == [8,9,10,11,12,13]


<EOL>seen_dash = False<EOL>for l in stdout.split("<STR_LIT:\n>"):<EOL><INDENT>l = l.strip()<EOL>if l.startswith("<STR_LIT>"):<EOL><INDENT>seen_dash = True<EOL>continue<EOL><DEDENT>if not seen_dash:<EOL><INDENT>continue<EOL><DEDENT>if not l or l.startswith("<STR_LIT:#>"):<EOL><INDENT>continue<EOL><DEDENT>if any(l.startswith(word) for word in NETMHC_TOKENS):<EOL><INDENT>continue<EOL><DEDENT>yield l.split()<EOL><DEDENT>

Given the standard output from NetMHC/NetMHCpan/NetMHCcons tools,
drop all {comments, lines of hyphens, empty lines} and split the
remaining lines by whitespace.


def clean_fields(fields, ignored_value_indices, transforms):

cleaned_fields = []<EOL>for i, field in enumerate(fields):<EOL><INDENT>if field in ignored_value_indices:<EOL><INDENT>ignored_index = ignored_value_indices[field]<EOL>if ignored_index == i:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>cleaned_field = transforms[i](field) if i in transforms else field<EOL>cleaned_fields.append(cleaned_field)<EOL><DEDENT>return cleaned_fields<EOL>

Sometimes, NetMHC* has fields that are only populated sometimes, which results
in different count/indexing of the fields when that happens.

We handle this by looking for particular strings at particular indices, and
deleting them.

Warning: this may result in unexpected behavior sometimes. For example, we
ignore "SB" and "WB" for NetMHC 3.x output; which also means that any line
with a key called SB or WB will be ignored.

Also, sometimes NetMHC* will have fields that we want to modify in some
consistent way, e.g. NetMHCpan3 has 1-based offsets and all other predictors
have 0-based offsets (and we rely on 0-based offsets). We handle this using
a map from field index to transform function.


binding_predictions = []<EOL>for fields in split_stdout_lines(stdout):<EOL><INDENT>fields = clean_fields(fields, ignored_value_indices, transforms)<EOL>offset = int(fields[offset_index])<EOL>peptide = str(fields[peptide_index])<EOL>allele = str(fields[allele_index])<EOL>ic50 = float(fields[ic50_index])<EOL>rank = float(fields[rank_index]) if rank_index else <NUM_LIT:0.0><EOL>log_ic50 = float(fields[log_ic50_index])<EOL>key = str(fields[key_index])<EOL>if sequence_key_mapping:<EOL><INDENT>original_key = sequence_key_mapping[key]<EOL><DEDENT>else:<EOL><INDENT>original_key = key<EOL><DEDENT>binding_predictions.append(BindingPrediction(<EOL>source_sequence_name=original_key,<EOL>offset=offset,<EOL>peptide=peptide,<EOL>allele=normalize_allele_name(allele),<EOL>affinity=ic50,<EOL>percentile_rank=rank,<EOL>log_affinity=log_ic50,<EOL>prediction_method_name=prediction_method_name))<EOL><DEDENT>return binding_predictions<EOL>

Generic function for parsing any NetMHC* output, given expected indices
of values of interest.

Parameters
----------
ignored_value_indices : dict
    Map from values to the positions we'll ignore them at. See clean_fields.

transforms  : dict
    Map from field index to a transform function to be applied to values in
    that field. See clean_fields.

Returns BindingPredictionCollection


<EOL>transforms = {<EOL><NUM_LIT:0>: lambda x: int(x) - <NUM_LIT:1>,<EOL>}<EOL>return parse_stdout(<EOL>stdout=stdout,<EOL>prediction_method_name=prediction_method_name,<EOL>sequence_key_mapping=sequence_key_mapping,<EOL>key_index=<NUM_LIT:10>,<EOL>offset_index=<NUM_LIT:0>,<EOL>peptide_index=<NUM_LIT:2>,<EOL>allele_index=<NUM_LIT:1>,<EOL>ic50_index=<NUM_LIT:12>,<EOL>rank_index=<NUM_LIT>,<EOL>log_ic50_index=<NUM_LIT:11>,<EOL>transforms=transforms)<EOL>


<EOL>return parse_netmhcpan3_stdout(<EOL>stdout=stdout,<EOL>prediction_method_name=prediction_method_name,<EOL>sequence_key_mapping=sequence_key_mapping)<EOL>

# NetMHCpan version 4.0

# Tmpdir made /var/folders/jc/fyrvcrcs3sb8g4mkdg6nl_t80000gp/T//netMHCpanuH3SvY
# Input is in PEPTIDE format

# Make binding affinity predictions

HLA-A02:01 : Distance to training data  0.000 (using nearest neighbor HLA-A02:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
-----------------------------------------------------------------------------------
  Pos          HLA         Peptide       Core Of Gp Gl Ip Il        Icore        Identity     Score Aff(nM)   %Rank  BindLevel
-----------------------------------------------------------------------------------
    1  HLA-A*02:01        SIINFEKL  SIINF-EKL  0  0  0  5  1     SIINFEKL         PEPLIST 0.1141340 14543.1 18.9860
-----------------------------------------------------------------------------------

Protein PEPLIST. Allele HLA-A*02:01. Number of high binders 0. Number of weak binders 0. Number of peptides 1


def to_dataframe(<EOL>self,<EOL>columns=BindingPrediction.fields + ("<STR_LIT>",)):

return pd.DataFrame.from_records(<EOL>[tuple([getattr(x, name) for name in columns]) for x in self],<EOL>columns=columns)<EOL>

Converts collection of BindingPrediction objects to DataFrame


<EOL>with open(os.devnull, '<STR_LIT:w>') as devnull:<EOL><INDENT>output = check_output([<EOL>program_name, "<STR_LIT>", "<STR_LIT>"],<EOL>stderr=devnull)<EOL><DEDENT>output_str = output.decode("<STR_LIT:ascii>", "<STR_LIT:ignore>")<EOL>common_kwargs = {<EOL>"<STR_LIT>": alleles,<EOL>"<STR_LIT>": default_peptide_lengths,<EOL>"<STR_LIT>": program_name,<EOL>"<STR_LIT>": process_limit,<EOL>"<STR_LIT>": extra_flags,<EOL>}<EOL>if "<STR_LIT>" in output_str:<EOL><INDENT>return NetMHCpan28(**common_kwargs)<EOL><DEDENT>elif "<STR_LIT>" in output_str:<EOL><INDENT>return NetMHCpan3(**common_kwargs)<EOL><DEDENT>elif "<STR_LIT>" in output_str:<EOL><INDENT>return NetMHCpan4(**common_kwargs)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>")<EOL><DEDENT>

This function wraps NetMHCpan28 and NetMHCpan3 to automatically detect which class
to use, with the help of the miraculous and strange '--version' netmhcpan argument.


return datetime.datetime.utcnow().replace(microsecond=<NUM_LIT:0>)<EOL>


for cls in self:<EOL><INDENT>cls.create_table(fail_silently=True)<EOL><DEDENT>


for cls in self:<EOL><INDENT>cls.drop_table(fail_silently=True)<EOL><DEDENT>


assert issubclass(model_cls, peewee.Model)<EOL>assert not hasattr(model_cls._meta, '<STR_LIT>')<EOL>if model_cls in self:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>self.append(model_cls)<EOL>model_cls._meta.database = self.dbm<EOL>return model_cls<EOL>


for name, connection in self.items():<EOL><INDENT>connection.connect()<EOL><DEDENT>


for name, connection in self.items():<EOL><INDENT>if not connection.is_closed():<EOL><INDENT>connection.close()<EOL><DEDENT><DEDENT>


for router in self.routers:<EOL><INDENT>r = router.get_database(model)<EOL>if r is not None:<EOL><INDENT>return r<EOL><DEDENT><DEDENT>return self.get('<STR_LIT:default>')<EOL>


try:<EOL><INDENT>return cls.get(**kwargs)<EOL><DEDENT>except cls.DoesNotExist:<EOL><INDENT>return None<EOL><DEDENT>


return self._meta.database.atomic()<EOL>

Shortcut method for creating atomic context


fields = self._meta.get_primary_keys()<EOL>assert fields<EOL>values = {field.name:self.__data__[field.name] for field in fields}<EOL>return values<EOL>

Returns dict of values to uniquely reference this item


return self.get(**cursor)<EOL>

Returns model instance from unique cursor reference


ref = self.to_cursor_ref()<EOL>return self.from_cursor_ref(ref)<EOL>

Return new model instance with fresh data from database
Only works on models which have a primary or compound key
See https://github.com/coleifer/peewee/issues/638

XXX: Add support for models without PK


@classmethod<EOL><INDENT>def paginate_query(self, query, count, offset=None, sort=None):<DEDENT>

assert isinstance(query, peewee.Query)<EOL>assert isinstance(count, int)<EOL>assert isinstance(offset, (str, int, type(None)))<EOL>assert isinstance(sort, (list, set, tuple, type(None)))<EOL>fields = query.model._meta.get_primary_keys()<EOL>if len(fields) == <NUM_LIT:0>:<EOL><INDENT>raise peewee.ProgrammingError(<EOL>'<STR_LIT>')<EOL><DEDENT>if len(fields) > <NUM_LIT:1>:<EOL><INDENT>raise peewee.ProgrammingError(<EOL>'<STR_LIT>')<EOL><DEDENT>if offset is not None:<EOL><INDENT>query = query.where(fields[<NUM_LIT:0>] >= offset)<EOL><DEDENT>order_bys = []<EOL>if sort:<EOL><INDENT>for field, direction in sort:<EOL><INDENT>if not isinstance(direction, str):<EOL><INDENT>raise ValueError("<STR_LIT>".format(field))<EOL><DEDENT>direction = direction.lower().strip()<EOL>if direction not in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>raise ValueError("<STR_LIT>".format(field))<EOL><DEDENT>order_by = peewee.SQL(field)<EOL>order_by = getattr(order_by, direction)()<EOL>order_bys += [order_by]<EOL><DEDENT><DEDENT>order_bys += [fields[<NUM_LIT:0>].asc()]<EOL>query = query.order_by(*order_bys)<EOL>query = query.limit(count)<EOL>return query<EOL>

Apply pagination to query

:attr query: Instance of `peewee.Query`
:attr count: Max rows to return
:attr offset: Pagination offset, str/int
:attr sort: List of tuples, e.g. [('id', 'asc')]

:returns: Instance of `peewee.Query`


return self.query<EOL>


return self.paginator<EOL>


def apply_filters(self, query, filters):

assert isinstance(query, peewee.Query)<EOL>assert isinstance(filters, dict)<EOL>


assert isinstance(filters, dict), "<STR_LIT>"<EOL>assert isinstance(cursor, dict), "<STR_LIT>"<EOL>query = self.get_query()<EOL>assert isinstance(query, peewee.Query)<EOL>paginator = self.get_paginator()<EOL>assert isinstance(paginator, Pagination)<EOL>count += <NUM_LIT:1><EOL>pquery = paginator.filter_query(query, cursor, count)<EOL>items = [ item for item in pquery ]<EOL>next_item = items.pop(<NUM_LIT:1>)<EOL>next_cursor = next_item.to_cursor_ref()<EOL>'''<STR_LIT>'''<EOL>return items, next_cursor<EOL>


assert isinstance(cursor, dict), "<STR_LIT>"<EOL>query = self.get_query()<EOL>assert isinstance(query, peewee.Query)<EOL>query<EOL>return query.get(**cursor)<EOL>


fake = Faker()<EOL>fake.seed(<NUM_LIT:0>)<EOL>cities = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>items = []<EOL>for x in range(<NUM_LIT:100>):<EOL><INDENT>city = cities[x % len(cities)]<EOL>items += [dict(name=fake.name(), city=city)]<EOL><DEDENT>Person.insert_many(items).execute()<EOL>assert Person.select().count() == <NUM_LIT:100><EOL>

Populate test models with (predictable) fake data


<EOL>if not isinstance(value, UUID):<EOL><INDENT>value = UUID(value)<EOL><DEDENT>parts = str(value).split("<STR_LIT:->")<EOL>reordered = '<STR_LIT>'.join([parts[<NUM_LIT:2>], parts[<NUM_LIT:1>], parts[<NUM_LIT:0>], parts[<NUM_LIT:3>], parts[<NUM_LIT:4>]])<EOL>value = binascii.unhexlify(reordered)<EOL>return super(OrderedUUIDField, self).db_value(value)<EOL>


value = super(OrderedUUIDField, self).python_value(value)<EOL>u = binascii.b2a_hex(value)<EOL>value = u[<NUM_LIT:8>:<NUM_LIT:16>] + u[<NUM_LIT:4>:<NUM_LIT:8>] + u[<NUM_LIT:0>:<NUM_LIT:4>] + u[<NUM_LIT:16>:<NUM_LIT>] + u[<NUM_LIT>:<NUM_LIT:32>]<EOL>return UUID(value.decode())<EOL>


value = self.transform_value(value)<EOL>return self.hhash.encrypt(value,<EOL>salt_size=self.salt_size, rounds=self.rounds)<EOL>

Convert the python value for storage in the database.


value = coerce_to_bytes(value)<EOL>obj = HashValue(value)<EOL>obj.field = self<EOL>return obj<EOL>

Convert the database value to a pythonic value.


if not self.is_valid:<EOL><INDENT>raise PolyaxonDeploymentConfigError(<EOL>'<STR_LIT>'.format(self.deployment_type))<EOL><DEDENT>check = False<EOL>if self.is_kubernetes:<EOL><INDENT>check = self.check_for_kubernetes()<EOL><DEDENT>elif self.is_docker_compose:<EOL><INDENT>check = self.check_for_docker_compose()<EOL><DEDENT>elif self.is_docker:<EOL><INDENT>check = self.check_for_docker()<EOL><DEDENT>elif self.is_heroku:<EOL><INDENT>check = self.check_for_heroku()<EOL><DEDENT>if not check:<EOL><INDENT>raise PolyaxonDeploymentConfigError(<EOL>'<STR_LIT>'.format(self.deployment_type))<EOL><DEDENT>


Install polyaxon using the current config to the correct platform.


while line.endswith('<STR_LIT:U+0020>') and not line.endswith('<STR_LIT>'):<EOL><INDENT>line = line[:-<NUM_LIT:1>]<EOL><DEDENT>return line.replace('<STR_LIT>', '<STR_LIT:U+0020>')<EOL>

Remove trailing spaces unless they are quoted with a backslash.


@classmethod<EOL><INDENT>def find_matching(cls, path, patterns):<DEDENT>

for pattern in patterns:<EOL><INDENT>if pattern.match(path):<EOL><INDENT>yield pattern<EOL><DEDENT><DEDENT>


@classmethod<EOL><INDENT>def is_ignored(cls, path, patterns):<DEDENT>

status = None<EOL>for pattern in cls.find_matching(path, patterns):<EOL><INDENT>status = pattern.is_exclude<EOL><DEDENT>return status<EOL>

Check whether a path is ignored. For directories, include a trailing slash.


for glob in patterns:<EOL><INDENT>try:<EOL><INDENT>if PurePath(path).match(glob):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return False<EOL>

Given a list of patterns, returns a if a path matches any pattern.


@classmethod<EOL><INDENT>def _ignore_path(cls, path, ignore_list=None, white_list=None):<DEDENT>

ignore_list = ignore_list or []<EOL>white_list = white_list or []<EOL>return (cls._matches_patterns(path, ignore_list) and<EOL>not cls._matches_patterns(path, white_list))<EOL>

Returns a whether a path should be ignored or not.


@click.group()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', is_flag=True, default=False, help='<STR_LIT>')<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def cli(context, verbose):

configure_logger(verbose or GlobalConfigManager.get_value('<STR_LIT>'))<EOL>non_check_cmds = ['<STR_LIT>', '<STR_LIT:version>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>if context.invoked_subcommand not in non_check_cmds:<EOL><INDENT>check_cli_version()<EOL><DEDENT>

Polyaxon CLI tool to:

        * Parse, Validate, and Check Polyaxonfiles.

        * Interact with Polyaxon server.

        * Run and Monitor experiments.

    Check the help available for each command listed below.


fd, filename = tempfile.mkstemp(prefix="<STR_LIT>".format(project_name), suffix='<STR_LIT>')<EOL>with tarfile.open(filename, "<STR_LIT>") as tar:<EOL><INDENT>for f in files:<EOL><INDENT>tar.add(f)<EOL><DEDENT><DEDENT>yield filename<EOL>os.close(fd)<EOL>os.remove(filename)<EOL>

Create a tar file based on the list of files passed


click.echo(<EOL>json.dumps(value,<EOL>sort_keys=True,<EOL>indent=<NUM_LIT:4>,<EOL>separators=('<STR_LIT:U+002C>', '<STR_LIT>')))<EOL>


@click.group(invoke_without_command=True)<EOL>@click.option('<STR_LIT>', '<STR_LIT>', is_flag=True, help='<STR_LIT>')<EOL>@clean_outputs<EOL>def config(list):

if list:<EOL><INDENT>_config = GlobalConfigManager.get_config_or_default()<EOL>Printer.print_header('<STR_LIT>')<EOL>dict_tabulate(_config.to_dict())<EOL><DEDENT>


@config.command()<EOL>@click.argument('<STR_LIT>', type=str, nargs=-<NUM_LIT:1>)<EOL>@clean_outputs<EOL>def get(keys):

_config = GlobalConfigManager.get_config_or_default()<EOL>if not keys:<EOL><INDENT>return<EOL><DEDENT>print_values = {}<EOL>for key in keys:<EOL><INDENT>if hasattr(_config, key):<EOL><INDENT>print_values[key] = getattr(_config, key)<EOL><DEDENT>else:<EOL><INDENT>click.echo('<STR_LIT>'.format(key))<EOL><DEDENT><DEDENT>dict_tabulate(print_values, )<EOL>

Get the global config values by keys.

    Example:

    \b
    ```bash
    $ polyaxon config get host http_port
    ```


@config.command()<EOL>@click.option('<STR_LIT>', type=bool, help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=str, help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=int, help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=int, help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=bool, help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=bool,<EOL>help='<STR_LIT>')<EOL>@clean_outputs<EOL>def set(verbose,  <EOL>host,<EOL>http_port,<EOL>ws_port,<EOL>use_https,<EOL>verify_ssl):

_config = GlobalConfigManager.get_config_or_default()<EOL>if verbose is not None:<EOL><INDENT>_config.verbose = verbose<EOL><DEDENT>if host is not None:<EOL><INDENT>_config.host = host<EOL><DEDENT>if http_port is not None:<EOL><INDENT>_config.http_port = http_port<EOL><DEDENT>if ws_port is not None:<EOL><INDENT>_config.ws_port = ws_port<EOL><DEDENT>if use_https is not None:<EOL><INDENT>_config.use_https = use_https<EOL><DEDENT>if verify_ssl is False:<EOL><INDENT>_config.verify_ssl = verify_ssl<EOL><DEDENT>GlobalConfigManager.set_config(_config)<EOL>Printer.print_success('<STR_LIT>')<EOL>CliConfigManager.purge()<EOL>

Set the global config values.

    Example:

    \b
    ```bash
    $ polyaxon config set --hots=localhost http_port=80
    ```


project = ProjectManager.get_config_or_raise()<EOL>files = IgnoreManager.get_unignored_file_paths()<EOL>try:<EOL><INDENT>with create_tarfile(files, project.name) as file_path:<EOL><INDENT>with get_files_in_current_directory('<STR_LIT>', [file_path]) as (files, files_size):<EOL><INDENT>try:<EOL><INDENT>PolyaxonClient().project.upload_repo(project.user,<EOL>project.name,<EOL>files,<EOL>files_size,<EOL>sync=sync)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error(<EOL>'<STR_LIT>'.format(project.name))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>Printer.print_error(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>Printer.print_success('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>Printer.print_error("<STR_LIT>")<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>

Upload code of the current directory while respecting the .polyaxonignore file.


Check if the current cli version satisfies the server requirements


@click.command()<EOL>@click.option('<STR_LIT>', is_flag=True, default=False, help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', is_flag=True, default=False, help='<STR_LIT>')<EOL>@clean_outputs<EOL>def version(cli, platform):

version_client = PolyaxonClient().version<EOL>cli = cli or not any([cli, platform])<EOL>if cli:<EOL><INDENT>try:<EOL><INDENT>server_version = version_client.get_cli_version()<EOL><DEDENT>except AuthorizationError:<EOL><INDENT>session_expired()<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>')<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>cli_version = get_version(PROJECT_CLI_NAME)<EOL>Printer.print_header('<STR_LIT>'.format(cli_version))<EOL>Printer.print_header('<STR_LIT>')<EOL>dict_tabulate(server_version.to_dict())<EOL><DEDENT>if platform:<EOL><INDENT>try:<EOL><INDENT>platform_version = version_client.get_platform_version()<EOL><DEDENT>except AuthorizationError:<EOL><INDENT>session_expired()<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>')<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>chart_version = version_client.get_chart_version()<EOL>Printer.print_header('<STR_LIT>'.format(chart_version.version))<EOL>Printer.print_header('<STR_LIT>')<EOL>dict_tabulate(platform_version.to_dict())<EOL><DEDENT>

Print the current version of the cli and platform.


try:<EOL><INDENT>pip_upgrade(PROJECT_CLI_NAME)<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.error(e)<EOL><DEDENT>


@admin.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', type=click.Path(exists=True),<EOL>help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=click.Path(exists=True),<EOL>help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', is_flag=True, default=False,<EOL>help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', is_flag=True, default=False,<EOL>help='<STR_LIT>')<EOL>@clean_outputs<EOL>def deploy(file, manager_path, check, dry_run):

config = read_deployment_config(file)<EOL>manager = DeployManager(config=config,<EOL>filepath=file,<EOL>manager_path=manager_path,<EOL>dry_run=dry_run)<EOL>exception = None<EOL>if check:<EOL><INDENT>manager.check()<EOL>Printer.print_success('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>manager.install()<EOL><DEDENT>except Exception as e:<EOL><INDENT>Printer.print_error('<STR_LIT>')<EOL>exception = e<EOL><DEDENT><DEDENT>if exception:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(exception))<EOL><DEDENT>


@admin.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', type=click.Path(exists=True),<EOL>help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=click.Path(exists=True),<EOL>help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', is_flag=True, default=False,<EOL>help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', is_flag=True, default=False,<EOL>help='<STR_LIT>')<EOL>@clean_outputs<EOL>def upgrade(file, manager_path, check, dry_run):

config = read_deployment_config(file)<EOL>manager = DeployManager(config=config,<EOL>filepath=file,<EOL>manager_path=manager_path,<EOL>dry_run=dry_run)<EOL>exception = None<EOL>if check:<EOL><INDENT>manager.check()<EOL>Printer.print_success('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>manager.upgrade()<EOL><DEDENT>except Exception as e:<EOL><INDENT>Printer.print_error('<STR_LIT>')<EOL>exception = e<EOL><DEDENT><DEDENT>if exception:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(exception))<EOL><DEDENT>


config = read_deployment_config(file)<EOL>manager = DeployManager(config=config, filepath=file)<EOL>exception = None<EOL>try:<EOL><INDENT>if click.confirm('<STR_LIT>', default=True):<EOL><INDENT>manager.teardown(hooks=True)<EOL><DEDENT>else:<EOL><INDENT>manager.teardown(hooks=False)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>Printer.print_error('<STR_LIT>')<EOL>exception = e<EOL><DEDENT>if exception:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(exception))<EOL><DEDENT>

Teardown a polyaxon deployment given a config file.


@click.group()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', type=str, help="<STR_LIT>")<EOL>@click.option('<STR_LIT>', '<STR_LIT>', type=int, help="<STR_LIT>")<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def build(ctx, project, build):

ctx.obj = ctx.obj or {}<EOL>ctx.obj['<STR_LIT>'] = project<EOL>ctx.obj['<STR_LIT>'] = build<EOL>


user, project_name, _build = get_build_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>try:<EOL><INDENT>response = PolyaxonClient().build_job.get_build(user, project_name, _build)<EOL>cache.cache(config_manager=BuildJobManager, response=response)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>get_build_details(response)<EOL>

Get build job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon build -b 1 get
    ```

    \b
    ```bash
    $ polyaxon build --build=1 --project=project_name get
    ```


user, project_name, _build = get_build_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>if not click.confirm("<STR_LIT>".format(_build)):<EOL><INDENT>click.echo('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>try:<EOL><INDENT>response = PolyaxonClient().build_job.delete_build(<EOL>user, project_name, _build)<EOL>BuildJobManager.purge()<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>if response.status_code == <NUM_LIT>:<EOL><INDENT>Printer.print_success("<STR_LIT>".format(_build))<EOL><DEDENT>

Delete build job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Example:

    \b
    ```bash
    $ polyaxon build delete
    ```

    \b
    ```bash
    $ polyaxon build -b 2 delete
    ```


@build.command()<EOL>@click.option('<STR_LIT>', type=str,<EOL>help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=str, help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=str, help='<STR_LIT>')<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def update(ctx, name, description, tags):

user, project_name, _build = get_build_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>update_dict = {}<EOL>if name:<EOL><INDENT>update_dict['<STR_LIT:name>'] = name<EOL><DEDENT>if description:<EOL><INDENT>update_dict['<STR_LIT:description>'] = description<EOL><DEDENT>tags = validate_tags(tags)<EOL>if tags:<EOL><INDENT>update_dict['<STR_LIT>'] = tags<EOL><DEDENT>if not update_dict:<EOL><INDENT>Printer.print_warning('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:0>)<EOL><DEDENT>try:<EOL><INDENT>response = PolyaxonClient().build_job.update_build(<EOL>user, project_name, _build, update_dict)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>Printer.print_success("<STR_LIT>")<EOL>get_build_details(response)<EOL>

Update build.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Example:

    \b
    ```bash
    $ polyaxon build -b 2 update --description="new description for my build"
    ```


@build.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', is_flag=True, default=False,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def stop(ctx, yes):

user, project_name, _build = get_build_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>if not yes and not click.confirm("<STR_LIT>"<EOL>"<STR_LIT>".format(_build)):<EOL><INDENT>click.echo('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:0>)<EOL><DEDENT>try:<EOL><INDENT>PolyaxonClient().build_job.stop(user, project_name, _build)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>Printer.print_success("<STR_LIT>")<EOL>

Stop build job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon build stop
    ```

    \b
    ```bash
    $ polyaxon build -b 2 stop
    ```


user, project_name, _build = get_build_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>try:<EOL><INDENT>PolyaxonClient().build_job.bookmark(user, project_name, _build)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>Printer.print_success("<STR_LIT>")<EOL>

Bookmark build job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon build bookmark
    ```

    \b
    ```bash
    $ polyaxon build -b 2 bookmark
    ```


user, project_name, _build = get_build_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>try:<EOL><INDENT>PolyaxonClient().build_job.unbookmark(user, project_name, _build)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>Printer.print_success("<STR_LIT>")<EOL>

Unbookmark build job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon build unbookmark
    ```

    \b
    ```bash
    $ polyaxon build -b 2 unbookmark
    ```


@build.command()<EOL>@click.option('<STR_LIT>', type=int, help="<STR_LIT>")<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def statuses(ctx, page):

user, project_name, _build = get_build_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>page = page or <NUM_LIT:1><EOL>try:<EOL><INDENT>response = PolyaxonClient().build_job.get_statuses(user, project_name, _build, page=page)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>meta = get_meta_response(response)<EOL>if meta:<EOL><INDENT>Printer.print_header('<STR_LIT>'.format(_build))<EOL>Printer.print_header('<STR_LIT>')<EOL>dict_tabulate(meta)<EOL><DEDENT>else:<EOL><INDENT>Printer.print_header('<STR_LIT>'.format(_build))<EOL><DEDENT>objects = list_dicts_to_tabulate(<EOL>[Printer.add_status_color(o.to_light_dict(humanize_values=True), status_key='<STR_LIT:status>')<EOL>for o in response['<STR_LIT>']])<EOL>if objects:<EOL><INDENT>Printer.print_header("<STR_LIT>")<EOL>objects.pop('<STR_LIT>', None)<EOL>dict_tabulate(objects, is_list_dict=True)<EOL><DEDENT>

Get build job statuses.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon build -b 2 statuses
    ```


@build.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', is_flag=True, help='<STR_LIT>')<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def resources(ctx, gpu):

user, project_name, _build = get_build_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>try:<EOL><INDENT>message_handler = Printer.gpu_resources if gpu else Printer.resources<EOL>PolyaxonClient().build_job.resources(user,<EOL>project_name,<EOL>_build,<EOL>message_handler=message_handler)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>

Get build job resources.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon build -b 2 resources
    ```

    For GPU resources

    \b
    ```bash
    $ polyaxon build -b 2 resources --gpu
    ```


@build.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', is_flag=True, help="<STR_LIT>")<EOL>@click.option('<STR_LIT>', '<STR_LIT>', is_flag=True, default=False,<EOL>help="<STR_LIT>")<EOL>@click.option('<STR_LIT>', is_flag=True, default=False,<EOL>help="<STR_LIT>")<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def logs(ctx, past, follow, hide_time):

user, project_name, _build = get_build_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>if past:<EOL><INDENT>try:<EOL><INDENT>response = PolyaxonClient().build_job.logs(<EOL>user, project_name, _build, stream=False)<EOL>get_logs_handler(handle_job_info=False,<EOL>show_timestamp=not hide_time,<EOL>stream=False)(response.content.decode().split('<STR_LIT:\n>'))<EOL>print()<EOL>if not follow:<EOL><INDENT>return<EOL><DEDENT><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>if not follow:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>PolyaxonClient().build_job.logs(<EOL>user,<EOL>project_name,<EOL>_build,<EOL>message_handler=get_logs_handler(handle_job_info=False, show_timestamp=not hide_time))<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_build))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>

Get build logs.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon build -b 2 logs
    ```

    \b
    ```bash
    $ polyaxon build logs
    ```


@click.group()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', type=str, help="<STR_LIT>")<EOL>@click.option('<STR_LIT>', '<STR_LIT>', type=int, help="<STR_LIT>")<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def job(ctx, project, job):

ctx.obj = ctx.obj or {}<EOL>ctx.obj['<STR_LIT>'] = project<EOL>ctx.obj['<STR_LIT>'] = job<EOL>


user, project_name, _job = get_job_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>try:<EOL><INDENT>response = PolyaxonClient().job.get_job(user, project_name, _job)<EOL>cache.cache(config_manager=JobManager, response=response)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_job))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>get_job_details(response)<EOL>

Get job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon job --job=1 get
    ```

    \b
    ```bash
    $ polyaxon job --job=1 --project=project_name get
    ```


user, project_name, _job = get_job_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>if not click.confirm("<STR_LIT>".format(_job)):<EOL><INDENT>click.echo('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>try:<EOL><INDENT>response = PolyaxonClient().job.delete_job(<EOL>user, project_name, _job)<EOL>JobManager.purge()<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_job))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>if response.status_code == <NUM_LIT>:<EOL><INDENT>Printer.print_success("<STR_LIT>".format(_job))<EOL><DEDENT>

Delete job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Example:

    \b
    ```bash
    $ polyaxon job delete
    ```


@job.command()<EOL>@click.option('<STR_LIT>', type=str,<EOL>help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=str, help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', type=str, help='<STR_LIT>')<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def update(ctx, name, description, tags):

user, project_name, _job = get_job_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>update_dict = {}<EOL>if name:<EOL><INDENT>update_dict['<STR_LIT:name>'] = name<EOL><DEDENT>if description:<EOL><INDENT>update_dict['<STR_LIT:description>'] = description<EOL><DEDENT>tags = validate_tags(tags)<EOL>if tags:<EOL><INDENT>update_dict['<STR_LIT>'] = tags<EOL><DEDENT>if not update_dict:<EOL><INDENT>Printer.print_warning('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:0>)<EOL><DEDENT>try:<EOL><INDENT>response = PolyaxonClient().job.update_job(<EOL>user, project_name, _job, update_dict)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_job))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>Printer.print_success("<STR_LIT>")<EOL>get_job_details(response)<EOL>

Update job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Example:

    \b
    ```bash
    $ polyaxon job -j 2 update --description="new description for my job"
    ```


@job.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', is_flag=True, default=False,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def stop(ctx, yes):

user, project_name, _job = get_job_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>if not yes and not click.confirm("<STR_LIT>"<EOL>"<STR_LIT>".format(_job)):<EOL><INDENT>click.echo('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:0>)<EOL><DEDENT>try:<EOL><INDENT>PolyaxonClient().job.stop(user, project_name, _job)<EOL><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_job))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>Printer.print_success("<STR_LIT>")<EOL>

Stop job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon job stop
    ```

    \b
    ```bash
    $ polyaxon job -xp 2 stop
    ```


@job.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT:-c>', is_flag=True, default=False,<EOL>help="<STR_LIT>")<EOL>@click.option('<STR_LIT>', '<STR_LIT>', multiple=True, type=click.Path(exists=True),<EOL>help="<STR_LIT>")<EOL>@click.option('<STR_LIT>', is_flag=True, default=False,<EOL>help="<STR_LIT>")<EOL>@click.pass_context<EOL>@clean_outputs<EOL>def restart(ctx, copy, file, u):

config = None<EOL>update_code = None<EOL>if file:<EOL><INDENT>config = rhea.read(file)<EOL><DEDENT>if u:<EOL><INDENT>ctx.invoke(upload, sync=False)<EOL>update_code = True<EOL><DEDENT>user, project_name, _job = get_job_or_local(ctx.obj.get('<STR_LIT>'), ctx.obj.get('<STR_LIT>'))<EOL>try:<EOL><INDENT>if copy:<EOL><INDENT>response = PolyaxonClient().job.copy(<EOL>user, project_name, _job, config=config, update_code=update_code)<EOL><DEDENT>else:<EOL><INDENT>response = PolyaxonClient().job.restart(<EOL>user, project_name, _job, config=config, update_code=update_code)<EOL><DEDENT><DEDENT>except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:<EOL><INDENT>Printer.print_error('<STR_LIT>'.format(_job))<EOL>Printer.print_error('<STR_LIT>'.format(e))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>get_job_details(response)<EOL>

Restart job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon job --job=1 restart
    ```