
    G@d                         d Z ddlmZ ddlZddlmZ ddlZddlm	Z	 ddl
mZ ddlmZmZmZmZmZ  G d d          Z G d	 d
e          ZdS )z
Projects Plugin API.
    )OrderedDictN_)get_project_config_folder)ProjectMultiConfigPROJECT_NAME_MAPPROJECT_DEFAULTSPROJECT_CONF_VERSION	WORKSPACEc                       e Zd ZdZdZddZedfdZefdZd Z	d Z
ed             Zed	             Zed
             Zd Zd Zd ZdS )BaseProjectTypez
    Spyder base project.

    This base class must not be used directly, but inherited from. It does not
    assume that python is specific to this project.
    Nc                    || _         || _        g | _        g | _        t	          j        |t                      d          }	 |                     |          | _        nC# t          j
        $ r1 t          j        |           |                     |          | _        Y nw xY w|                     d          }|s|                     d| j                   d S d S )Nconfigproject_type)plugin	root_pathopen_project_filesopen_non_project_filesospjoinr   create_configr   configparserErrorshutilrmtree
get_option
set_optionID)selfr   parent_pluginpathact_names        ;lib/python3.11/site-packages/spyder/plugins/projects/api.py__init__zBaseProjectType.__init__$   s    #""$&(# x	#<#>#>II
	3,,T22DKK! 	3 	3 	3M$,,T22DKKK	3
 ??>22 	5OONDG44444	5 	5s    A =BBc                 <    | j                             |||          S )z!Get project configuration option.)sectionoptiondefault)r   get)r   r'   r&   r(   s       r#   r   zBaseProjectType.get_option=   s    {wvwOOO    c                 @    | j                             |||           dS )z!Set project configuration option.)r&   r'   valueN)r   set)r   r'   r,   r&   s       r#   r   zBaseProjectType.set_optionA   s"    eDDDDDr*   c                 V   g }|D ]l}t          j        |          rV	 t          j        || j                  }|                    |           G# t
          $ r |                    |           Y hw xY wmt          t          j        |                    }| 	                    d|           dS )z*Set a list of files opened by the project.recent_filesN)
r   isfilerelpathr   append
ValueErrorlistr   fromkeysr   )r   r/   processed_recent_filesrecent_filerelative_recent_filefiless         r#   set_recent_filesz BaseProjectType.set_recent_filesE   s    !#' 	? 	?Kz+&& ??+.;#T^,5 ,5(*112FGGGG! ? ? ?*11+>>>>>?? [)*@AABB.....s   /AA.-A.c                                           ddg           }|r1 j                            dd                                |           n                      dg           } fd|D             }|dd         D ]+}t	          j        |          s|                    |           ,t          t          j	        |                    S )z-Return a list of files opened by the project.r/   main)r(   c                 p    g | ]2}t          j        |          r|nt          j        j        |          3S  )r   isabsr   r   ).0r7   r   s     r#   
<listcomp>z4BaseProjectType.get_recent_files.<locals>.<listcomp>`   sN     9 9 9' (+y'='= C XdnkBB9 9 9r*   N)
r   r   remove_optionr:   r   r0   remover4   r   r5   )r   r/   r7   s   `  r#   get_recent_filesz BaseProjectType.get_recent_filesT   s     ~vrBB 	GK%%fn===!!,////??>2?FFL9 9 9 9+79 9 9 (? 	1 	1K:k** 1##K000K(66777r*   c           
      N    t          t          | t          dt          ddd          S )z*Create the project's configuration object.TF)r!   defaultsloadversionbackupraw_moderemove_obsolete)r   r   r	   r
   )r!   s    r#   r   zBaseProjectType.create_configi   s3     "%(!	
 	
 	
 		
r*   c                       t          d          )z;
        Provide a human readable version of NAME.
        z#Must implement a `get_name` method!)NotImplementedErrorr>   r*   r#   get_namezBaseProjectType.get_namey   s    
 ""GHHHr*   c                     dS )a  
        Validate the project's name.

        Returns
        -------
        tuple
            The first item (bool) indicates if the name was validated
            successfully, and the second item (str) indicates the error
            message, if any.
        T r>   )r!   names     r#   validate_namezBaseProjectType.validate_name   s	     xr*   c                     dS )a0  
        Create a project and do any additional setup for this project type.

        Returns
        -------
        tuple
            The first item (bool) indicates if the project was created
            successfully, and the second item (str) indicates the error
            message, if any.
        )Fz4A ProjectType must define a `create_project` method!r>   r   s    r#   create_projectzBaseProjectType.create_project   s     MLr*   c                     dS )a-  
        Open a project and do any additional setup for this project type.

        Returns
        -------
        tuple
            The first item (bool) indicates if the project was opened
            successfully, and the second item (str) indicates the error
            message, if any.
        )Fz3A ProjectType must define an `open_project` method!r>   rU   s    r#   open_projectzBaseProjectType.open_project        LKr*   c                     dS )a.  
        Close a project and do any additional setup for this project type.

        Returns
        -------
        tuple
            The first item (bool) indicates if the project was closed
            successfully, and the second item (str) indicates the error
            message, if any.
        )Fz3A ProjectType must define a `close_project` method!r>   rU   s    r#   close_projectzBaseProjectType.close_project   rY   r*   )N)__name__
__module____qualname____doc__r   r$   r   r   r   r:   rD   staticmethodr   rN   rS   rV   rX   r[   r>   r*   r#   r   r      s         
B5 5 5 52 *3D P P P P 1: E E E E/ / /8 8 8* 
 
 \
 I I \I   \M M ML L LL L L L Lr*   r   c                   :    e Zd ZdZed             Zd Zd Zd ZdS )EmptyProjectzempty-project-typec                       t          d          S )NzEmpty projectr   r>   r*   r#   rN   zEmptyProject.get_name   s    !!!r*   c                     dS NrP   r>   rU   s    r#   rV   zEmptyProject.create_project       xr*   c                     dS re   r>   rU   s    r#   rX   zEmptyProject.open_project   rf   r*   c                     dS re   r>   rU   s    r#   r[   zEmptyProject.close_project   rf   r*   N)	r\   r]   r^   r   r`   rN   rV   rX   r[   r>   r*   r#   rb   rb      s_        	B" " \"        r*   rb   )r_   collectionsr   r   os.pathr!   r   r   spyder.api.translationsr   spyder.config.baser   $spyder.plugins.projects.utils.configr   r   r	   r
   r   r   rb   r>   r*   r#   <module>rn      s#   
 $ # # # # #            & % % % % % 8 8 8 8 8 8= = = = = = = = = = = = = =XL XL XL XL XL XL XL XLv    ?     r*   