o
    -wi                    @  s  U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZmZmZmZmZmZmZmZmZ d dlmZmZmZ d dlmZmZmZmZ d dl m!Z!m"Z"m#Z# d dl$m%Z% d dl&Z&d d	l&m'Z'm(Z( d d
l)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 ddl3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z: de;d< e*rd dl<m=Z=m>Z> d"ddZ?nd dl m@Z@ d"ddZ?d#ddZAG dd de!d d!ZBdS )$    )annotationsN)datetime)	AnyCallableDictListLiteralOptionalSequenceTupleUnion)quoteunquote	urlencode)	BoolValueDoubleValue
Int32ValueStringValue)	BaseModel
ConfigDictField)Self)envutil)IS_PYDANTIC_V2AliasChoicescomputed_fieldfield_validatormodel_validator
UsageError)wandb_settings_pb2   )apikeycredentialsipython)GitRepo)	RunMomentzCallable[[str], None]validate_url)SchemaValidatorcore_schemaurlstrreturnNonec                 C  s$   t tjddgdd}||  dS )zValidate a URL string.httphttpsT)allowed_schemesstrictN)r)   r*   
url_schemavalidate_python)r+   url_validator r6   U/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/sdk/wandb_settings.pyr(   /   s   )root_validatorc                 C  sF  ddl m}m} | du rdS d}d}d}d| d | d	 | d
 }d| d }d| d }d| | d| d d }	td| d | d |	 d tj}
ddh}td}| dd  }|| }|| }|j	dkrtt
d|  || r}t
d||vrt
d|
| st
|  d|jdu st|jdkrt
ddS ) ag  Validate the base url of the wandb server.

        param value: URL to validate

        Based on the Django URLValidator, but with a few additional checks.

        Copyright (c) Django Software Foundation and individual contributors.
        All rights reserved.

        Redistribution and use in source and binary forms, with or without modification,
        are permitted provided that the following conditions are met:

            1. Redistributions of source code must retain the above copyright notice,
               this list of conditions and the following disclaimer.

            2. Redistributions in binary form must reproduce the above copyright
               notice, this list of conditions and the following disclaimer in the
               documentation and/or other materials provided with the distribution.

            3. Neither the name of Django nor the names of its contributors may be used
               to endorse or promote products derived from this software without
               specific prior written permission.

        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
        ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
        WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
        ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
        LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
        ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
        SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        r   )urlparseurlsplitNu   ¡-￿zo(?:0|25[0-5]|2[0-4][0-9]|1[0-9]?[0-9]?|[1-9][0-9]?)(?:\.(?:0|25[0-5]|2[0-4][0-9]|1[0-9]?[0-9]?|[1-9][0-9]?)){3}z\[[0-9a-f:.]+\]z[a-zz0-9](?:[a-zz0-9-]{0,61}[a-zz0-9])?z(?:\.(?!-)[a-zz0-9-]{1,63}(?<!-))*z\.(?!-)(?:[a-zz%-]{2,63}|xn--[a-z0-9]{1,59})(?<!-)\.?(z)?z|localhost)z5^(?:[a-z0-9.+-]*)://(?:[^\s:@/]+(?::[^\s:@/]*)?@)?(?:|z#)(?::[0-9]{1,5})?(?:[/?#][^\s]*)?\Zr/   r0   z	
