
    Ki_                        d 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dl	m
Z
 ddlmZ ddlmZ dd	lmZ  ee      Zd
edeeef   fdZdededz  dee   dz  dee   dz  dedz  deeedz  eee   eeef   dz  f   fdZy)z&Shared utilities for install commands.    N)Path)dotenv_values)ValidationError)print)
get_logger)MCPServerConfig)FileSystemSourceenv_varreturnc                     d| vr$t        d|  d       t        j                  d       | j                  dd      \  }}|j	                         |j	                         fS )z6Parse environment variable string in format KEY=VALUE.=z1[red]Invalid environment variable format: '[bold]z![/bold]'. Must be KEY=VALUE[/red]   )r   sysexitsplitstrip)r
   keyvalues      f/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/fastmcp/cli/install/shared.pyparse_env_varr      sW    
'?yHij	
 	sA&JC99;%%    server_specserver_namewith_packagesenv_varsenv_filec                 d  K   |xs g }|xs g }d}| j                  d      rt        |       j                         }|j                         s$t	        d| d       t        j                  d       	 t        |      5 }t        j                  |      }ddd       dv r!t	        d       t        j                  d       nat        j                  |      }|j                  j                  r6t        |j                  j                        }	t        t        ||	z               }nt%        | 	      }t        |
      }t        |j&                  j(                        j                         }t+        |j&                  d      r|j&                  j,                  nd}t.        j1                  dt3        |      |||d       |}d}|s/	 |j&                  j5                          d{   }|j6                  }d}|s|rRi }|r4	 |t?        |      jA                         D ci c]  \  }}|	|| c}}z  }|D ]  }tE        |      \  }}|||<    |||||fS # 1 sw Y   xY w# t        j                   t"        f$ r/}
t	        d|
 d       t        j                  d       Y d}
~
dd}
~
ww xY w7 # t8        t:        f$ r8}
t.        j1                  ddt3        |
      i       |j<                  }Y d}
~
d}
~
ww xY wc c}}w # tB        $ r.}
t	        d|
 d       t        j                  d       Y d}
~
d}
~
ww xY ww)zProcess common arguments shared by all install commands.

    Handles both fastmcp.json config files and traditional file.py:object syntax.
    Nz.jsonz#[red]Configuration file not found: z[/red]r   
mcpServersz=[red]MCPConfig files are not supported for installation[/red]z![red]Invalid configuration file: )path)source
entrypointzInstalling server)filer   server_objectr   )extrazFCould not import server (likely missing dependencies), using file nameerrorz[red]Failed to load .env file: )#endswithr   resolveexistsr   r   r   openjsonloadr   	from_fileenvironmentdependencieslistsetJSONDecodeErrorr   r	   r    r   hasattrr!   loggerdebugstrload_servernameImportErrorModuleNotFoundErrorstemr   items	Exceptionr   )r   r   r   r   r   configconfig_pathfdataconfig_packageser    r"   r#   r7   serverenv_dictkvr
   r   r   s                         r   process_common_argsrG      s     "'RM~2HFG$;'//1!!#7}FKLHHQK	k" $ayy|$ t#UV )22;? %%22&*6+=+=+J+J&KO$(]_-L)M$NM "{3 / ""#++-D$+FMM<$H  d  LLI&**	
   DF	!==4466F;;D '+H8%28%<%B%B%D!QAqD    	"G&w/JC!HSM	" mX==W$ $" $$o6 	5aS?@HHQKK	< 701 	LLXA'   99D	  7s&ABs   A-L00I ;IBI BL0?J& J$J& -
L08K6 
K0 K0%K6 +!L0II J!2$JL0J!!L0$J& &K-5.K(#L0(K--L00K6 6	L-?$L(#L0(L--L0)__doc__r*   r   pathlibr   dotenvr   pydanticr   richr   fastmcp.utilities.loggingr   #fastmcp.utilities.mcp_server_configr   9fastmcp.utilities.mcp_server_config.v1.sources.filesystemr	   __name__r3   r5   tupler   r/   dictrG    r   r   <module>rT      s    ,  
    $  0 ? V	H	&3 &5c? &b>b>tb> 9t#b> 3i$	b>
 Tkb> 4tS$s)T#s(^d-BBCb>r   