Objects serialization
Some plugins like jmespath apply their actions against object-serialized version of files. Also, the style files itself parsed by project-config to execute the rules are serialized to objects.
This is really convenient for configuration files because the most common files formats like JSON, TOML or YAML can be converted into a map (dictionary in Python, object in Javascript) to perform operations against the structured nodes.
The serialization process of project-config converts strings to Python dictionaries using loader functions depending on the format of the files. The format is discovered, based mostly on file names, using identify.
The next formats are currently supported:
JSON
Loader:
json.loads()
.Dumper:
json.dumps()
.
JSON5
Loader:
pyjson5.loads()
or json5.loads as fallback.Dumper:
pyjson5.dumps()
or json5.dumps as fallback.
YAML (v1.2)
Loader:
project_config.serializers.yaml.loads()
(based on ruamel.yaml).Dumper:
project_config.serializers.yaml.dumps()
(based on ruamel.yaml).
TOML (v1)
Loader: tomlkit.parse.
Dumper: tomlkit.dumps.
See the TOML v1 specification.
INI
Editorconfig
The root directive, if exists, will be added in an empty string key ""
object:
root = true
[*]
end_of_line = lf
charset = utf-8
indent_style = space
trim_trailing_whitespace = true
{
"": {
"root": true
},
"*": {
"end_of_line": "lf",
"charset": "utf-8",
"indent_style": "space",
"trim_trailing_whitespace": true
}
}
Python
For Python files, the global namespace is exposed after executing the file in
a Python dictionary, including the key __file__
with the script file path.
bar = "baz"
{
"bar": "baz"
}
Tip
project-config CLI sets the environment variable PROJECT_CONFIG
while is running, which is useful if you want to expose the global namespaces
of scripts only when the tool is running.
Text
Fallback for all serialized files. Just converts the string to an array of lines, excluding line endings.
bar
baz
["bar", "baz"]