update_cmakeformat_config

The CMakeFormat tool provides powerful formatting and linting for CMake files, and it allows you to specify the semantics of any custom CMake functions in your configuration file (.cmake-format.json). This script provides a way to update all the command specifications in one file with those present in another file.

Oranges provides a JSON file containing command specifications for all commands provided by Oranges modules; this file is located at util/OrangesCMakeCommands.json. You can update your CMakeFormat configuration file by running this command from the root of the Oranges repository:

python3 scripts/update_cmakeformat_config.py --input=util/OrangesCMakeCommands.json --output=<pathToYourConfigFile>

Command-line usage

usage: update_cmakeformat_config [-h] --input INPUT_FILE
                                 [--output OUTPUT_FILE]

Named Arguments

--input, -i

Path of the input file to read. If this is a relative path, the file used will be $(pwd)/<input_file>.

--output, -o

Path to the config file to update. If this is a relative path, the file used will be $(pwd)/<output_file>. Defaults to $(pwd)/.cmake-format.json.

Default: “/home/docs/checkouts/readthedocs.org/user_builds/oranges/checkouts/latest/Builds/docs/.cmake-format.json”

Module functions

This script updates a .cmake-format.json file’s additional_commands field with command descriptions from another json file.

update_cmakeformat_config.read_commands_from_json(input_file: str) dict[dict]

Parses the input JSON file and creates a dictionary of dictionaries, each entry representing a single CMake command specification.

Parameters:

input_file (str) – Absolute path of the input file to parse

Returns:

A dictionary of dictionaries, with each entry in the list representing one CMake command specification

Return type:

dict[dict]

update_cmakeformat_config.update_cmakeformat_config(input_file: str, output_file: str) None

Updates the output .cmake-format.json file with the command descriptions found in the input file. Both input and output files must be valid JSON.

Parameters:
  • input_file (str) – Path to the input file to read. If this is a relative path, the file used will be $(pwd)/<input_file>. The root object of this JSON file can contain the ‘parse’ key, or the ‘additional_commands’ key can be at the top level of the root object.

  • output_file (str) – Path to the config file to update. If this is a relative path, the file used will be $(pwd)/<output_file>. Defaults to $(pwd)/.cmake-format.json.

Return type:

None