Scheaven
2021-09-18 291deeb1fcf45dbf39a24aa72a213ff3fd6b3405
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
U
ú{‹`Hã@sfdZddlZddlZddlmZddlZddlmZddl    m
Z
dZ Gdd„deƒZed    œd
d „Z dS) z9
@author:  l1aoxingyu
@contact: sherlockliao01@gmail.com
éN)ÚAny)ÚCfgNode)Ú PathManagerZ_BASE_csneZdZdZedeedœdd„ƒZdeedœdd„Z‡fd    d
„Z    e
d œ‡fd d „ Z ee dœ‡fdd„ Z ‡ZS)raM
    Our own extended version of :class:`yacs.config.CfgNode`.
    It contains the following extra features:
    1. The :meth:`merge_from_file` method supports the "_BASE_" key,
       which allows the new CfgNode to inherit all the attributes from the
       base configuration file.
    2. Keys that start with "COMPUTED_" are treated as insertion-only
       "computed" attributes. They can be inserted regardless of whether
       the CfgNode is frozen or not.
    3. With "allow_unsafe=True", it supports pyyaml tags that evaluate
       expressions in config. See examples in
       https://pyyaml.org/wiki/PyYAMLDocumentation#yaml-tags-and-python-types
       Note that this may lead to arbitrary code execution: you must not
       load a config file from untrusted sources before manually inspecting
       the content of the file.
    F)ÚfilenameÚ allow_unsafec st |d¡v}zt |¡}Wn`tjjk
r||s6‚t t¡}|     d 
|¡¡|  ¡t|dƒ}t  |¡}W5QRXYnXW5QRX‡fdd„‰t |kr
|t }| d¡r¼tj |¡}tt|jdddgƒƒsètj tj |¡|¡}tj||d    }|t =ˆ||ƒ|S|S)
a 
        Just like `yaml.load(open(filename))`, but inherit attributes from its
            `_BASE_`.
        Args:
            filename (str): the file name of the current config. Will be used to
                find the base config file.
            allow_unsafe (bool): whether to allow loading the config file with
                `yaml.unsafe_load`.
        Returns:
            (dict): the loaded yaml
        ÚrzlLoading config {} with yaml.unsafe_load. Your machine may be at risk if the file contains malicious content.cs\| ¡D]N\}}t|tƒrN||krNt||tƒs>td |¡ƒ‚ˆ|||ƒq|||<qdS)Nz"Cannot inherit key '{}' from base!)ÚitemsÚ
isinstanceÚdictÚAssertionErrorÚformat)ÚaÚbÚkÚv©Úmerge_a_into_b©ú./config/config.pyrCsÿþz3CfgNode.load_yaml_with_base.<locals>.merge_a_into_bú~ú/zhttps://zhttp://©r)rÚopenÚyamlZ    safe_loadÚ constructorZConstructorErrorÚloggingÚ    getLoggerÚ__name__Úwarningr ÚcloseZ unsafe_loadÚBASE_KEYÚ
startswithÚosÚpathÚ
expanduserÚanyÚmapÚjoinÚdirnamerÚload_yaml_with_base)rrÚfÚcfgÚloggerZ base_cfg_fileZbase_cfgrrrr)%sF 
þÿ $
 
 ÿ
ÿÿ
zCfgNode.load_yaml_with_base)Ú cfg_filenamercCstj||d}t|ƒ|ƒ}dS)zí
        Merge configs from a given yaml file.
        Args:
            cfg_filename: the file name of the yaml config.
            allow_unsafe: whether to allow loading the config file with
                `yaml.unsafe_load`.
        rN)rr)Útype)Úselfr-rZ
loaded_cfgrrrÚmerge_from_filebs
ÿzCfgNode.merge_from_filecs"t|kstd t¡ƒ‚tƒ |¡S)zO
        Args:
            cfg_other (CfgNode): configs to merge from.
        ú0The reserved key '{}' can only be used in files!)r r r ÚsuperÚmerge_from_other_cfg)r/Z    cfg_other©Ú    __class__rrr3qs
ÿþzCfgNode.merge_from_other_cfg)Úcfg_listcs4t|ddd…ƒ}t|ks(td t¡ƒ‚tƒ |¡S)zS
        Args:
            cfg_list (list): list of configs to merge from.
        rNér1)Úsetr r r r2Úmerge_from_list)r/r6Úkeysr4rrr9}s ÿþzCfgNode.merge_from_list)ÚnameÚvalcsT| d¡rB||kr8||}||kr&dStd |||¡ƒ‚|||<ntƒ ||¡dS)NZ    COMPUTED_zOComputed attributed '{}' already exists with a different value! old={}, new={}.)r!ÚKeyErrorr r2Ú __setattr__)r/r;r<Zold_valr4rrr>ˆs
þÿ
zCfgNode.__setattr__)F)F)rÚ
__module__Ú __qualname__Ú__doc__Ú staticmethodÚstrÚboolr)r0r3Úlistr9rr>Ú __classcell__rrr4rrs<  r)ÚreturncCsddlm}| ¡S)z]
    Get a copy of the default config.
    Returns:
        a fastreid CfgNode instance.
    é©Ú_C)ÚdefaultsrJÚclonerIrrrÚget_cfg™s rM) rArr"ÚtypingrrZ yacs.configrZ_CfgNodeÚ utils.file_iorr rMrrrrÚ<module>s