inicheck package


inicheck.changes module

class inicheck.changes.ChangeLog(paths=None, mcfg=None, **kwargs)[source]

Bases: object

apply_changes(ucfg, potentials, changes)[source]

Iterate through the list of detectd applicable changes retrieved from get_actived_changes to produce a new config file with the correct changes.

  • ucfg – UserConifg Object
  • changes – list lists length 4 (section item property value) representing detected changes

Config dictionary

Return type:



Checks the current master config that the items we’re moving to are valid. Also confirms that removals are aligned with the master.


Goes through the users config looking for matching old configurations, then makes recommendations.

Parameters:ucfg – UserConfig Object

Joins multiple changelogs together

Parameters:paths – List of paths containing changelogs syntax
lists of line item changes provided in each line as a
list of [old, new]
Return type:changes

Opens the file and reads in sections and the items.

Parameters:path – Path to a changlog file

inicheck.checkers module

Functions for checking values in a config file and producing errors and warnings

class inicheck.checkers.CheckBool(**kwargs)[source]

Bases: inicheck.checkers.CheckType

Boolean checking whether a value of the right type.


Function used to cast values to boolean

Parameters:value – value(s) to be casted
Returns:Value returned as a boolean
Return type:value
class inicheck.checkers.CheckCriticalDirectory(**kwargs)[source]

Bases: inicheck.checkers.CheckDirectory

Checks whether a critical directory exists. This is for any directories that have to exist prior to launching some piece of software.

class inicheck.checkers.CheckCriticalFilename(**kwargs)[source]

Bases: inicheck.checkers.CheckFilename

Checks whether a critical file exists. This would be any files that absolutely have to exist to avoid crashing the software. These are static files.

class inicheck.checkers.CheckDatetime(**kwargs)[source]

Bases: inicheck.checkers.CheckType

Check values that are declared as type datetime. Parses anything that dateparser can parse.

class inicheck.checkers.CheckDatetimeOrderedPair(**kwargs)[source]

Bases: inicheck.checkers.CheckDatetime

Checks to see if start and stop based items are infact in fact ordered in the same section.

Requires keywords section and item to ba passed as keyword args. Looks for keywords start/begin or stop/end in an item name. Then looks for a corresponding match with the opposite name.

start_simulation: 10-01-2019
stop_simulation: 10-01-2017

Would return an issue.

This when checking the start will look for “simulation” with a temporal keyword reference in an item name like end/stop etc. Then it will attempt to determine them to be before.


Looks in the config section for an opposite match for the item.

if we are checking start_simulation, then we look for end_simulation
item name in the config section corresponding with
item being checked
Return type:corresponding
Raises:ValueError – raises an error if the name contains both sets or None of keywords

Checks whether it convertable to datetime, then checks for order.

Parameters:value – Single value to be evaluated
Returns:valid - Boolean whether the value was acceptable msg - string to print if value is not valid.
Return type:tuple
class inicheck.checkers.CheckDirectory(**kwargs)[source]

Bases: inicheck.checkers.CheckPath

Checks whether a directory exists. These directories are allowed to be none and only warn when they do not exist. E.g. Output folders

class inicheck.checkers.CheckDiscretionaryCriticalFilename(**kwargs)[source]

Bases: inicheck.checkers.CheckCriticalFilename

Checks whether a an optional file exists that may change software behavior by being present. In other words, this can be none and still valid. If the not then it registers an error if the string doesn’t exist as path.

class inicheck.checkers.CheckFilename(**kwargs)[source]

Bases: inicheck.checkers.CheckPath

Checks whether a directory exists. These are files that the may be created or not necessary to run. E.g. Log files

class inicheck.checkers.CheckFloat(**kwargs)[source]

Bases: inicheck.checkers.CheckType

Float checking whether a value of the right type.

class inicheck.checkers.CheckInt(**kwargs)[source]

Bases: inicheck.checkers.CheckType

Integer checking whether a value of the right type.


