cmake_format package

Module contents

Language tools for cmake


cmake_format.configuration module

class cmakelang.configuration.Configuration(**kwargs)[source]

Bases: cmakelang.config_util.ConfigObject

Various configuration options and parameters


Implements the descriptor interface for nested configuration objects.


Implements the descriptor interface for nested configuration objects.


Implements the descriptor interface for nested configuration objects.


Implements the descriptor interface for nested configuration objects.


Implements the descriptor interface for nested configuration objects.


Implements the descriptor interface for nested configuration objects.

resolve_for_command(command_name, config_key, default_value=None)[source]

Check for a per-command value or override of the given configuration key and return it if it exists. Otherwise return the global configuration value for that key.

class cmakelang.configuration.EncodingConfig(**kwargs)[source]

Bases: cmakelang.config_util.ConfigObject

Options affecting file encoding

emit_byteorder_mark = False
input_encoding = 'utf-8'
output_encoding = 'utf-8'
class cmakelang.configuration.FormattingConfig(**kwargs)[source]

Bases: cmakelang.config_util.ConfigObject

Options affecting formatting.

always_wrap = []
autosort = False
command_case = 'canonical'
dangle_align = 'prefix'
dangle_parens = False
disable = False
enable_sort = True
fractional_tab_policy = 'use-space'
keyword_case = 'unchanged'
layout_passes = {}
line_ending = 'unix'
line_width = 80
max_lines_hwrap = 2
max_pargs_hwrap = 6
max_prefix_chars = 10
max_rows_cmdline = 2
max_subgroups_hwrap = 2
min_prefix_chars = 4
require_valid_layout = False
separate_ctrl_name_with_space = False
separate_fn_name_with_space = False
tab_size = 2
use_tabchars = False
class cmakelang.configuration.LinterConfig(**kwargs)[source]

Bases: cmakelang.config_util.ConfigObject

Options affecting the linter

argument_var_pattern = '[a-z][a-z0-9_]+'
disabled_codes = []
function_pattern = '[0-9a-z_]+'
global_var_pattern = '[A-Z][0-9A-Z_]+'
internal_var_pattern = '_[A-Z][0-9A-Z_]+'
keyword_pattern = '[A-Z][0-9A-Z_]+'
local_var_pattern = '[a-z][a-z0-9_]+'
macro_pattern = '[0-9A-Z_]+'
max_arguments = 5
max_branches = 12
max_conditionals_custom_parser = 2
max_localvars = 15
max_returns = 6
max_statement_spacing = 2
max_statements = 50
min_statement_spacing = 1
private_var_pattern = '_[0-9a-z_]+'
public_var_pattern = '[A-Z][0-9A-Z_]+'
class cmakelang.configuration.MarkupConfig(**kwargs)[source]

Bases: cmakelang.config_util.ConfigObject

Options affecting comment reflow and formatting.

bullet_char = '*'
canonicalize_hashrulers = True
enable_markup = True
enum_char = '.'
explicit_trailing_pattern = '#<'
fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
first_comment_is_literal = False
hashruler_min_length = 10
literal_comment_pattern = None
ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
class cmakelang.configuration.MiscConfig(**kwargs)[source]

Bases: cmakelang.config_util.ConfigObject

Miscellaneous configurations options.

per_command = {}
class cmakelang.configuration.ParseConfig(**kwargs)[source]

Bases: cmakelang.config_util.ConfigObject

Options affecting listfile parsing

additional_commands = {'foo': {'flags': ['BAR', 'BAZ'], 'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}}
override_spec = {}
proptags = []
vartags = []

cmake_format.common module

class cmakelang.common.EnumObject(value)[source]

Bases: object

Simple enumeration base. Design inspired by clang python bindings BaseEnumeration. Subclasses must provide class member _id_map.

classmethod assign_names()[source]
classmethod from_id(qid)[source]
classmethod from_name(name)[source]
classmethod get(name, default=None)[source]

Get the enumeration name of this value.

classmethod register_value(value, obj)[source]
exception cmakelang.common.FormatError(msg=None)[source]

Bases: Exception

Raised during format or format –check indicating that the program should exit with nonzero status code.

exception cmakelang.common.InternalError(msg=None)[source]

Bases: Exception

Raised when we encounter something we do not expect, indicating a problem with the code itself.

exception cmakelang.common.UserError(msg=None)[source]

Bases: Exception

Raised when we encounter a fatal problem with usage: e.g. parse error, config error, input error, etc.

cmakelang.common.stable_wrap(wrapper, paragraph_text)[source]

textwrap doesn’t appear to be stable. We run it multiple times until it converges

cmake_format.lexer module

cmake_format.markup module

Functions for parsing comments in markup

class cmakelang.markup.CommentItem(kind)[source]

Bases: object

class cmakelang.markup.CommentType(value)[source]

Bases: cmakelang.common.EnumObject

FENCE = CommentType.FENCE
NOTE = CommentType.NOTE
RULER = CommentType.RULER
cmakelang.markup.format_item(config, line_width, item)[source]

Return lines of formatted text based on the typeof markup

cmakelang.markup.format_items(config, line_width, items)[source]

Return lines of formatted text for the sequence of items within a comment block


Return true if the markup item is a hash ruler, i.e.:

# Like this ^^^ or this vvv
cmakelang.markup.parse(lines, config=None)[source]

Parse comment lines. Returns objects of different formatable entities

cmake_format.parse module

class cmakelang.parse.MockEverything[source]

Bases: object

Dummy object which implements any interface by mocking all functions with an empty implementation that returns None

class cmakelang.parse.ParseContext(parse_db=None, lint_ctx=None, config=None)[source]

Bases: object

Global context passed through every function in the parse stack.

cmakelang.parse.parse(tokens, ctx=None)[source]

digest tokens, then layout the digested blocks.

cmake_format.parse.funs module

Statement parser functions


Returns a dictionary mapping statement name to parse functor for that statement.