z:// zInvalid URL: z$URL cannot contain unsafe charactersz URL must start with `http(s)://`z is not a valid server address   zhostname is invalid)urllib.parser9   r:   recompile
IGNORECASE	frozensetsplitlowernetloc
ValueErrorintersectionsearchhostnamelen)r+   r9   r:   ulipv4_reipv6_rehostname_re	domain_retld_rehost_reregexschemesunsafe_charsscheme	split_url
parsed_urlr6   r6   r7   r(   ;   sb   #
	


argsc                  G  s   t jt jj|  S )z-Join path and apply os.path.expanduser to it.)ospath
expanduserjoin)rY   r6   r6   r7   _path_convert   s   r^   c                   @  s"  e Zd ZU dZedddddZdZded< 	 dZded	< 	 d
Z	ded< 	 d
Z
ded< 	 d
Zded< 	 dZded< 	 d
Zded< 	 d
Zded< 	 edddZded< 	 dZded< 	 edd dZded< 	 dZded < 	 dZded!< 	 dZded"< 	 d
Zded#< 	 d
Zded$< 	 d
Zded%< 	 d
Zded&< 	 dZded'< 	 d
Zd(ed)< 	 d
Zded*< 	 d+Zded,< 	 d
Zded-< 	 d
Zded.< 	 d/Z d0ed1< 	 d
Z!ded2< 	 d
Z"ded3< 	 d
Z#ded4< 	 d
Z$ded5< 	 d6Z%d7ed8< 	 d9Z&d:ed;< 	 dZ'ded<< 	 d
Z(ded=< 	 d
Z)d>ed?< 	 dZ*ded@< 	 dZ+dedA< 	 d
Z,dedB< 	 d
Z-dCedD< 	 edEddZ.dFedG< 	 d
Z/dedH< 	 d
Z0dedI< 	 d
Z1dedJ< 	 d
Z2dedK< 	 d
Z3dedL< 	 dZ4dedM< 	 dNZ5dOedP< 	 dZ6dedQ< 	 d
Z7dRedS< 	 d
Z8d(edT< 	 dZ9dedU< 	 edVd dZ:dedW< 	 d
Z;dedX< 	 d
Z<dedY< 	 d
Z=dedZ< 	 d
Z>ded[< 	 d
Z?ded\< 	 d
Z@d]ed^< 	 dZAded_< 	 d
ZBd`eda< 	 d
ZCdedb< 	 d
ZDd`edc< 	 d
ZEd`edd< 	 dZFdede< 	 dZGdedf< 	 dZHdedg< 	 dZIdedh< 	 d
ZJdedi< 	 d
ZKd`edj< 	 dkZLd0edl< 	 dmZMd0edn< 	 d
ZNdedo< 	 d
ZOdedp< 	 edqd dZPdedr< 	 d
ZQd`eds< 	 dZRdedt< 	 d
ZSdedu< 	 dZTdedv< 	 dZUdedw< 	 dZVdedx< 	 dZWdedy< 	 dZXdedz< 	 d
ZYded{< 	 d
ZZded|< 	 d
Z[d}ed~< 	 d
Z\d}ed< 	 d
Z]dCed< 	 d
Z^d}ed< 	 d
Z_dCed< 	 d
Z`dCed< 	 d
ZadCed< 	 d
Zbd}ed< 	 d
ZcdCed< 	 d
ZddCed< 	 d
ZedCed< 	 d
Zfded< 	 d
Zgd`ed< 	 d
Zhd`ed< 	 d
Zid}ed< 	 d
ZjdCed< 	 d
ZkdCed< 	 d
ZldCed< 	 dZmd:ed< 	 d
Znded< 	 d
Zoded< 	 d
Zpded< 	 d
Zqded< 	 d
Zrd}ed< 	 d
Zsd}ed< 	 etjuZvd0ed< 	 d
Zwd}ed< 	 edexdddZyded< 	 d
Zzded< 	 d
Z{ded< 	 dZ|ded< 	 dZ}ded< 	 dZ~ded< 	 d
Zded< 	 dZd:ed< 	 dZded< 	 d
ZdCed< 	 e Zd0ed< 	 eddZd:ed< 	 d
Zded< 	 d
Zded< 	 d
Zded< 	 d
Zded< 	 d
Zded< 	 dZded< 	 d
Zd}ed< 	 d
Zd}ed< 	 d
Zd}ed< 	 d
Zded< 	 d
Zded< 	 dZd0ed< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 eddÍeddń Zer#eddÍdddʄZeddÍdd̄ Znedd͍eddʄ Zedd͍edd̄ ZedddÍeddф ZedddÍeddӄ ZedddÍeddՄ ZedddÍeddׄ Zed{ddÍeddل Zed|ddÍeddۄ ZedddÍedd݄ ZedddÍedd߄ Zed)ddÍedddZed3ddÍedd Zed4ddÍedd Zed8ddÍedd ZedIddÍedd ZedJddÍedd ZedKddÍedd ZedLddÍedd ZedSddÍedd ZedTddÍedddZedWddÍedd ZedYddÍedd ZedbddÍedd ZedddÍedd ZediddÍedd ZedddÍedd ZedddÍed d ZedddÍedd ZedddÍedd ZedddÍedd ZedddÍedd	 ZedddÍed
d ZedoddÍedd ZedpddÍedd ZeedddZeedddZeedddZeedddZeedddZeedddZeedddZeeddd Zeedd!d"Zeedd#d$Zeedd%d&Zeedd'd(Zeedd)d*Zeedd+d,Zeedd-d.Zeedd/d0Zeedd1d2Zeedd3d4Zeedd6d7Zeedd8d9Zeedd:d;Zeedd<d=Zeedd>d?Zeedd@dAZeeddBdCZeeddDdEZeeddFdGZeeddHdIZeeddKdLZeeddMdNZeeddOdPZeeddQdRZeeddSdTZeeddUdVZeeddWdXZeeddYdZZeedd[d\Zd]d^ Zd_d` ZddcddZdedf ZddidjZddkdlZddndoZddpdqZedddsdtZedddxdyZddzd{Zdd|d}ZedddZesdd Zdd ZedddZd
S d
S (  Settingsa  Settings for the W&B SDK.

    This class manages configuration settings for the W&B SDK,
    ensuring type safety and validation of all settings. Settings are accessible
    as attributes and can be initialized programmatically, through environment
    variables (WANDB_ prefix), and via configuration files.

    The settings are organized into three categories:
    1. Public settings: Core configuration options that users can safely modify to customize
       W&B's behavior for their specific needs.
    2. Internal settings: Settings prefixed with 'x_' that handle low-level SDK behavior.
       These settings are primarily for internal use and debugging. While they can be modified,
       they are not considered part of the public API and may change without notice in future
       versions.
    3. Computed settings: Read-only settings that are automatically derived from other settings or
       the environment.
    forbidTalways)extravalidate_defaultuse_attribute_docstringsrevalidate_instancesboolallow_offline_artifactsFallow_val_changeNz+Optional[Literal['allow', 'must', 'never']]	anonymousOptional[str]api_keyzOptional[Dict[str, str]]azure_account_url_to_access_keyhttps://api.wandb.air,   base_urlcode_dirzOptional[Sequence[str]]config_pathsauto)defaultrc   zBLiteral['auto', 'off', 'wrap', 'redirect', 'wrap_raw', 'wrap_emu']consoleconsole_multipartc                   C  s
   t tjS N)r,   r$   DEFAULT_WANDB_CREDENTIALS_FILEr6   r6   r6   r7   <lambda>   s   
 zSettings.<lambda>)default_factorycredentials_filedisable_codedisable_gitdisable_job_creationdockeremailentityorganizationforceOptional[RunMoment]	fork_from
