o
    2wi                     @   s~   d Z ddlZddlmZ ddlZddlZddlmZ ddl	m
Z
 ddlmZ defd	d
Zddeje deje fddZdS )z=Internal utilities, likely shouldn't be called from outside.
    N)Path   )fatal)DecoratedMain)import_or_fatalmain_modulec                 C   s   t d}g }| D ]}| r%|d  r%||  d  r%||j q
t|dkr2td d S t|dkr<|d S tdd| d	 d S )
N.z__init__.pyz.pyr   zCould not find a training package. Use -P, or set DORA_PACKAGE to set the package. Use --main_module or set DORA_MAIN_MODULE to set the module to be excecuted inside the defined package.r   zFound multiple candidates: z, z. Use -P, or set DORA_PACKAGE to set package being searched. Use --main_module or set DORA_MAIN_MODULE to set the module being searched inside the package.)	r   iterdiris_direxistsappendnamelenr   join)r   cwd
candidateschild r   H/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/dora/_utils.py_find_package   s   r   packagec                 C   s   | d u rt jdpd} |d u rt jd}|d u rt| }|d |  }tjdttd	  t
|}z|j}W n tyK   td| d Y nw t|tsXt| d |S )NDORA_MAIN_MODULEtrainDORA_PACKAGEr   r   z"Could not find function `main` in z).main was not decorated with `dora.main`.)osenvirongetr   syspathinsertstrr   resolver   mainAttributeErrorr   
isinstancer   )r   r   module_namemoduler"   r   r   r   get_main'   s"   

r'   )NN)__doc__r   pathlibr   r   typingtplogr   r"   r   utilsr   r    r   Optionalr'   r   r   r   r   <module>   s   $