When expecting an integer, it is convenient to automatically convert floats to integers (e.g. 6.0 –> 6) but its pertinent to catch when the input has a non-zero decimal and warn user (e.g. avoid 6.5 –> 6)

Parameters:value – The value to be casted to integer
Returns:the value converted
Return type:value
class inicheck.checkers.CheckPassword(**kwargs)[source]

Bases: inicheck.checkers.CheckType

No checking of any kind here other than avoids alterring it.

class inicheck.checkers.CheckPath(**kwargs)[source]

Bases: inicheck.checkers.CheckType

Checks whether a Path exists. Base for checking if paths exist.


Checks for existing filename

Parameters:value – Single value to be evaluated
Returns:valid - Boolean whether the value was acceptable msg - string to print if value is not valid.
Return type:tuple

Looks at a path and determines its absolute path. All paths should be either absolute or relative to the config file in which they will be converted to absolute paths

Parameters:value – single path or filename
Returns:absolute path or filename
Return type:str
class inicheck.checkers.CheckString(**kwargs)[source]

Bases: inicheck.checkers.CheckType

String checking non paths and passwords. These types of strings are always lower case.

class inicheck.checkers.CheckType(**kwargs)[source]

Bases: inicheck.checkers.GenericCheck

Base class for type checking whether a value of the right type. Here extra Attributes are added such as maximum and minimum.

  • minimum – Minimum value for bounded entries.
  • maximum – Maximum value for bounded entries.
  • type_func – Function used to cast the data to the desired type. Default - str()
  • bounded – Boolean indicating if a value can be limited by a min or max.

Attempts to return the casted values of the each value in self.values.

This is performed with self.type_func unless the value is none in which we return None (NoneType)

Returns:All values from self.values casted correctly
Return type:list

Types are checked differently than some general checker. The checking goes through 5 steps and if anyone of them is invalid it will not check the rest. The process is as follows:

  1. Check if self.values should be a list or not.
  2. Check if a value in self.values should be None or not.
  3. Check for options and if a single value from self.values is among them.
  4. Check is a single value is valid according to self.valid.
  5. Check if a single value is inside any defined bounds.
A list equal to the len(self.values) of either None or
strings relaying the issues found
Return type:list

Checks the users values to see if its in the bounds specified by the developer.

If self.max or self.min == None then it is assumed no bounds on either end.

Function only runs when bounded = True in the master config.

Parameters:value – Single value being evaluated against the bounds.
Returns:valid - Boolean whether the value was acceptable msg - string to print if value is not valid.
Return type:tuple

Checks to see if self.values provided are in a list and if they should be.

Returns:valid - Boolean whether the value was acceptable in terms of being a list msg - string to print if value is not valid.
Return type:tuple

Check a single value if it is None and whether that is accecptable.

Parameters:value – single value to be assessed whether none is valid
Returns:valid - Boolean whether the value was acceptable msg - string to print if value is not valid.
Return type:tuple

Check to see if the current value being evaluated is also in the list of provided options in the master config. Only runs if options were provided.

Parameters:value – A single value which is checked against the list of options in the master config
Returns:valid - Boolean whether the value was in the options list msg - string to print if value is not in the options.
Return type:tuple

Checks a single value using the specified type function. All checkers should have a version of this function.

Parameters:value – Single value to be evaluated
Returns:valid - Boolean whether the value was acceptable msg - string to print if value is not valid.
Return type:tuple
class inicheck.checkers.CheckURL(**kwargs)[source]

Bases: inicheck.checkers.CheckType

Check URLs to see if it can be connected to.


Makes a request to the URL to determine the validity.

Parameters:value – Single value to be evaluated
Returns:valid - Boolean whether the value was acceptable msg - string to print if value is not valid.
Return type:tuple
class inicheck.checkers.GenericCheck(**kwargs)[source]

Bases: object

Generic Checking class. Every class thats a checker should inherit from this class. This class is used like:

Every check will run the check().

  • message – String message to report if the value passed is not valid
  • msg_level – Urgency of the message which can be either a warning or error
  • values – value to be checked, casted, and reported on
  • config – UserConfig object that the item/value being check resides
  • type – string name representing the datatype which is based off the class name
  • is_list – Boolean specifying the resulting values as a list or not
  • allow_none – Boolean specifying the values can contain a value
  • E.G.

    b = GenericCheck(section=’test’, item= ‘tiem1’, config=ucfg) issue = b.check() if issue != None:

Function that is ran by the checking function of the user config to return useful message to instruct user.

Returns:None if the entry is valid, else returns self.message
Return type:msgs

This checks to see if the original entry was a list or not. So instead of evaluating self.values which is always a single item, we evaluate self.config[self.section][self.item]

Parameters:values – The uncasted entry from a config file section and item, can be a list or a single item
Returns:True if its a list false if it is not.
Return type:boolean

Abstract function for defining how a value is checked for validity. It should always be used in check(). Is valid should always return a boolean whether the result is valid, and the issue as a string stating the problem. If no issue it should still return None.

Parameters:value – Single value to be evaluated
Returns:valid - Boolean whether the value was acceptable msg - string to print if value is not valid.
Return type:tuple

inicheck.cli module

inicheck.cli.check_for_changes(directory, modules=[], paths=[])[source]

Returns files with changes found in the changelog. Using the change log this function goes through all the files in the directory and returns any filenames with a config entry in python code that will error out

This script only looks at and reports changes in found for sections and items listed in the changelog. Currently ignores default changes.

  • directory – Folder with python scripts to check for instances of changes
  • paths – list of paths to an inicheck changelog
  • modules – list of python modules with an __config_changelog__ attribute

dictionary with filenames as keys and line numbers in a list as the value.

Return type:



CLI tool for examining a python repo and reporting any old python code that references a deprecated config file entry as reported in a changelog

inicheck.cli.inicheck_main(config_file=None, master=None, modules=None, write_out=False, show_recipes=False, show_non_defaults=False, details=None, apply_changelog=False)[source]

Function used for the CLI for inicheck. This is mostly for cleaner testing. Allows users to look at master config details, check their config file against the master, look at recipes applied, examine non-default entries, write new config files, and apply changes from a changelog


Creates a report showing the difference in files

inicheck.cli.inidiff_main(config_files, master=None, modules=None)[source]

Attempts to walk through making a brand new ini file based on developers master config and recipes.

Currently config files can have different configurations based on recipes. This script will ask the user for a decision by looking for:

  • Triggers built on sections and if that section is removed in another conditional
  • Triggers built on any_section item trigger which is also removed in another conditional

inicheck.config module

class inicheck.config.MasterConfig(path=None, modules=None, checkers=None, titles=None, header=None, changelogs=None)[source]

Bases: object


Designed to add to the master config file if the user has split up files to reduce the amount of info in a master file. e.g. recipes are stored in another file.

Parameters:paths – list of real path to another cfg.ini
Original config with appended information found in the
extra cfg
Return type:config

Merges the a master config object into the current master config object in place

class inicheck.config.UserConfig(filename, mcfg=None)[source]

Bases: object

Class meant for managing the the users config, here we operate on the config repeatedly making it available through the attribute self.cfg

  • raw_cfg – Untouched original OrderedDict that inicheck read from file
  • cfg – OrderedDict of the config file that inicheck will check, cast, list, etc
  • recipes – List of that apply to this config
  • sections – List of strings that represent the unique sections for the whole config file
  • items – List of strings that represent the unique items for the whole config file
  • values – List of strings that represent the unique values for the whole config file
  • mcfg – config.MasterConfig object that represents the standard the cfg is checked against
add_defaults(cfg, sections=None, items=None)[source]

Look through the users config file and section by section add in missing parameters to add defaults

Parameters:sections – Single section name or a list of sections to apply (optional) otherwise uses all sections in users config
Returns:User config dictionary with defaults added.
Return type:user_cfg

Look through the users config file and section by section add in missing parameters to add defaults