git_commitorigin
git_remotegit_remote_urlgit_root   intheartbeat_secondshost
http_proxyhttps_proxyidentity_token_filer6   zSequence[str]ignore_globsg     V@floatinit_timeoutinsecure_disable_ssljob_namez.Optional[Literal['repo', 'artifact', 'image']]
job_sourcelabel_disablelaunchlaunch_config_pathzOptional[float]login_timeoutonlinezCLiteral['online', 'offline', 'shared', 'disabled', 'dryrun', 'run']modenotebook_nameprogramprogram_abspathprogram_relpathprojectquietrr   zSUnion[Literal['default', 'return_previous', 'finish_previous', 'create_new'], bool]reinitreloginz3Optional[Literal['allow', 'must', 'never', 'auto']]resumeresume_fromresumedc                   C  s   t jt  S ru   )rZ   r[   abspathgetcwdr6   r6   r6   r7   rw     s    root_dir	run_grouprun_idrun_job_typerun_name	run_noteszOptional[Tuple[str, ...]]run_tagssagemaker_disablezOptional[bool]	save_codesettings_systemshow_colors
show_emojishow_errors	show_infoshow_warningssilentstart_methodr2   <   summary_timeout   summary_warningssweep_idsweep_param_pathc                   C  s   t  dkrdS dS )NWindowsFTplatformsystemr6   r6   r6   r7   rw   
  s    symlinksync_tensorboard%table_raise_on_max_row_limit_exceededusernamex_cli_only_modex_disable_metax_disable_statsx_disable_viewerx_disable_machine_infox_executablex_extra_http_headerszOptional[int]x_file_stream_max_bytesx_file_stream_max_line_bytesx_file_stream_transmit_intervalx_file_stream_retry_max$x_file_stream_retry_wait_min_seconds$x_file_stream_retry_wait_max_secondsx_file_stream_timeout_secondsx_file_transfer_retry_max&x_file_transfer_retry_wait_min_seconds&x_file_transfer_retry_wait_max_secondsx_file_transfer_timeout_secondsx_files_dirx_flow_control_customx_flow_control_disabledx_graphql_retry_max x_graphql_retry_wait_min_seconds x_graphql_retry_wait_max_secondsx_graphql_timeout_secondsg       @x_internal_check_processx_jupyter_namex_jupyter_pathx_jupyter_rootx_labelx_live_policy_rate_limitx_live_policy_wait_timex_log_levelx_network_buffer	x_primaryx_primary_node)rr   validation_alias	x_proxiesx_runqueue_item_idx_save_requirementsx_server_side_derived_summary!x_server_side_expand_glob_metricsx_service_transportg      >@x_service_waitx_skip_transaction_logx_start_timex_stats_pidg      .@)rr   x_stats_sampling_interval"x_stats_neuron_monitor_config_pathx_stats_dcgm_exporterx_stats_open_metrics_endpointsz5Union[Dict[str, Dict[str, str]], Sequence[str], None]x_stats_open_metrics_filters!x_stats_open_metrics_http_headers)/x_stats_disk_pathsx_stats_cpu_countx_stats_cpu_logical_countx_stats_gpu_countx_stats_gpu_typezOptional[Sequence[int]]x_stats_gpu_device_idsr   x_stats_buffer_sizezhttp://169.254.169.254#x_stats_coreweave_metadata_base_urlz/api/v2/cloud-init/meta-data#x_stats_coreweave_metadata_endpointx_stats_track_process_treex_syncx_update_finish_statebeforer   c                 C  s:   i }|D ]}| dr|| |d| < q|| ||< q|S )zCheck if a private field is provided and assign to the corresponding public one.

        This is a compatibility layer to handle previous versions of the settings.
        _x)
