The Modes
In the context of a CsvPaths
instance's run, an individual CsvPath
instance can operate in several possible modes that allow you to configure its behavior without resorting to the global config.ini
or applying settings programmatically. In particular, the modes help you configure groups of csvpaths more flexibly. You can use them to easily disable individual csvpaths or configure them differently than other csvpaths in the same named-paths group.
Modes are set in your csvpath's comments. The modes are:
explain-mode
:
[explain
/no-explain
]files-mode
:
(all or any combination of)all
data
/no-data
unmatched
/no-unmatched
printouts
/no-printouts
logic-mode
:
[AND
/OR
]print-mode
:
[default
/no-default
]return-mode
:
[matches
/no-matches
]run-mode
:
[run
/no-run
]source-mode
:
preceding
transfer-mode
:
data
/unmatched
>
var-name
unmatched-mode
:
[keep
/no-keep
]validation-mode
:
(any combination of)print
/no-print
raise
/no-raise
stop
/no-stop
fail
/no-fail
Modes are only set in external comments. External comments are comments that are outside the csvpath, above or below it. External comments can also have other user-defined metadata and plain text mixed in with mode settings. If a mode setting is followed by plain text there must be a stand-alone colon between the mode and the text.
Defaults
When a mode is not explicitly set the default is:
explain-mode
: no explanations are logged when logging is set to INFOfiles-mode
: there is no check for optional files having been generatedlogic-mode
: match components are ANDedprint-mode
: print statements go to the consolereturn-mode
: matches are returnedrun-mode
: the csvpath is runsource-mode
: the named-file that was passed to the named-paths group is used as inputtransfer-mode
: no result data transfer is madeunmatched-mode
: lines not returned are discardedvalidation-mode
: validation errors are only printed and logged
An Example
These settings are configured like in this example of two trivial csvpaths in a named-paths group called example
:
hello_world
will not be run when the named-paths group runs, but it will be imported into the second csvpath identified as next please!
. This example doesn't do much, but it gives an idea of how you can easily configure individual csvpaths within a group that will be run as a single unit. As you can see, some modes can take multiple values separated by commas.
Detailed Descriptions
Run Mode
Validation Mode
Validation mode controls how the CsvPath
instance reacts to built-in validation errors. Built-in validation errors have two types:
Problems with the csvpath's syntax or structure
Problems with the data being validated
Logic Mode
Return Mode
Print Mode
Explain Mode
Unmatched Mode
Files Mode
The impact of files-mode
is that the run instance manifest and the csvpath's manifest will show that files were created as expected, or not.
There are various reasons why printouts.txt, data.csv and unmatched.csv might not be generated. For e.g., if we expect no validation output from user-created print()
statements or built-in validation error messages we might set the files-mode
to no-printouts
. If a validation error was then printed we would be alerted in the metadata. In another example, if we set unmatched-mode
to no-keep
(the default) and files-mode
to unmatched
we have a conflict that we'll be alerted to in the metadata. Similarly, if we set files-mode
to data
and then run fast_forward_paths()
we will not get data.csv
files and the metadata will alert us to the mismatch.
errors.json
, vars.json
, meta.json
, and manifest.json
are always generated, regardless of files-mode
. When you set files-mode
to all
the CsvPath Library will double-check that meta, vars, errors were correctly created, but that part of its checking is superfluous.
Source Mode
Usually the data for a csvpath in a named-paths group comes from the data input for the whole group. I.e., all the csvpaths in the group run against the same source file. However, in some cases you might want the input to a csvpath to be the csvpath preceding it. Meaning that the results captured from the first csvpath are piped into the second. To do this, you set source-mode: preceding
on the second csvpath.
Keep in mind that CsvPaths
instances' _collects
methods and _by_line
methods are quite different in how they handle data sources. Source mode does not apply to by-lines runs—i.e. it is for linear, not breadth-first runs—because in a by-lines run each line is passed through each of the csvpaths in the named-paths group before the next line is considered. Csvpaths in a by-lines run can change data for downstream csvpaths in their named-paths group, and they can skip or advance the run in order to filter data so that downstream csvpaths don't have a chance at it. This just means that there are multiple ways of allowing earlier csvpaths to have an effect on later csvpaths.
Transfer Mode
transfer-mode
let's you copy data.csv
or unmatched.csv
to an arbitrary location in the transfers
directory. The transfers
directory is configured in config/config.ini
under [results] transfers
. To use transfer-mode
you use the form data
| unmatched
>
var-name where var-name is the name of a variable that will be the relative path under the transfer
directory to the data you are transferring. Note that transfer-mode
has no effect on the original data, in keeping with CsvPath Library's copy-on-write semantics. You may have as many transfers as you like by separating them with commas.
Last updated