U of @sddlmZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z dd l m Z dd l m Z d d lmZd d lmZd ddddddZdddddZddddddZddddZdS)!) annotationsN)exists)join)splitext) check_call)Dict)List)Mapping)Optionalis_posix) CommandErrorstrzOptional[Dict[str, str]]None)filenameenvironreturnc Csb|dkrtjn|}zt|}t||gWn2tk r\}ztd|f|W5d}~XYnXdS)a Opens the given file in a text editor. If the environment variable ``EDITOR`` is set, this is taken as preference. Otherwise, a list of commonly installed editors is tried. If no editor matches, an :py:exc:`OSError` is raised. :param filename: The filename to open. Will be passed verbatim to the editor command. :param environ: An optional drop-in replacement for ``os.environ``. Used mainly for testing. NzError executing editor (%s))osr _find_editorr Exceptionr)rrenveditorexcrA/opt/hc_python/lib/python3.8/site-packages/alembic/util/editor.pyopen_in_editors rzMapping[str, str])rrcCs~t}tdD]>\}}||kr||}t|r6|Stj|kr|||q|D]}t||}|dk rR|SqRtddS)N)ZEDITORZVISUALzSNo suitable editor found. Please set the "EDITOR" or "VISUAL" environment variables)_default_editors enumeraterrsepinsert_find_executableOSError)r candidatesivarZ user_choice candidatepathrrrr)s   rz Optional[str])r&rrcCsTtst|ddkr|d7}|ddtjD]}t||}t|r0|Sq0dS)Nr z.exePATH)r rgetsplitrpathseprr)r&rr'valuerrrr!=s  r!z List[str])rcCs trdddddgSdddgSdS) Nzsensible-editorrZnanovimcodezcode.exez notepad++.exez notepad.exer rrrrrKsr)N) __future__rros.pathrrr subprocessrtypingrrr r compatr rrrrr!rrrrrs