startswith)clsvalues
new_valueskeyr6   r6   r7   catch_private_settings  s   
zSettings.catch_private_settingsafterr-   r   c                 C  s.   t dd | j| j| jfD dkrtd| S )Nc                 s  s    | ]}|d uV  qd S ru   r6   .0or6   r6   r7   	<genexpr>  s
    
GSettings.validate_mutual_exclusion_of_branching_args.<locals>.<genexpr>r"   ``fork_from`, `resume`, or `resume_from` are mutually exclusive. Please specify only one of them.)sumr   r   r   rG   selfr6   r6   r7   +validate_mutual_exclusion_of_branching_args  s   z4Settings.validate_mutual_exclusion_of_branching_argsc                 C  s   | j r
| jr
td| S )N+Cannot skip transaction log in offline mode)_offliner   rG   r  r6   r6   r7   validate_skip_transaction_log  s   z&Settings.validate_skip_transaction_log)prec                   s&   t  fdddD dkrtd S )Nc                 3  s    | ]
}  |d uV  qd S ru   )getr  r  r6   r7   r    s
    
r  )r   r   r   r"   r  )r  rG   r  r  r6   r$  r7   r    s   c                 C  s    | dr| drtd|S )Nr   r   r  )r#  rG   r%  r6   r6   r7   r!    s   c                 C  s(   |d urt |t | krtd|S )Nz+API key cannot start or end with whitespace)rK   stripr    r  valuer6   r6   r7   validate_api_key  s   zSettings.validate_api_keyc                 C  sR   t | td|rd|vrt| dtd|r$|ds$td|dS )Nz.*wandb\.ai[^\.]*$zapi.zB is not a valid server address, did you mean https://api.wandb.ai?r0   z3http is not secure, please use https://api.wandb.air   )r(   r@   matchrG   r  rstripr'  r6   r6   r7   validate_base_url  s   
zSettings.validate_base_urlc                 C     t |tjr
t|S |S ru   
isinstancepathlibPathr,   r'  r6   r6   r7   validate_code_dir     zSettings.validate_code_dirc                 C  s   |dkr|S dS )Nrq   wrapr6   r  r(  r  r6   r6   r7   validate_console  s   zSettings.validate_consolec                 C  r-  ru   r.  r'  r6   r6   r7   validate_x_executable  r3  zSettings.validate_x_executablec                 C     t |tr
t|S |S ru   r/  r,   jsonloadsr'  r6   r6   r7   validate_x_extra_http_headers     

z&Settings.validate_x_extra_http_headersc                 C  s   |d ur|dk rt d|S )Nr"   z1File stream max line bytes must be greater than 0)rG   r'  r6   r6   r7   #validate_file_stream_max_line_bytes  s   z,Settings.validate_file_stream_max_line_bytesc                 C  r-  ru   r.  r'  r6   r6   r7   validate_x_files_dir%  r3  zSettings.validate_x_files_dirc                 C  sN   |  |}t|dr|j}n|}|r%|dd ur%|d|jkr%td|S )Ndatar   zProvided `run_id` is the same as the run to `fork_from`. Please provide a different `run_id` or remove the `run_id` argument. If you want to rewind the current run, please use `resume_from` instead._runmoment_preprocessorhasattrr@  r#  runrG   r  r(  r  
run_momentr6   r6   r7   validate_fork_from-  s   

zSettings.validate_fork_fromc                 C     |d u rd S t | |dS Nr   r(   r+  r'  r6   r6   r7   validate_http_proxyE     
zSettings.validate_http_proxyc                 C  rH  rI  rJ  r'  r6   r6   r7   validate_https_proxyM  rL  zSettings.validate_https_proxyc                 C  s   t |ts	t|S |S ru   )r/  tupler'  r6   r6   r7   validate_ignore_globsU     zSettings.validate_ignore_globsc                 C  r-  ru   r.  r'  r6   r6   r7   validate_programZ  r3  zSettings.validate_programc                 C  r-  ru   r.  r'  r6   r6   r7   validate_program_abspathb  r3  z!Settings.validate_program_abspathc                 C  r-  ru   r.  r'  r6   r6   r7   validate_program_relpathj  r3  z!Settings.validate_program_relpathc              	     sp    d u rd S t d}t dkrtd d fdd|D }|r6td dd|d	d| S )
Nz/\#?%:   zInvalid project name z: exceeded 128 charactersc                   s   h | ]}| v r|qS r6   r6   r  charr(  r6   r7   	<setcomp>z      z,Settings.validate_project.<locals>.<setcomp>z: cannot contain characters ,z, found )listrK   r    r]   )r  r(  r  invalid_chars_listinvalid_charsr6   rW  r7   validate_projectr  s   zSettings.validate_projectc                 C  s   |du rd S |du rdS |S )NFTrq   r6   r'  r6   r6   r7   validate_resume  s
   zSettings.validate_resumec                 C  sN   |  |}t|dr|j}n|}|r%|dd ur%|d|jkr%td|S )Nr@  r   zGBoth `run_id` and `resume_from` have been specified with different ids.rA  rE  r6   r6   r7   validate_resume_from  s   