Returns:User config dictionary with defaults added.
Return type:user_cfg

Appends all the values in the user config to respectives lists of section names, item names, and values. Afterwards any copy is removed so all is left is a unique list of names and values

Parameters:cfg – OrderedDict of the config file
Returns:tuple of len=3 of sets of unique sections items and values
Return type:tuple
interpret_recipes(partial_cfg, situation)[source]

User inserts a partial config by using each situation that triggered a recipe. A triggering situation consists of a tuple of (section, item, value) that represent the specific settings that trigger the recipe. All default references should avoid overwriting the users selection.

  • partial_cfg – dictionary of edits to be applied to the cfg
  • situation – List of len=3 describing the trigger mechanism

Modified dictionary

Return type:



Sets all paths so that they are always relative to the config file or absolute.

inicheck.config.check_types(cfg, checkers)[source]

Iterates through all the master config items and confirm all type are valid

  • cfg – dict of master config entries listing out properties
  • checkers – dict of checker names and class as Key Value pairs

True if no error is raised

Return type:



ValueError – raises error if a type is specified not in the lists of checkers

inicheck.entries module

class inicheck.entries.ConfigEntry(name=None, parseable_line=None)[source]

Bases: object

ConfigEntry designed to aid in parsing master config file entries. This is meant to parse:


                type = <value>,
                options = [<value> <value>],
                description = text describing entry

Config entry expects to recieve the above in the following format:

parseable_line = ["type = <value>",
                 "options = [<value> <value>"],
                 "description=text describing entry"]
name = item

Config entry then will parse the strings looking for space separated lists, values denoted with =, and will only receive:

  • type
  • default
  • options
  • description
  • max
  • min
  • allow_none
class inicheck.entries.RecipeSection(recipe_section_dict, name=None)[source]

Bases: object

The RecipeSection enables the master config file to parses a section that is actually a recipe. Operates using keywords provided n the name of the section. It collects triggers and adjustments to the config file and assigns them to this class. Trigger represent the conditional statements to apply the adjustments listed below. If an item in the section doesn’t contain any trigger keyword then it is assumed to be an adjustment to be made.

class inicheck.entries.TriggerEntry(parseable_line, name=None)[source]

Bases: object

RecipeEntry designed to aid in parsing master config file entries under a recipe. This is meant to parse:


                has_section_name = <value>,
                has_value = [<section name> <item name>, <value>],
                has_item_name = <value>


Config entry expects to recieve the above in the following format:

            ["has_section = <value>",
             "has_item = [<section> <item>"],
             "has_value = [<section> <item> <value>]"

Recipe entry then will parse the strings looking for space separated lists, values denoted with = and will only accept keyword

  • has_section
  • has_item
  • has_value

inicheck.iniparse module


Takes in a section and item parsed dictionary and parses on > forming a list. It works as the following:

To move an item to another section or item name section/item -> new_section/new_item

section/item -> Removed

Parameters:change_list – List of modifcations that occured to the config
a list of a list length 2 containing of list length 4
representing section item property value which are all any by default.
Return type:result
inicheck.iniparse.parse_entry(info, item=None, valid_names=None)[source]

Parse the values found in the master config where the entries are a little more complicated. Specifically this deals with syntax issues and whether a entry option is valid or not.

This should be used only after knowning the section and item.

  • info – a single line or a List of lines to parse containing master config options
  • item – Item name were parsing. Only for reporting errors purposes
  • valid_names – valid property names to be parsing.

dictionary containing the properties as keys

Return type:


inicheck.iniparse.parse_items(parsed_sections_dict, mcfg=None)[source]

Takes the output from parse_sections and parses the items in each section

Parameters:parsed_sections_dict – dictionary containing keys as the sections and values as a continuous string of the
dictionary of dictionaries containing sections,items, and
their values
Return type:result

Returns a dictionary containing all the sections as keys with a single string of the contents after the section

