
    g4                        d dl Z d dlZd dlZd dlmZmZmZmZ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mZ  ej.                  e      Zd	 Zed
        Zd Zd Zd Zd Zd Z 	 	 dde
e!   de
e!   ddfdZ"y)    N)PIPECalledProcessErrorPopenSubprocessError
check_call)Optional)Requirement)default_instrumentations)	libraries)__version__)PackageNotFoundErrorversionc                      d fd	}|S )Nc                     	 | r |       S         S # t         $ r>}t        |dd       }|rddj                  |       d}| r d|  d}t              d }~ww xY w)NcmdzError calling system command " "z for package ")r   getattrjoinRuntimeError)packageexpr   msgfuncs       \/var/www/openai/venv/lib/python3.12/site-packages/opentelemetry/instrumentation/bootstrap.pywrapperz_syscall.<locals>.wrapper-   ss    
	$G}$6M 	$#ud+C6sxx}oQG^G9A6s##	$s   	  	A9AAN )r   r   s   ` r   _syscallr   ,   s    $ N    c           
          	 t        t        j                  dddddd| g       y # t        $ r}t	        |       Y d }~y d }~ww xY w)N-mpipinstallz-Uz--upgrade-strategyzonly-if-needed)r   sys
executabler   print)r   errors     r   _sys_pip_installr)   =   sK    $ 		
  es   !$ 	A=Ac                 2   t        t        j                  dddgt              5 }|j	                         d   j                         }|j                         }ddd       | D ])  }|D ]"  }|j                         v st        d        + y# 1 sw Y   8xY w)aw  Ensures none of the instrumentations have dependency conflicts.
    Clean check reported as:
    'No broken requirements found.'
    Dependency conflicts are reported as:
    'opentelemetry-instrumentation-flask 1.0.1 has requirement opentelemetry-sdk<2.0,>=1.0, but you have opentelemetry-sdk 0.5.'
    To not be too restrictive, we'll only check for relevant packages.
    r"   r#   check)stdoutr   NzDependency conflict found: )r   r%   r&   r   communicatedecodelowerr   )r   
check_pipe	pip_checkpip_check_lowerpackage_tupr   s         r   
_pip_checkr4   Q   s     
	ug.t
	**,Q/668	#//+	

 !"G}}/1"%@#LMM # !
 
s   2BBc                     t        |       } 	 t        | j                        }| j                  j                  |      st        j                  d| |       yy# t        $ r Y yw xY w)NFzRinstrumentation for package %s is available but version %s is installed. Skipping.T)r	   r   namer   	specifierfilterloggerwarning)reqdist_versions     r   _is_installedr=   d   sf    
c
Csxx( ==-6		
    s   A 	A"!A"c              #   \   K   | D ]  }|  |D ]  }t        |d         s|d     y w)Nlibraryinstrumentation)r=   r
   r   libs      r   _find_installed_librariesrC   w   s9     '	 ( Y('(( s   ,
,c                     t         j                  t        j                         t	        dj                  t        | |                   y )N
)r9   setLevelloggingERRORr'   r   rC   )r
   r   s     r   _run_requirementsrI      s1    
OOGMM"			%&>	J	
r    c                 R    t        | |      D ]  }t        |        t        |       y r   )rC   r)   r4   rA   s      r   _run_installrK      s%    ()A9M Nyr    r
   r   returnc                 (   d}d}t        j                  d      }|j                  ddddt        z   	       |j                  d
d||g|d       |j	                         }|t
        }| t        } |t        |t        i|j                     } || |       y )Nr$   requirementsz
        opentelemetry-bootstrap detects installed libraries and automatically
        installs the relevant instrumentation packages for them.
        )descriptionz	--versionzprint version informationr   z	%(prog)s )helpactionr   z-az--actiona  
        install - uses pip to install the new requirements using to the
                  currently active site-package.
        requirements - prints out the new requirements to stdout. Action can
                       be piped and appended to a requirements.txt file.
        )choicesdefaultrP   )
argparseArgumentParseradd_argumentr   
parse_argsgen_librariesgen_default_instrumentationsrK   rI   rQ   )r
   r   action_installaction_requirementsparserargsr   s          r   runr^      s     N($$F (k)	   !45#   D!	'#?  	. kkC  ),r    )NN)#rT   rG   r%   
subprocessr   r   r   r   r   typingr   packaging.requirementsr	   +opentelemetry.instrumentation.bootstrap_genr
   rY   r   rX   %opentelemetry.instrumentation.versionr   &opentelemetry.util._importlib_metadatar   r   	getLogger__name__r9   r   r)   r4   r=   rC   rI   rK   listr^   r   r    r   <module>rh      s      
   . >
 
		8	$" 
 
&N&&) 04 $+-&tn+-~+- 
+-r    