zSettings.validate_resume_fromc                 C  r-  ru   r.  r'  r6   r6   r7   validate_root_dir  r3  zSettings.validate_root_dirc                   s|   |d u rd S t |dkrtdt |t | krtdt| s(tdd t fdd|D r<td  |S )	Nr   zRun ID cannot be emptyz*Run ID cannot start or end with whitespacez%Run ID cannot contain only whitespacez:;,#?/'c                 3  s    | ]}| v V  qd S ru   r6   rU  reserved_charsr6   r7   r    s    z+Settings.validate_run_id.<locals>.<genexpr>z&Run ID cannot contain the characters: )rK   r    r&  rf   anyr5  r6   rb  r7   validate_run_id  s   zSettings.validate_run_idc                 C  s,   |d u rd S t |tjrtt|S t|S ru   )r/  r0  r1  r,   r^   r'  r6   r6   r7   validate_settings_system  s
   z!Settings.validate_settings_systemc                 C     |dk rt d|S )Nr   z$Service wait time cannot be negativer   r'  r6   r6   r7   validate_service_wait     zSettings.validate_service_waitc                 C  s   |d u r|S t jddd |S )Nz`start_method` is deprecated and will be removed in a future version of wandb. This setting is currently non-functional and safely ignored.F)repeat)wandbtermwarnr'  r6   r6   r7   validate_start_method  s   zSettings.validate_start_methodc                 C  s   t | |dS rI  rJ  r'  r6   r6   r7   ,validate_x_stats_coreweave_metadata_base_url  s   
z5Settings.validate_x_stats_coreweave_metadata_base_urlc                 C  r8  ru   r9  r'  r6   r6   r7   validate_x_stats_gpu_device_ids  r=  z(Settings.validate_x_stats_gpu_device_idsc                 C  r-  ru   r.  r'  r6   r6   r7   +validate_x_stats_neuron_monitor_config_path  r3  z4Settings.validate_x_stats_neuron_monitor_config_pathc                 C  r8  ru   r9  r'  r6   r6   r7   %validate_stats_open_metrics_endpoints  r=  z.Settings.validate_stats_open_metrics_endpointsc                 C  r8  ru   r9  r'  r6   r6   r7   #validate_stats_open_metrics_filters  r=  z,Settings.validate_stats_open_metrics_filtersc                 C  r8  ru   r9  r'  r6   r6   r7   (validate_stats_open_metrics_http_headers  r=  z1Settings.validate_stats_open_metrics_http_headersc                 C  rg  )Ng?z7Stats sampling interval cannot be less than 0.1 secondsr   r'  r6   r6   r7    validate_stats_sampling_interval  ri  z)Settings.validate_stats_sampling_intervalc                 C  sT   |d u rd S t |dkrtdt |t | krtdt| s(td|S )Nr   zSweep ID cannot be emptyz,Sweep ID cannot start or end with whitespacez'Sweep ID cannot contain only whitespace)rK   r    r&  rf   r'  r6   r6   r7   validate_sweep_id  s   zSettings.validate_sweep_idc                 C  r-  ru   r.  r'  r6   r6   r7   validate_sweep_param_path  r3  z"Settings.validate_sweep_param_path	List[str]c                 C  s   | j s
tjdd  S g S )Nr"   )_jupytersysargvr  r6   r6   r7   _args"  s   zSettings._argsc                 C  s(   ddl m} | }|rt|dsdS dS )z0Check if we are running in a lambda environment.r   )get_lambda_bootstraphandle_event_requestFT)"sentry_sdk.integrations.aws_lambdar|  rC  )r  r|  lambda_bootstrapr6   r6   r7   _aws_lambda)  s   zSettings._aws_lambdac                 C  s   | j r	| | j S dS )aT  The relative path from the current working directory to the code path.

        For example, if the code path is /home/user/project/example.py, and the
        current working directory is /home/user/project, then the code path local
        is example.py.

        If couldn't find the relative path, this will be an empty string.
        N)r   _get_program_relpathr  r6   r6   r7   _code_path_local8  s   zSettings._code_path_localc                 C  s
   dt jv S )Nzgoogle.colab)ry  modulesr  r6   r6   r7   _colabE     
