
    iC                         d Z ddlZddlZddlmZ dedee   fdZdedee   fdZdedee   fd	Zd
 Z	e
dk(  r e	        yy)z
Script to identify legacy imports that were previously available via star imports.

This script analyzes the codebase to find all imports that were previously available
via star imports but are no longer imported at the top level.
    N)Set	file_pathreturnc                    t        | d      5 }|j                         }ddd       	 t        j                        }t               }t        j                  |      D ]Z  }t        |t        j                        s|j                  d   j                  dk(  s;|j                  }|sJ|j                  |       \ |S # 1 sw Y   xY w# t        $ r t        d|         t               cY S w xY w)z
    Find all star imports in a file.

    Args:
        file_path: Path to the file to analyze.

    Returns:
        Set of module names that are imported with star imports.
    rNWarning: Could not parse r   *)openreadastparseSyntaxErrorprintsetwalk
isinstance
ImportFromnamesnamemoduleadd)r   fcontenttreestar_importsnodemodule_names          t/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pinecone/utils/find_legacy_imports.pyfind_star_importsr      s     
i	 &&(yy!
 5L .dCNN+

10B0Bc0I++K  -	. # 
  ))56us   B:C :C!C*)C*c                 f   t        | d      5 }|j                         }ddd       	 t        j                        }t               }t        j                  |      D ]  }t        |t        j                        r-|j                  D ]  }|j                  |j                          Jt        |t        j                        se|j                  D ]-  }|j                  dk7  s|j                  |j                         /  |S # 1 sw Y   xY w# t        $ r t        d|         t               cY S w xY w)z
    Find all names that are imported in a file.

    Args:
        file_path: Path to the file to analyze.

    Returns:
        Set of imported names.
    r   Nr   r	   )r
   r   r   r   r   r   r   r   r   Importr   r   r   r   )r   r   r   r   imported_namesr   r   s          r   find_imported_namesr#   ,   s    
i	 &&(yy!
 UN 2dCJJ'

 .""499-.cnn-

 299#"&&tyy122 ) 
  ))56us   D D  D	!D0/D0module_pathc                     	 t        | dg      }t        t        |            S # t        $ r t	        d|         t               cY S w xY w)z
    Find all names that are exported by a module.

    Args:
        module_path: Path to the module to analyze.

    Returns:
        Set of exported names.
    r	   )fromlistzWarning: Could not import )
__import__r   dirImportErrorr   )r$   r   s     r   find_module_exportsr*   M   sJ    K3%83v; *;-89us   !$ !AAc            
         t         j                  j                  t         j                  j                  t         j                  j                  t                          } t         j                  j                  | d      }t        |      }t        |      }i }|D ]  }t        |      ||<    g }t        j                  |       D ]`  \  }}}	|	D ]U  }
|
j                  d      s|
j                  d      r'|j                  t         j                  j                  ||
             W b t               }|D ]  }
|j                  t        |
              i }|j                         D ]   \  }}|D ]  }||v s||vs||f|d| <    " t!        d       t#        |j                               D ]  \  }\  }}t!        d| d| d| d	        t!        d
       y)z/
    Main function to find legacy imports.
    z__init__.pyz.py__z	pinecone.zLEGACY_IMPORTS = {z    'z': ('z', 'z'),}N)ospathdirnameabspath__file__joinr   r#   r*   r   endswith
startswithappendr   updateitemsr   sorted)package_root	init_filer   r"   module_exportsr   package_filesroot_filesfilepackage_importslegacy_importsexportsexportlegacy_namer$   actual_names                     r   mainrH   _   s   
 77??277??277??83L#MNL \=9I %Y/L )3N N# G&9+&F{#G M'',/ ?a 	?D}}U#DOOD,A$$RWW\\$%=>	?? eO :2489: N . 4 4 6 MW 	MF(V>-I8CV7L6(34	MM 

39.:N:N:P3Q K//k;k]%}DSIJK	#J    __main__)__doc__r   r.   typingr   strr   r#   r*   rH   __name__ rI   r   <module>rP      su     	  S <3 3s8 BS SX $,^ zF rI   