nitpick.plugins.ini module

INI files.

class nitpick.plugins.ini.IniPlugin(info:, expected_config: Dict[str, Any], fix=False)[source]

Bases: nitpick.plugins.base.NitpickPlugin

Enforce config on 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: collections.OrderedDict) None[source]

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

can_fix: bool = True

Can this plugin modify files directly?

comma_separated_values: Set[str]
compare_different_keys(section, key, raw_actual: Any, raw_expected: Any) Iterator[nitpick.violations.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[nitpick.violations.Fuss][source]

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

enforce_missing_sections() Iterator[nitpick.violations.Fuss][source]

Enforce missing sections.

enforce_rules() Iterator[nitpick.violations.Fuss][source]

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

enforce_section(section: str) Iterator[nitpick.violations.Fuss][source]

Enforce rules for a section.

entry_point() Iterator[nitpick.violations.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 = ''
classmethod get_compiled_jmespath_filenames()

Return a compiled JMESPath expression for file names, using the class name as part of the key.

static get_example_cfg(parser: configparser.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.


Post initialization after the instance was created.

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.

show_missing_keys(section: str, values: List[Tuple[str, Any]]) Iterator[nitpick.violations.Fuss][source]

Show the keys that are not present in a section.

skip_empty_suggestion = False
updater: configupdater.configupdater.ConfigUpdater
validation_schema: Optional[Schema] = 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
warn_missing_different(comparison: nitpick.formats.Comparison, prefix: str = '') Iterator[nitpick.violations.Fuss]

Warn about missing and different keys.

write_file(file_exists: bool) Optional[nitpick.violations.Fuss][source]

Write the new file.

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

Bases: nitpick.violations.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: Optional[Type[nitpick.plugins.base.NitpickPlugin]][source]

Handle INI files.

nitpick.plugins.ini.plugin_class() Type[nitpick.plugins.base.NitpickPlugin][source]

Handle INI files.