nitpick.plugins.ini module

INI files.

class nitpick.plugins.ini.IniPlugin(info: FileInfo, expected_config: JsonDict, autofix=False)[source]

Bases: NitpickPlugin

Enforce configurations and autofix INI files.

Examples of .ini files handled by this plugin:

Style examples enforcing values on INI files: flake8 configuration.

add_options_before_space(section: str, options: dict) None[source]

Add new options before a blank line in the end of the section.

comma_separated_values: set[str]
compare_different_keys(section, key, raw_actual: Any, raw_expected: Any) Iterator[Fuss][source]

Compare different keys, with special treatment when they are lists or numeric.

static contents_without_top_section(multiline_text: str) str[source]

Remove the temporary top section from multiline text, and keep the newline at the end of the file.

property current_sections: set[str]

Current sections of the .ini file, including updated sections.

dirty: bool
enforce_comma_separated_values(section, key, raw_actual: Any, raw_expected: Any) Iterator[Fuss][source]

Enforce sections and keys with comma-separated values. The values might contain spaces.

enforce_missing_sections() Iterator[Fuss][source]

Enforce missing sections.

enforce_rules() Iterator[Fuss][source]

Enforce rules on missing sections and missing key/value pairs in an INI file.

enforce_section(section: str) Iterator[Fuss][source]

Enforce rules for a section.

entry_point() Iterator[Fuss]

Entry point of the Nitpick plugin.

expected_config: JsonDict
property expected_sections: set[str]

Expected sections (from the style config).

file_path: Path
filename = ''
fixable: bool = True

Can this plugin modify its files directly? Are the files fixable?

static get_example_cfg(parser: ConfigParser) str[source]

Print an example of a config parser in a string instead of a file.

get_missing_output() str[source]

Get a missing output string example from the missing sections in an INI file.

identify_tags: set[str] = {'editorconfig', 'ini'}

Which identify tags this nitpick.plugins.base.NitpickPlugin child recognises.

property initial_contents: str

Suggest the initial content for this missing file.

property missing_sections: set[str]

Missing sections.

property needs_top_section: bool

Return True if this .ini file needs a top section (e.g.: .editorconfig).

property nitpick_file_dict: Dict[str, Any]

Nitpick configuration for this file as a TOML dict, taken from the style file.

post_init()[source]

Post initialization after the instance was created.

predefined_special_config() SpecialConfig

Create a predefined special configuration for this plugin. Each plugin can override this method.

show_missing_keys(section: str, values: list[tuple[str, Any]]) Iterator[Fuss][source]

Show the keys that are not present in a section.

skip_empty_suggestion = False
updater: ConfigUpdater
validation_schema: Schema | None = None

Nested validation field for this file, to be applied in runtime when the validation schema is rebuilt. Useful when you have a strict configuration for a file type (e.g. nitpick.plugins.json.JsonPlugin).

violation_base_code: int = 320
write_file(file_exists: bool) Fuss | None[source]

Write the new file.

write_initial_contents(doc_class: type[BaseDoc], expected_dict: dict | None = None) str

Helper to write initial contents based on a format.

class nitpick.plugins.ini.Violations(value)[source]

Bases: ViolationEnum

Violations for this plugin.

INVALID_COMMA_SEPARATED_VALUES_SECTION = (325, ': invalid sections on comma_separated_values:')
MISSING_OPTION = (324, ': section [{section}] has some missing key/value pairs. Use this:')
MISSING_SECTIONS = (321, ' has some missing sections. Use this:')
MISSING_VALUES_IN_LIST = (322, ' has missing values in the {key!r} key. Include those values:')
OPTION_HAS_DIFFERENT_VALUE = (323, ': [{section}]{key} is {actual} but it should be like this:')
PARSING_ERROR = (326, ': parsing error ({cls}): {msg}')
TOP_SECTION_HAS_DIFFERENT_VALUE = (327, ': {key} is {actual} but it should be:')
TOP_SECTION_MISSING_OPTION = (328, ': top section has missing options. Use this:')
nitpick.plugins.ini.can_handle(info: FileInfo) type[NitpickPlugin] | None[source]

Handle INI files.

nitpick.plugins.ini.plugin_class() type[NitpickPlugin][source]

Handle INI files.