class NitpickSectionSchema(BaseNitpickSchema): """Validation schema for the ``[nitpick]`` section on the style file.""" meta = fields.Nested(NitpickMetaSchema) minimum_version = fields.NonEmptyString() styles = fields.Nested(NitpickStylesSectionSchema) files = fields.Nested(NitpickFilesSectionSchema)
class NitpickSectionSchema(BaseNitpickSchema): """Validation schema for the ``[nitpick]`` section on the style file.""" minimum_version = fields.FilledString() styles = fields.Nested(NitpickStylesSectionSchema) files = fields.Nested(NitpickFilesSectionSchema) # TODO: load this schema dynamically, then add this next field JSONFile JSONFile = fields.Nested(NitpickJSONFileSectionSchema)
class BaseStyleSchema(Schema): """Base validation schema for style files. Dynamic fields will be added to it later.""" error_messages = { "unknown": help_message("Unknown file", "config_files.html") } nitpick = fields.Nested(NitpickSectionSchema)
class NitpickFilesSectionSchema(BaseNitpickSchema): """Validation schema for the ``[nitpick.files]`` section on the style file.""" error_messages = { "unknown": help_message("Unknown file", "nitpick_section.html#nitpick-files") } absent = fields.Dict(fields.FilledString, fields.String()) present = fields.Dict(fields.FilledString, fields.String()) # TODO: load this schema dynamically, then add this next field setup_cfg setup_cfg = fields.Nested(SetupCfgSchema, data_key=SetupCfgFile.file_name)
def file_field_pair(file_name: str, base_file_class: Type[NitpickPlugin]) -> Dict[str, fields.Field]: """Return a schema field with info from a config file class.""" valid_toml_key = TOMLFormat.group_name_for(file_name) unique_file_name_with_underscore = slugify(file_name, separator="_") kwargs = {"data_key": valid_toml_key} if base_file_class.validation_schema: field = fields.Nested(base_file_class.validation_schema, **kwargs) else: # For default files (pyproject.toml, setup.cfg...), there is no strict schema; # it can be anything they allow. # It's out of Nitpick's scope to validate those files. field = fields.Dict(fields.String, **kwargs) return {unique_file_name_with_underscore: field}
def file_field_pair( filename: str, base_file_class: type[NitpickPlugin]) -> dict[str, fields.Field]: """Return a schema field with info from a config file class.""" unique_filename_with_underscore = slugify(filename, separator="_") kwargs = {"data_key": filename} if base_file_class.validation_schema: file_field = fields.Nested(base_file_class.validation_schema, **kwargs) else: # For some files (e.g.: TOML/ INI files), there is no strict schema; # it can be anything they allow. # It's out of Nitpick's scope to validate those files. file_field = fields.Dict(fields.String, **kwargs) return {unique_filename_with_underscore: file_field}
class TextSchema(Schema): """Validation schema for the text file TOML configuration.""" error_messages = {"unknown": help_message("Unknown configuration", TEXT_FILE_RTFD_PAGE)} contains = fields.List(fields.Nested(TextItemSchema))