Parameters:lines – a list of string lines containing all the raw info of a cfg file
dictionary containing keys that are the section names and
values that are strings of the contents between sections
Return type:sections

Takes the output from parse_items and parses any values or properties provided in each item placing the strings into a list. If no properties are defined then it will clean up values provided and put them in a list of len one.

Parameters:parsed_sections_dict – dict of dicts containing joined strings found under each item
dictionary of dictionaries containing sections, items,
and the values provided as a list
Return type:result

Opens and reads in the config file in its most raw form. Creates a dictionary of dictionaries that contain the string result

Parameters:fname – Real path to the config file to be opened
Returns:dict of dicts containing the info in a config file
Return type:config

inicheck.output module

inicheck.output.generate_config(config_obj, fname, cli=False)[source]

Generates a list of strings using the config data then its written to an .ini file

  • config_obj – config object containing data to be outputted
  • fname – String path to the output location for the new config file
  • cli – Boolean value that adds the line “file generated using inicheck.cli”, Default = False
inicheck.output.print_cfg_for_recipe(cfg, fmt, hdr=None)[source]
inicheck.output.print_change_report(potential_changes, required_changes, ucfg, logger=None)[source]

Pass in the list of changes generated by check_config file. print out in a pretty format the changes required

  • potential_changes – List of warnings about config property changes especialy about defaults retruned from get_active_changes().
  • potential_required – List of critical changes returned from get_active_changes().
inicheck.output.print_config_report(warnings, errors, logger=None)[source]

Pass in the list of string messages generated by check_config file. print out in a pretty format the issues

  • warnings – List of non-critical messages returned from check_config().
  • errors – List of critical messages returned from check_config().
  • logger – pass in the logger function being used. If no logger is provided, print is used. Default = None
inicheck.output.print_details(details, mcfg)[source]

Prints out the details for a list of provided options designed for use with the CLI. Details about a section, or an item can be requested by passing in a list of in the section,item order. If a section is only passed then we the details provided are for the entire section

  • details – a list in [section item value] requesting details.
  • mcfg – master config dictionary to gather the details from

Prints out the options used that were not default option values.

Parameters:ucfg – config object containing options that are not default

Prints out the recipes found and how they are interpretted

Parameters:lst_recipes – list of the recipe entry objects module, mcfg_obj)[source]

Cast all values into the appropiate type using checkers, other_types and the master config.

  • config_obj – The object of the user config from
  • mcfg_obj – The object used for manage the master config from class MasterConfig
  • other_types – User provided list to add any custom types

The users config dictionary containing the correct value types

Return type:


Looks at the users provided config file and checks it to a master config file looking at correctness and missing info.

Parameters:config_obj - UserConfig object produced byUserConfig
  • warnings - Returns a list of string messages that are
    consider non-critical issues with config file.
  • errors - Returns a list of string messages that are
    consider critical issues with the config file.
Return type:tuple, paths=None, modules=None, section_link_dict={})[source]

Auto documents the core config file. Outputs to a file which is can then be used for documentation. Specifically formulated for sphinx

  • out_f – string path to output location for the auto documentation
  • paths – paths to master config files to use for creating docs
  • modules – modules with attributes __core_config__ for creating docs
  • section_link_dict – dictionary containing special documentation for a section in the config file reference'inicheck.checkers', keywords='check', ignore=['type', 'generic', 'path'])[source]
  • module – The module to search for the classes
  • keyword – Keywords to look for in class names
  • ignore – Post parsed keywords to ignore if found in a class name

Dict of the classes available for checking config entries

Return type:


Retrieve the dictionary of checker classes by grabbing all in inicheck and any prescribed in the master config through another module

Parameters:ucfg – User Config object containing modules
all_checks - dictionary of all the checkers from inicheck
and any modules assigned to the master config.
Return type:dictionary, master_files=None, modules=None, mcfg=None, changelog_file=None, cli=False)[source]