zSettings._colabc                 C     t  S ru   )r%   
in_ipythonr  r6   r6   r7   _ipythonJ     zSettings._ipythonc                 C  r  ru   )r%   
in_jupyterr  r6   r6   r7   rx  O  r  zSettings._jupyterc                 C  r  ru   )r   _is_likely_kaggler  r6   r6   r7   _kaggleT  r  zSettings._kagglec                 C  
   | j dkS )Ndisabledr  r  r6   r6   r7   _noopY  r  zSettings._noopc                 C  s   | j p| jp| jp| jS ru   )r  rx  r  r  r  r6   r6   r7   	_notebook^  s   zSettings._notebookc                 C  s
   | j dv S )N)offlinedryrunr  r  r6   r6   r7   r   c  r  zSettings._offlinec                 C  s   t j ddS )z7The operating system of the machine running the script.T)aliased)r   r  r6   r6   r7   _osh     zSettings._osc                 C  s   t   dt    S N-)r   r   machinerE   r  r6   r6   r7   	_platformn  s   zSettings._platformc                 C  s   t   dt   S )N )r   python_implementationpython_versionr  r6   r6   r7   _pythons  rP  zSettings._pythonc                 C  r  )zWhether we are in shared mode.

        In "shared" mode, multiple processes can write to the same run,
        for example from different machines.
        sharedr  r  r6   r6   r7   _sharedx  s   
zSettings._sharedc                 C  s$   | j d u rdS t| j }|dS )Nr=   z%Y%m%d_%H%M%S)r   r   fromtimestampstrftime)r  datetime_nowr6   r6   r7   _start_datetime  s   

zSettings._start_datetimec                 C  s   t | jddS )Ntmpcoder^   sync_dirr  r6   r6   r7   _tmp_code_dir     zSettings._tmp_code_dirc                 C  s   t  dkS )Nr   r   r  r6   r6   r7   _windows     zSettings._windowsc                 C  s2   | j sdS | jr| jdrt| j}d| S dS )z3The URL to the Colab notebook, if running in Colab.NfileId=z+https://colab.research.google.com/notebook#)r  r   r  r   )r  	unescapedr6   r6   r7   	colab_url  s   
zSettings.colab_urlLiteral['local', 'cloud']c                 C  s   | j rdS dS )Nlocalcloud)is_localr  r6   r6   r7   
deployment  r  zSettings.deploymentc                 C  s   | j pt| jdS )zFAbsolute path to the local directory where the run's files are stored.files)r   r^   r  r  r6   r6   r7   	files_dir  s   zSettings.files_dirc                 C  s   t | jdkS )Nrm   )r,   rn   r  r6   r6   r7   r    r  zSettings.is_localc                 C     t | jdS )z$The directory for storing log files.logsr  r  r6   r6   r7   log_dir  r  zSettings.log_dirc                 C  r  )z.The path to the file to use for internal logs.debug-internal.logr^   r  r  r6   r6   r7   log_internal  r  zSettings.log_internalc                 C  r  )zHThe path to the symlink to the internal log file of the most recent run.r  r^   	wandb_dirr  r6   r6   r7   log_symlink_internal  r  zSettings.log_symlink_internalc                 C  r  )zLThe path to the symlink to the user-process log file of the most recent run.	debug.logr  r  r6   r6   r7   log_symlink_user  r  zSettings.log_symlink_userc                 C  r  )z2The path to the file to use for user-process logs.r  r  r  r6   r6   r7   log_user  r  zSettings.log_userc                 C  s$   |   }|sdS |  }| | S )z,The W&B URL where the project can be viewed.r=   )_project_url_base_get_url_query_stringr  project_urlqueryr6   r6   r7   r    s
   zSettings.project_urlc                 C  r  )zThe path to the resume file.zwandb-resume.jsonr  r  r6   r6   r7   resume_fname  r  zSettings.resume_fnameLiteral['run', 'offline-run']c                 C  s   | j sdS dS )NrD  zoffline-run)r   r  r6   r6   r7   run_mode  r  zSettings.run_modec                 C  sF   |   }t|| jgsdS |  }d}| dt| jpd|d | S )z(The W&B URL where the run can be viewed.r=   z=+&$@z/runs/)safe)r  allr   r  r   )r  r  r  
safe_charsr6   r6   r7   run_url  s    zSettings.run_urlc                 C  r  )z(The path to the workspace settings file.settingsr  r  r6   r6   r7   settings_workspace  r  zSettings.settings_workspacec                 C  s>   |   }t|| jgsdS |  }| dt| jpd | S )z*The W&B URL where the sweep can be viewed.r=   z/sweeps/)r  r  r   r  r   r  r6   r6   r7   	sweep_url  s
   zSettings.sweep_urlc                 C  s"   t | j| j d| j d| j S r  )r^   r  r  timespecr   r  r6   r6   r7   r    s   zSettings.sync_dirc                 C  s   t | jd| j dS )z4Path to the append-only binary transaction log file.zrun-.wandb)r^   r  r   r  r6   r6   r7   	sync_file
  s   zSettings.sync_filec                 C  r  )Nz
