a
    g	g	                     @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dl	mZ d d	l	mZ d d
l	mZ ddlmZ ddlmZ d ddddddZdddddZddddddZddddZdS )!    )annotationsN)exists)join)splitext)
check_call)Dict)List)Mapping)Optional   is_posix)CommandErrorstrzOptional[Dict[str, str]]None)filenameenvironreturnc              
   C  sd   |du rt jn|}zt|}t|| g W n4 ty^ } ztd|f |W Y d}~n
d}~0 0 dS )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.
    NzError executing editor (%s))osr   _find_editorr   	Exceptionr   )r   r   enveditorexc r   V/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/alembic/util/editor.pyopen_in_editor   s    r   zMapping[str, str])r   r   c                 C  s~   t  }tdD ]>\}}|| v r| | }t|r6|  S tj|vr||| q|D ]}t|| }|d urR|  S qRtdd S )N)ZEDITORZVISUALzSNo suitable editor found. Please set the "EDITOR" or "VISUAL" environment variables)_default_editors	enumerater   r   sepinsert_find_executableOSError)r   
candidatesivarZuser_choice	candidatepathr   r   r   r   )   s    


r   zOptional[str])r&   r   r   c                 C  sT   t st| d dkr| d7 } |ddtjD ]}t|| }t|r0|  S q0d S )Nr   z.exePATH )r   r   getsplitr   pathsepr   r   )r&   r   r'   valuer   r   r   r!   =   s    

r!   z	List[str])r   c                   C  s   t rg dS g dS d S )N)zsensible-editorr   ZnanoZvimcode)zcode.exeznotepad++.exeznotepad.exer   r   r   r   r   r   K   s    r   )N)
__future__r   r   os.pathr   r   r   
subprocessr   typingr   r   r	   r
   compatr   r   r   r   r   r!   r   r   r   r   r   <module>   s     