Config reader - vcspull._internal.config_reader

Warning

Be careful with these! Internal APIs are not covered by version policies. They can break or be removed between minor versions!

If you need an internal API stabilized please file an issue.

class vcspull._internal.config_reader.ConfigReader(content)[source]

Bases: object

Parse string data (YAML and JSON) into a dictionary.

>>> cfg = ConfigReader({ "session_name": "my session" })
>>> cfg.dump("yaml")
'session_name: my session\n'
>>> cfg.dump("json")
'{\n  "session_name": "my session"\n}'
Parameters:

content (RawConfigData)

static _load(fmt, content)[source]

Load raw config data and directly return it.

Return type:

dict[str, Any]

Parameters:
  • fmt (FormatLiteral)

  • content (str)

>>> ConfigReader._load("json", '{ "session_name": "my session" }')
{'session_name': 'my session'}
>>> ConfigReader._load("yaml", 'session_name: my session')
{'session_name': 'my session'}
classmethod load(fmt, content)[source]

Load raw config data into a ConfigReader instance (to dump later).

>>> cfg = ConfigReader.load("json", '{ "session_name": "my session" }')
>>> cfg
<tmuxp.config_reader.ConfigReader object at ...>
:rtype: :sphinx_autodoc_typehints_type:`ConfigReader`
>>> cfg.content
{'session_name': 'my session'}
>>> cfg = ConfigReader.load("yaml", 'session_name: my session')
>>> cfg
<tmuxp.config_reader.ConfigReader object at ...>
>>> cfg.content
{'session_name': 'my session'}
Parameters:
  • fmt (FormatLiteral)

  • content (str)

Return type:

ConfigReader

classmethod _from_file(path)[source]

Load data from file path directly to dictionary.

YAML file

For demonstration only, create a YAML file:

>>> yaml_file = tmp_path / 'my_config.yaml'
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`dict\`\\ \\\[\:py\:class\:\`str\`\, \:py\:data\:\`\~typing.Any\`\]`
>>> yaml_file.write_text('session_name: my session', encoding='utf-8')
24

Read YAML file:

>>> ConfigReader._from_file(yaml_file)
{'session_name': 'my session'}

JSON file

For demonstration only, create a JSON file:

>>> json_file = tmp_path / 'my_config.json'
>>> json_file.write_text('{"session_name": "my session"}', encoding='utf-8')
30

Read JSON file:

>>> ConfigReader._from_file(json_file)
{'session_name': 'my session'}
Parameters:

path (Path)

Return type:

dict[str, Any]

classmethod from_file(path)[source]

Load data from file path.

YAML file

For demonstration only, create a YAML file:

>>> yaml_file = tmp_path / 'my_config.yaml'
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~vcspull.\_internal.config\_reader.ConfigReader\``
>>> yaml_file.write_text('session_name: my session', encoding='utf-8')
24

Read YAML file:

>>> cfg = ConfigReader.from_file(yaml_file)
>>> cfg
<tmuxp.config_reader.ConfigReader object at ...>
>>> cfg.content
{'session_name': 'my session'}

JSON file

For demonstration only, create a JSON file:

>>> json_file = tmp_path / 'my_config.json'
>>> json_file.write_text('{"session_name": "my session"}', encoding='utf-8')
30

Read JSON file:

>>> cfg = ConfigReader.from_file(json_file)
>>> cfg
<tmuxp.config_reader.ConfigReader object at ...>
>>> cfg.content
{'session_name': 'my session'}
Parameters:

path (Path)

Return type:

ConfigReader

static _dump(fmt, content, indent=2, **kwargs)[source]

Dump directly.

Return type:

str

Parameters:
  • fmt (FormatLiteral)

  • content (RawConfigData)

  • indent (int)

  • kwargs (Any)

>>> ConfigReader._dump("yaml", { "session_name": "my session" })
'session_name: my session\n'
>>> ConfigReader._dump("json", { "session_name": "my session" })
'{\n  "session_name": "my session"\n}'
dump(fmt, indent=2, **kwargs)[source]

Dump via ConfigReader instance.

>>> cfg = ConfigReader({ "session_name": "my session" })
>>> cfg.dump("yaml")
'session_name: my session\n'
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
>>> cfg.dump("json")
'{\n  "session_name": "my session"\n}'
Parameters:
  • fmt (FormatLiteral)

  • indent (int)

  • kwargs (Any)

Return type:

str