latest-runr  r  r6   r6   r7   sync_symlink_latest  r  zSettings.sync_symlink_latestc                 C  s   | j S ru   )r  r  r6   r6   r7   r    s   zSettings.timespecc                 C  sH   t jt j| jdrdt j ndt j }t j| j|}t j|S )z!Full path to the wandb directory.r  rk  )rZ   r[   existsr]   r   sepr\   )r  	stage_dirr[   r6   r6   r7   r    s   zSettings.wandb_dirc                 C  J   | j r
tj| j sdS | | j  D ]\}}|dur"t| || qdS )z,Update settings from the system config file.N)r   rZ   r[   r  _load_config_fileitemssetattrr  r  r(  r6   r6   r7   update_from_system_config_file-     z'Settings.update_from_system_config_filec                 C  r  )z/Update settings from the workspace config file.N)r  rZ   r[   r  r  r  r  r  r6   r6   r7   !update_from_workspace_config_file5  r  z*Settings.update_from_workspace_config_fileenvironDict[str, Any]c           	   
   C  s   d}|d }ddddddd	d
dd	}t  }| D ]A\}}||s#q||v r,|| }n||r>d|t|d   }n
|t|d  }|| jv rZ|dv rV|d}|||< q| D ]\}}|durmt| || q_dS )z+Update settings from environment variables.WANDB_r  r   r   r   r   r   r   r   r   r~   )	WANDB_SERVICE_TRANSPORT	WANDB_DIR
WANDB_NAMEWANDB_NOTES
WANDB_TAGSWANDB_JOB_TYPEWANDB_HTTP_TIMEOUTWANDB_FILE_PUSHER_TIMEOUTWANDB_USER_EMAILx_N)r   r   rZ  )dictr  r  rK   rE   __dict__rD   r  )	r  r  
env_prefixprivate_env_prefixspecial_env_var_namesr   settingr(  r  r6   r6   r7   update_from_env_vars=  s>   




zSettings.update_from_env_varsc              	   C  s  | j du s
| j du rttjdusttjdurt | _ ttjdur,t | _| j	rS| j
du s9| j
dkrStj| j}|d| _|d| _|d| _n*| j	rp| j
durptj| j
rp| j
| _| j
| _t | _n| j	r}td| j
 d | jdu rt | _| jptjtjptjpt d	pd	}|| _| j!du rt"t#$ | _!| j%rdS | j&p| ' }|durz| jst( j)pt nt }W n t*y   t }Y nw | j+p| ,||| _+tj-tj.|tj/t ||}tj|r|| _0nd
}|| _&dS )z,Update settings from the system environment.TNr=   r[   namerootzGWANDB_NOTEBOOK_NAME should be a path to a notebook file, couldn't find .python3z<python with no main file>)1r   rZ   getenvr   	SAVE_CODEDISABLE_CODEshould_save_codeDISABLE_GITr{   rx  r   rk  jupyternotebook_metadatar   r#  r   r   r   r[   r  r   rl  r   socketgethostnamer   r  _EXECUTABLEry  
executableshutilwhichr}   
get_dockerr   image_id_from_k8sr   r   _get_programr&   r  	Exceptionr   r  r   r]   relpathr   )r  meta_executabler   r  r   r6   r6   r7   update_from_system_environmentb  s~   








z'Settings.update_from_system_environmentr  r.   c                 C  s.   t | D ]\}}|durt| || qdS )z"Update settings from a dictionary.N)r  r  r  )r  r  r  r(  r6   r6   r7   update_from_dict  s
   zSettings.update_from_dictc                   s*    fdd j D }|r| | dS dS )z4Update settings from another instance of `Settings`.c                   s   i | ]}|t  |qS r6   )getattr)r  fieldr  r6   r7   
<dictcomp>  rY  z1Settings.update_from_settings.<locals>.<dictcomp>N)model_fields_setr  )r  r  dr6   r  r7   update_from_settings  s   zSettings.update_from_settingswandb_settings_pb2.Settingsc                 C  s*  t  }| jdd D ]\}}|dv rq|dkrbt|tttfr/t||}|j	j
| n2t|trUt||}| D ]\}}| D ]\}}||jj
| j
|< qEq=ntdt| d| q|dv rt|trm|nt|d|d	|d
d}	t||t j|	j|	j
|	jd qt|trt||t|d qt|trt||t|d qt|trt||t|d qt|trt||t|d qt|tttfrt||}
|
j
| qt|trt||}| D ]	\}}||j
|< qq|du rqtdt| d| |S )z3Generate a protobuf representation of the settings.T)exclude_none)r   r   zUnsupported type z for setting )r   r   rD  r(  metric)rD  r(  r  rW  N)r!   r_   
model_dumpr  r/  r[  setrN  r  sequencer(  extendr  mapping	TypeErrortyper'   r#  CopyFromrD  r  rf   r   r   r   r   r   r,   r   )r  settings_protokvr  r  r(  kkvvrF  r  r  r6   r6   r7   to_proto  sl   



	






zSettings.to_protoc                 C  s   | j r| jr	| jS | js| jS | jdr| jS | jS ttj	}|dur'|S zddl
}W n
 ty7   Y dS w z|jdu rD|j}W |S d|jj }W |S  tyW   Y dS w )z1Get the program that started the current process.r  Nr   z-m )rx  r   r   r   r  r   rZ   r  r   PROGRAM__main__ImportError__spec____file__r  AttributeError)r  r   r'  python_argsr6   r6   r7   r    s2   
