
    z	id,                         S r SSKrSSKrSSKJr  SSKJr  \R                  R                  \R                  R                  S5      SS5      r
 " S S	5      rSS
 jrS rg)z1Utils for reading a user preference config files.    N)warn)
exceptions~z.qiskitzsettings.confc                   (    \ rS rSrSrSS jrS rSrg)
UserConfig   al  Class representing a user config file

The config file format should look like:

[default]
circuit_drawer = mpl
circuit_mpl_style = default
circuit_mpl_style_path = ~/.qiskit:<default location>
circuit_reverse_bits = True
circuit_idle_wires = False
transpile_optimization_level = 1
parallel = False
num_processes = 4
sabre_all_threads = true
min_qpy_version = 13

Nc                 p    Uc  [         U l        OXl        0 U l        [        R                  " 5       U l        g)zCreate a UserConfig

Args:
    filename (str): The path to the user config file. If one isn't
        specified, ~/.qiskit/settings.conf is used.
N)DEFAULT_FILENAMEfilenamesettingsconfigparserConfigParserconfig_parser)selfr   s     L/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/user_config.py__init__UserConfig.__init__+   s.     ,DM$M)668    c                 ,	   [         R                  R                  U R                  5      (       d  gU R                  R                  U R                  5        SU R                  R                  5       ;   Ga  U R                  R                  SSSS9nU(       a-  US;  a  [        R                  " U S35      eXR                  S'   U R                  R                  SSSS9nU(       aL  / SQnX#;  a5  S	R                  S
 U 5       5      n[        R                  " SU SU S35      eX R                  S'   U R                  R                  SSSS9nU(       a7  [        U[        5      (       d  [        U S3[        S5        XPR                  S'   U R                  R                  SSSS9nU(       a  UR!                  S5      nU HZ  n[         R                  R#                  [         R                  R%                  U5      5      (       a  MF  [        U S3[        S5        M\     XpR                  S'    U R                  R'                  SSSS9n	U	b  XR                  S'    U R                  R'                  SSSS9nUb  XR                  S'    U R                  R'                  SSSS9nUb  XR                  S'   U R                  R+                  SSSS9nUS:w  a0  US:  d  US:  a  [        R                  " S5      eXR                  S'   U R                  R'                  SSSS9nUb  XR                  S'   U R                  R+                  SS SS9nUS:w  a*  US::  a  [        R                  " S!5      eXR                  S '   U R                  R'                  SS"SS9nUb  UU R                  S"'   U R                  R+                  SS#SS9nU(       a/  US:  a  [        R                  " U S$35      eUU R                  S#'   ggg! [(         a'  n
[        R                  " S[        U
5       35      eSn
A
ff = f! [(         a'  n
[        R                  " S[        U
5       35      eSn
A
ff = f! [(         a'  n
[        R                  " S[        U
5       35      eSn
A
ff = f)%z?Read config file and parse the contents into the settings attr.Ndefaultcircuit_drawer)fallback)textmpllatexlatex_sourceautozi is not a valid circuit drawer backend. Must be either 'text', 'mpl', 'latex', 'latex_source', or 'auto'.state_drawer)reprr   r   r   qspherehintonblochz', 'c              3   $   #    U  H  ov   M     g 7fN ).0cs     r   	<genexpr>.UserConfig.read_config_file.<locals>.<genexpr>W   s     6VBUQqBUs   'z5' is not a valid state drawer backend. Choose from: 'circuit_mpl_stylezN is not a valid mpl circuit style. Must be a text string. Will not load style.   circuit_mpl_style_path:zT is not a valid circuit mpl style path. Correct the path in ~/.qiskit/settings.conf.circuit_reverse_bitsz5Value assigned to circuit_reverse_bits is not valid. circuit_idle_wiresz3Value assigned to circuit_idle_wires is not valid. circuit_measure_arrowsz7Value assigned to circuit_measure_arrows is not valid. transpile_optimization_levelr      z<%s is not a valid optimization level. Must be 0, 1, 2, or 3.parallelparallel_enablednum_processesz=%s is not a valid number of processes. Must be greater than 0sabre_all_threadsmin_qpy_versionz is not a valid QPY version.)ospathisfiler   r   readsectionsgetr   QiskitUserConfigErrorr   join
isinstancestrr   UserWarningsplitexists
expanduser
getboolean
ValueErrorgetint)r   r   r   valid_state_drawersvalid_choices_stringr+   r-   
cpath_listr;   r/   errr0   r1   r2   r6   r7   r8   r9   s                     r   read_config_fileUserConfig.read_config_file9   s   ww~~dmm,,.**3355!//33I?OZ^3_N!)YY$::)* +" " 
 3A./  --11)^VZ1[L'#  :+1;;6VBU6V+V($::L> *))=(>aA  1=n- !% 2 2 6 6. !7 ! !!"3S99,- .> >#	 6G12 &*%7%7%;%;3d &< &" &399#>
&D77>>"''*<*<T*BCC#f %L L'	 ' ;E67'+'9'9'D'D5 (E ($ $/8L45%)%7%7%B%B3d &C &" "-6H23)-););)F)F7$ *G *& &1:P67 ,0+=+=+D+D9B ,E ,( ,r1/!37SVW7W$::V  A]<=  $11<<Y
]a<b+4D01 !..55i[]5^M" A%$::W  2?o. !% 2 2 = =. !> ! !,5F12 #0077	CT_c7dO"Q&$::*++GH  4C/0 I 6F   66KCPSH:V    66I#c(T    66McRUhZX sH   ,O: P. Q" :
P+"P&&P+.
Q8"QQ"
R,"RR)r   r   r   r$   )__name__
__module____qualname____firstlineno____doc__r   rO   __static_attributes__r%   r   r   r   r      s    $9NCr   r   c           	         U=(       d    [         R                  " S[        5      nUc  SOUn[        U [        5      (       d  [
        R                  " S5      e1 SknUS;   a  X;  a  [
        R                  " U  S35      e[        R                  " 5       nUR                  U5        X&R                  5       ;  a  UR                  U5        UR                  X [	        U5      5         [        US5       nUR                  U5        SSS5        [!        U5      n	U	R#                  5         g! , (       d  f       N*= f! [         a+  n[
        R                  " S	U S
[	        U5       S35      eSnAff = f)a-  Adds or modifies a user configuration

It will add configuration to the currently configured location
or the value of file argument.

Only valid user config can be set in 'default' section. Custom
user config can be added in any other sections.

Changes to the existing config file will not be reflected in
the current session since the config file is parsed at import time.

Args:
    key (str): name of the config
    value (obj): value of the config
    section (str, optional): if not specified, adds it to the
        `default` section of the config file.
    file_path (str, optional): the file to which config is added.
        If not specified, adds it to the default config file or
        if set, the value of `QISKIT_SETTINGS` env variable.

Raises:
    QiskitUserConfigError: if the config is invalid
QISKIT_SETTINGSNr   zKey must be string type>
   r5   r7   r   r9   r+   r8   r0   r/   r-   r2   )Nr   z is not a valid user config.wzUnable to load the config file z
. Error: 'r*   )r:   getenvr
   rB   rC   r   r@   r   r   r=   r>   add_sectionsetopenwriteOSErrorr   rO   )
keyvaluesection	file_pathr   valid_configconfigcfgfileexuser_configs
             r   
set_configri      s8   0 JBII&79IJH"?iGc3../HIIL ##"22cU:V3WXX&&(F
KKoo''7#
JJwSZ(
(C GLL! ! X&K  " !  
..-hZz#b'!L
 	

s6   %D8 1D'D8 '
D51D8 5D8 8
E-&E((E-c                  (   [         R                  " SS5      R                  5       S:X  a  0 $ [         R                  " S[        5      n [         R                  R                  U 5      (       d  0 $ [        U 5      nUR                  5         UR                  $ )a  Read the config file from the default location or env var.

It will read a config file at the location specified by the ``QISKIT_SETTINGS`` environment
variable if set, or ``$HOME/.qiskit/settings.conf`` if not.

If the environment variable ``QISKIT_IGNORE_USER_SETTINGS`` is set to the string ``TRUE``, this
will return an empty configuration, regardless of all other variables.

Returns:
    dict: The settings dict from the parsed config file.
QISKIT_IGNORE_USER_SETTINGSfalsetruerX   )	r:   rZ   lowerr
   r;   r<   r   rO   r   )r   rh   s     r   
get_configro     sr     
yy.8>>@FJ	yy*,<=H77>>(##	X&K  "r   )NN)rU   r   r:   warningsr   qiskitr   r;   rA   rG   r
   r   ri   ro   r%   r   r   <module>rr      sW    8  	  77<< 2 23 7OT oC oCdA#H r   