Returns the users config as the object UserConfig.

  • config_file – real path to existing config file
  • master_file – real path to a Core Config file
  • modules – a module or list of modules with a string attribute __CoreConfig__ which is the path to a CoreConfig
  • mcfg – the master config object after it has been read in.
  • changelog_file – Path to a changlog showing any changes to the config file the developers have made
  • cli – boolean determining whether to attempt to process the changes which should be done from the CLI only

Users config as an object

Return type:


inicheck.utilities module

inicheck.utilities.ask_config_setup(choices_series, section=None, item=None, num_questions=None)[source]

Ask repeating questions for setting up a config

inicheck.utilities.ask_user(question, choices=None)[source]

Asks the user which choice to make and handles incorrect choices.

inicheck.utilities.find_options_in_recipes(recipes, choice_search, action_kw, condition_position=0)[source]

Looks through the master config at recipes and entries to determine if there are place the developer made distince choices, this is used in the inimake script to walk users through making their own config file from scratch.

This function looks through and finds sections or items that match the conditional. Then it looks through the adj_config to determine if any sections/items are being removed as a result, then it finds those. If a section/item appears in a recipe condition and a removed by another trigger it is extremely likely these are choices.

  • mcfg – Recipes object from master config
  • conditional – list of 3 focusing on what were looking for
  • action_kw – action keyword is a string of what to look for in matching choices where ever true is used will popoulate with every item/section

Return type:


inicheck.utilities.get_inicheck_cmd(config_file, modules=None, master_files=None)[source]

Strings together an inicheck cli command based on modules and files

inicheck.utilities.get_kw_match(potential_matches, kw_list, kw_count=1)[source]

Loops through a list of potential matches looking for keywords in the list of strings being presented. When a match is found return its value.

  • potential_matches – List of strings to check
  • kw_list – List of strings to look for inside the single word
  • kw_count – Minimum Number of keywords to be found for it to be True

The first potential found with the keyword match

Return type:


inicheck.utilities.get_relative_to_cfg(path, user_cfg_path)[source]

Converts a path so that all paths are relative to the config file

  • path – relative str path to be converted
  • user_cfg_path – path to the users config file

absolute path of the input considering it was relative to the cfg

Return type:


inicheck.utilities.is_kw_matched(single_word, kw_list, kw_count=1)[source]

Checks to see if there are any keywords in the single word and returns a boolean

  • single_word – String to be examined for keywords
  • kw_list – List of strings to look for inside the single word
  • kw_count – Minimum Number of keywords to be found for it to be True

Whether a keyword match was found

Return type:


inicheck.utilities.is_valid(value, cast_fn, expected_data_type, allow_none=False)[source]

Checks whether a value can be converted using the cast_fn function.

  • value – Value to be considered
  • cast_fn – Function used to determine the validity, should throw an exception if it cannot
  • expected_data_type – string name of the expected data
  • allow_none – Boolean determining if none is valid

valid (boolean): whether it could be casted msg (string): Msg reporting what happen

Return type:


inicheck.utilities.mk_lst(values, unlst=False)[source]

while iterating through several type of lists and items it is convenient to assume that we recieve a list, use this function to accomplish this. It also convenient to be able to return the original type after were done with it.


Function used to cast items to datetime from string. Meant to prevent the importing of pandas just for the to_datetime function.

Parameters:value – string of a datetime
Returns:Datetime object representing the value passed.
Return type:converted

prints out the config file to the prompt with a nice stagger Look for readability

Parameters:cfg – dict of dict in a heirarcy of {section, {items, values}}

prints out the core config file to the prompt with a nice stagger Look for readability

Parameters:cfg – dict of dict in a hierarchy of {section, {items, values}}
inicheck.utilities.remove_chars(orig_str, char_str, replace_str=None)[source]

Removes all character in orig_str that are in char_str

  • orig_str – Original string needing cleaning
  • char_str – String of characters to be removed
  • replace_str – replace values with a character if requested

orig_str with out any characters in char_str

Return type:



Takes a single line and removes and .ini type comments. Also remove any spaces at the begining or end of a commented line

Module contents