zSettings._get_programr  c                 C  sz   | sdS |p	t  }|sdS t|| sdS t j|t jt  || }t j|r;t jj||d}d|v r9dS |S dS )z=Get the relative path to the program from the root directory.N)startz../)rZ   r   r   are_paths_on_same_driver[   r]   r	  r  )r   r  full_path_to_programrelative_pathr6   r6   r7   r  '  s    zSettings._get_program_relpath	file_namesectionr  c                 C  s^   t  }|| ||  t }|| D ]}|| | ||< |dkr,|| d||< q|S )z?Load a config file and return the settings for a given section.r   rZ  )configparserConfigParseradd_sectionreadr  rD   )r1  r2  parserconfigr!  r6   r6   r7   r  A  s   

zSettings._load_config_filec                 C  sH   t | j| jgs
dS t| j}| dt| jpd dt| jp d S )z'Construct the base URL for the project.r=   r   )r  r   r   r   app_urlrn   r   )r  r9  r6   r6   r7   r  N  s   (zSettings._project_url_basec                 C  s,   | j dvrdS tj| d}dtd|i S )z<Construct the query string for project, run, and sweep URLs.)allowmustr=   r  ?apiKey)ri   r#   rk   r   )r  rk   r6   r6   r7   r  V  s   
zSettings._get_url_query_stringvalUnion[RunMoment, str, None]c                 C  s.   t | ts	| du r| S t | trt| S dS )z5Preprocess the setting for forking or resuming a run.N)r/  r'   r,   from_uri)r>  r6   r6   r7   rB  `  s
   

z Settings._runmoment_preprocessorc                 O  s   | j |i |S ru   )copy)r  rY   kwargsr6   r6   r7   
model_copyl  s   zSettings.model_copyc           	      K  s   | dd}| jdi |}t| jD ]5}t| j|d}t|tr:zt| |}|||< W q ttt	t
fy9   Y qw t|trHt| |}|||< qh d}|D ]	}||v rX||= qO|rddd | D S |S )a  Compatibility method for Pydantic v1 to mimic v2's model_dump.

            In v1, this is equivalent to dict() but also includes computed properties.

            Args:
                **kwargs: Options passed to the dict method
                    - exclude_none: Whether to exclude fields with None values

            Returns:
                A dictionary of the model's fields and computed properties
            r  FN>   
__fields__model_configmodel_fieldsr  __pydantic_self____model_fields_set__pydantic_initialised__c                 S  s   i | ]\}}|d ur||qS ru   r6   )r  r!  r"  r6   r6   r7   r    s    z'Settings.model_dump.<locals>.<dictcomp>r6   )popr  dir	__class__r  r/  propertyr+  NotImplementedErrorr  rG   r'   r  )	r  rB  r  resultr  attrr(  exclude_fieldsr  r6   r6   r7   r  o  s.   



zSettings.model_dumpr  c                 C  s   t | dt S )zReturn a set of fields that have been explicitly set.

            This is a compatibility property for Pydantic v1 to mimic v2's model_fields_set.
            __fields_set__)r  r  r  r6   r6   r7   r    s   zSettings.model_fields_set)r-   r   )r-   r   )r-   rw  )r-   rf   )r-   rj   )r-   r,   )r-   r  )r-   r  )r  r  )r  r  r-   r.   )r  r_   r-   r.   )r-   r  ru   )r   r,   r  rj   r-   rj   )r1  r,   r2  r,   r-   r  )r>  r?  r-   r   )r-   r  )__name__
__module____qualname____doc__r   rE  rg   __annotations__rh   ri   rk   rl   rn   ro   rp   r   rs   rt   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   loggingINFOr   r   r   r   r   r   r   r   r   r   r   r   r   rZ   getpidr   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r	  r   classmethodr  r   r  r!  r8   r   r)  r,  r2  r6  r7  r<  r>  r?  rG  rK  rM  rO  rQ  rR  rS  r^  r_  r`  ra  re  rf  rh  rm  rn  ro  rp  rq  rr  rs  rt  ru  rv  r   rM  r{  r  r  r  r  rx  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r  staticmethodr  r  r  r  rB  rC  r  r  r6   r6   r6   r7   r_      s>  
 	

	
	

































	
	%PC$
	7r_   T)validate_assignment)r+   r,   r-   r.   )rY   r,   r-   r,   )C
__future__r   r3  r:  rX  rZ   r0  r   r@   r  r  ry  r   typingr   r   r   r   r   r	   r
   r   r   r?   r   r   r   google.protobuf.wrappers_pb2r   r   r   r   pydanticr   r   r   typing_extensionsr   rk  r   r   wandb._pydanticr   r   r   r   r   wandb.errorsr    wandb.protor!   libr#   r$   r%   
lib.gitlibr&   lib.run_momentr'   rW  pydantic_corer)   r*   r(   r8   r^   r_   r6   r6   r6   r7   <module>   sB    ,


_