Debian Codegraph @

cylc/flow/parsec/README.md

raw
1 # Parsec Config File Parser
2
3 A framework for constructing nested-INI-style config file formats with
4 automatic parsing, validation, default values, on-the-fly item
5 obsoletion, deprecation and upgrade, and site/user-style file override
6 (e.g. User's ``global.cylc`` overrides site's overrides spec default values).
7
8 ### Used in Cylc for:
9
10 * workflow definition files
11 * site/user config files
12
13
14 ## Design & Implementation
15
16 ### Parsing: ``cylc/flow/parsec/fileparse.py``
17
18 Parses any nested-INI format file into a corresponding nested dict
19 structure, after ``%include``-inlining, Jinja2 processing, and line
20 continuation joining. Also: trailing comments are stripped; single-,
21 double-, or un-quoted values; and triple-quoted multiline string values.
22 string-internal comments are retained.
23
24 ### Validation: ``cylc/flow/parsec/validate.py``
25
26 Validates a config structure (from the parser) against a file spec that
27 defines the "file format" (next).
28
29 ### File spec
30
31 **E.g. ``cylc/flow/parsec/test_spec.py`` for ``cylc/flow/parsec/test.cylc`` and Cylc file
32 specs in ``cylc/flow/cfgspec/``.**
33
34 A nested dict that contains all legal items in their proper place, and
35 "values" that are *validator* objects prescribing the type of the value
36 (string, integer, etc.), other requirements, and default values. There
37 are pre-defined validators for string, integer, float; list (of strings,
38 integers, floats, and lists with multipliers as for Cylc "retry
39 delays"); and Cylc times. Other validators can be defined.
40
41 ### Deprecation & automatic upgrade: ``cylc/flow/parsec/upgrade.py``
42
43 Allows the file spec module to specify mapping between deprecated items
44 and their new counterparts, along with an upgrader object to do any
45 value transformation required. If affected items are found in the
46 config file, a deprecation warning will be emitted and the item upgraded
47 on-the-fly for compatibility with the current file spec.
48
49 ### High-level "interface"(?): ``cylc/flow/parsec/loadcfg.py``
50
51 Defines functions that combine parsing and validation for (presumably)
52 common use cases. Includes combine two config files with precedence order.
53
54 ## Testing
55
56 * **``cylc/flow/parsec/test.cylc``**
57 An example config file that does (or should/will) contain all types of
58 config item that parsec is supposed to support.
59
60 * **``cylc/flow/parsec/test_spec.py``**
61 Defines a spec for ``test.cylc``, and a unit test to parse, validate, and
62 print the config file. Does not test deprecation/upgrade at this stage.
63
64 * **``cylc/flow/parsec/upgrade.py``**
65 Contains a unit test to test on-the-fly upgrade of deprecated items.
66
67 ## Note on use of ordered dicts
68
69 Files are parsed into ordered dicts, in case order is important. In Cylc
70 it is important in at least two places: variables defined in
71 ``[[[environment]]]`` sections under ``[runtime]`` may depend on other variables
72 previously defined in the same section; and in site/user config files,
73 parsed host sections need to remain ordered in case of an ordered hierarchy
74 (specific to general) of hostname match patterns.
75
76 This generally only matters for items parsed from config files, not for
77 the default values defined in file spec modules - so there is no need to
78 use ordered dicts in file specs unless the order of defaults matters.