cmakepresets


Namecmakepresets JSON
Version 0.5.0 PyPI version JSON
download
home_pageNone
SummaryA library for parsing CMakePresets.json
upload_time2025-10-25 17:19:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords cmakepresets.json cmake presets
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [//]: # (x-release-please-start-version)
# CMakePresets 0.5.0
[//]: # (x-release-please-end)


A Python library and CLI tool for working with CMakePresets.json configuration files in CMake projects.

## About

CMakePresets is a utility that helps you inspect and work with CMake preset configurations. It provides both a Python API for programmatic access and a command-line interface for interactive use.

## Features

- Parse and analyze CMakePresets.json files
- List all available presets of different types (configure, build, test, package, workflow)
- Show detailed information about specific presets
- Find related presets (e.g., build presets that use a specific configure preset)
- Display inheritance relationships between presets
- Output in different formats (rich tables, plain text, JSON)

## Installation

```bash
pip install cmakepresets
```

## CLI Usage

### List all presets

```bash
cmakepresets --file CMakePresets.json list
cmakepresets --directory /path/to/project list
```

### List specific types of presets

```bash
cmakepresets --file CMakePresets.json list --type configure
```

### Show details of a specific preset

```bash
cmakepresets --file CMakePresets.json show my-preset
cmakepresets --file CMakePresets.json show my-preset --type configure
```

### Show in JSON format

```bash
cmakepresets --file CMakePresets.json show my-preset --json
```

### Find related presets

```bash
cmakepresets --file CMakePresets.json related my-configure-preset
cmakepresets --file CMakePresets.json related my-configure-preset --type build
```

### Script-friendly output

```bash
cmakepresets --file CMakePresets.json related my-configure-preset --plain
```

## Python API

```python
>>> # Set up the test environment (only needed for doctest)
>>> import os
>>> import sys
>>> sys.path.insert(0, '.')
>>> # Create a proper test environment
>>> from tests.decorators import CMakePresets_json
>>>
>>> # Create test preset content
>>> preset_content = '''{
...   "version": 4,
...   "cmakeMinimumRequired": {"major": 3, "minor": 23, "patch": 0},
...   "configurePresets": [
...     {
...       "name": "base",
...       "generator": "Ninja",
...       "binaryDir": "${sourceDir}/build/${presetName}",
...       "hidden": true
...     },
...     {
...       "name": "my-config",
...       "inherits": "base",
...       "cacheVariables": {
...         "CMAKE_BUILD_TYPE": "Debug"
...       }
...     }
...   ],
...   "buildPresets": [
...     {
...       "name": "my-build",
...       "configurePreset": "my-config"
...     }
...   ]
... }'''
>>>
>>> # Set up the test environment
>>> patcher = CMakePresets_json(preset_content)
>>> test_env = patcher.__enter__()  # This creates a fake filesystem with CMakePresets.json

>>> ###################################################################
>>> # Now we can import and use CMakePresets normally as in real code #
>>> ###################################################################
>>> # Python API Examples
>>> ####
>>> from cmakepresets import CMakePresets
>>> from cmakepresets.constants import CONFIGURE, PACKAGE

>>> # Silence library debug output in doctest
>>> import logging
>>> import cmakepresets
>>> logging.getLogger(cmakepresets.__name__).setLevel(logging.WARNING)

>>> # Load presets from a file (uses the fake filesystem)
>>> presets = CMakePresets("CMakePresets.json")
>>> print(len(presets.configure_presets))
2


>>> # Or load from a project directory
>>> presets = CMakePresets(".")
>>> print(len(presets.build_presets))
1


>>> # Access preset collections
>>> configure_presets = presets.configure_presets
>>> # List names of all configure presets
>>> [preset["name"] for preset in configure_presets]
['base', 'my-config']


>>> # Get related prests to the configurePreset 'my-config'
>>> related = presets.find_related_presets("my-config")
>>> print(related)
{'build': [{'name': 'my-build', 'configurePreset': 'my-config'}], 'test': [], 'package': []}

>>> # Get related packagePrests to 'my-config'
>>> related = presets.find_related_presets("my-config", PACKAGE)
>>> print(len(related[PACKAGE]))
0


>>> # Get a specific preset by name
>>> my_config = presets.get_preset_by_name(CONFIGURE, "my-config")
>>> my_config["name"]
'my-config'

>>> # Get flattened preset with all inherited properties resolved
>>> flattened = presets.flatten_preset(CONFIGURE, "my-config")

>>> # Print the original preset
>>> print(my_config)
{'name': 'my-config', 'inherits': 'base', 'cacheVariables': {'CMAKE_BUILD_TYPE': 'Debug'}}

>>> # Compared to flattened
>>> print(flattened)
{'name': 'my-config', 'generator': 'Ninja', 'binaryDir': '${sourceDir}/build/${presetName}', 'cacheVariables': {'CMAKE_BUILD_TYPE': 'Debug'}}

>>> # Get flattened preset with "pseudo" resolved macros
>>> resolved = presets.resolve_macro_values(CONFIGURE, "my-config")
>>> print(resolved)
{'name': 'my-config', 'generator': 'Ninja', 'binaryDir': '/home/user/project/build/my-config', 'cacheVariables': {'CMAKE_BUILD_TYPE': 'Debug'}}


>>> # Clean up test environment (important to avoid resource leaks)
>>> patcher.__exit__(None, None, None)

```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cmakepresets",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "CMakePresets.json, cmake, presets",
    "author": null,
    "author_email": "Thomas Kristensen <thomas@sl.m04r.space>",
    "download_url": "https://files.pythonhosted.org/packages/68/16/66f5b88ae5a3cecbbdf56197631a2d38c942d7ad023729acf8a4a383f6f9/cmakepresets-0.5.0.tar.gz",
    "platform": null,
    "description": "[//]: # (x-release-please-start-version)\n# CMakePresets 0.5.0\n[//]: # (x-release-please-end)\n\n\nA Python library and CLI tool for working with CMakePresets.json configuration files in CMake projects.\n\n## About\n\nCMakePresets is a utility that helps you inspect and work with CMake preset configurations. It provides both a Python API for programmatic access and a command-line interface for interactive use.\n\n## Features\n\n- Parse and analyze CMakePresets.json files\n- List all available presets of different types (configure, build, test, package, workflow)\n- Show detailed information about specific presets\n- Find related presets (e.g., build presets that use a specific configure preset)\n- Display inheritance relationships between presets\n- Output in different formats (rich tables, plain text, JSON)\n\n## Installation\n\n```bash\npip install cmakepresets\n```\n\n## CLI Usage\n\n### List all presets\n\n```bash\ncmakepresets --file CMakePresets.json list\ncmakepresets --directory /path/to/project list\n```\n\n### List specific types of presets\n\n```bash\ncmakepresets --file CMakePresets.json list --type configure\n```\n\n### Show details of a specific preset\n\n```bash\ncmakepresets --file CMakePresets.json show my-preset\ncmakepresets --file CMakePresets.json show my-preset --type configure\n```\n\n### Show in JSON format\n\n```bash\ncmakepresets --file CMakePresets.json show my-preset --json\n```\n\n### Find related presets\n\n```bash\ncmakepresets --file CMakePresets.json related my-configure-preset\ncmakepresets --file CMakePresets.json related my-configure-preset --type build\n```\n\n### Script-friendly output\n\n```bash\ncmakepresets --file CMakePresets.json related my-configure-preset --plain\n```\n\n## Python API\n\n```python\n>>> # Set up the test environment (only needed for doctest)\n>>> import os\n>>> import sys\n>>> sys.path.insert(0, '.')\n>>> # Create a proper test environment\n>>> from tests.decorators import CMakePresets_json\n>>>\n>>> # Create test preset content\n>>> preset_content = '''{\n...   \"version\": 4,\n...   \"cmakeMinimumRequired\": {\"major\": 3, \"minor\": 23, \"patch\": 0},\n...   \"configurePresets\": [\n...     {\n...       \"name\": \"base\",\n...       \"generator\": \"Ninja\",\n...       \"binaryDir\": \"${sourceDir}/build/${presetName}\",\n...       \"hidden\": true\n...     },\n...     {\n...       \"name\": \"my-config\",\n...       \"inherits\": \"base\",\n...       \"cacheVariables\": {\n...         \"CMAKE_BUILD_TYPE\": \"Debug\"\n...       }\n...     }\n...   ],\n...   \"buildPresets\": [\n...     {\n...       \"name\": \"my-build\",\n...       \"configurePreset\": \"my-config\"\n...     }\n...   ]\n... }'''\n>>>\n>>> # Set up the test environment\n>>> patcher = CMakePresets_json(preset_content)\n>>> test_env = patcher.__enter__()  # This creates a fake filesystem with CMakePresets.json\n\n>>> ###################################################################\n>>> # Now we can import and use CMakePresets normally as in real code #\n>>> ###################################################################\n>>> # Python API Examples\n>>> ####\n>>> from cmakepresets import CMakePresets\n>>> from cmakepresets.constants import CONFIGURE, PACKAGE\n\n>>> # Silence library debug output in doctest\n>>> import logging\n>>> import cmakepresets\n>>> logging.getLogger(cmakepresets.__name__).setLevel(logging.WARNING)\n\n>>> # Load presets from a file (uses the fake filesystem)\n>>> presets = CMakePresets(\"CMakePresets.json\")\n>>> print(len(presets.configure_presets))\n2\n\n\n>>> # Or load from a project directory\n>>> presets = CMakePresets(\".\")\n>>> print(len(presets.build_presets))\n1\n\n\n>>> # Access preset collections\n>>> configure_presets = presets.configure_presets\n>>> # List names of all configure presets\n>>> [preset[\"name\"] for preset in configure_presets]\n['base', 'my-config']\n\n\n>>> # Get related prests to the configurePreset 'my-config'\n>>> related = presets.find_related_presets(\"my-config\")\n>>> print(related)\n{'build': [{'name': 'my-build', 'configurePreset': 'my-config'}], 'test': [], 'package': []}\n\n>>> # Get related packagePrests to 'my-config'\n>>> related = presets.find_related_presets(\"my-config\", PACKAGE)\n>>> print(len(related[PACKAGE]))\n0\n\n\n>>> # Get a specific preset by name\n>>> my_config = presets.get_preset_by_name(CONFIGURE, \"my-config\")\n>>> my_config[\"name\"]\n'my-config'\n\n>>> # Get flattened preset with all inherited properties resolved\n>>> flattened = presets.flatten_preset(CONFIGURE, \"my-config\")\n\n>>> # Print the original preset\n>>> print(my_config)\n{'name': 'my-config', 'inherits': 'base', 'cacheVariables': {'CMAKE_BUILD_TYPE': 'Debug'}}\n\n>>> # Compared to flattened\n>>> print(flattened)\n{'name': 'my-config', 'generator': 'Ninja', 'binaryDir': '${sourceDir}/build/${presetName}', 'cacheVariables': {'CMAKE_BUILD_TYPE': 'Debug'}}\n\n>>> # Get flattened preset with \"pseudo\" resolved macros\n>>> resolved = presets.resolve_macro_values(CONFIGURE, \"my-config\")\n>>> print(resolved)\n{'name': 'my-config', 'generator': 'Ninja', 'binaryDir': '/home/user/project/build/my-config', 'cacheVariables': {'CMAKE_BUILD_TYPE': 'Debug'}}\n\n\n>>> # Clean up test environment (important to avoid resource leaks)\n>>> patcher.__exit__(None, None, None)\n\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A library for parsing CMakePresets.json",
    "version": "0.5.0",
    "project_urls": {
        "Homepage": "https://github.com/tkk2112/cmakepresets",
        "Issues": "https://github.com/tkk2112/cmakepresets/issues",
        "Repository": "https://github.com/tkk2112/cmakepresets.git"
    },
    "split_keywords": [
        "cmakepresets.json",
        " cmake",
        " presets"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "98985ae36d30bad21edcdfafa7d237b78cf1a781edc542c8b3b2a09d32c1a157",
                "md5": "a524e42356f69e585af729379a322d3c",
                "sha256": "3852d651a7934fa4f5d713a55ab623c3d7487a546f3519f7b7e6d4c3eaa07503"
            },
            "downloads": -1,
            "filename": "cmakepresets-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a524e42356f69e585af729379a322d3c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 26665,
            "upload_time": "2025-10-25T17:19:19",
            "upload_time_iso_8601": "2025-10-25T17:19:19.805773Z",
            "url": "https://files.pythonhosted.org/packages/98/98/5ae36d30bad21edcdfafa7d237b78cf1a781edc542c8b3b2a09d32c1a157/cmakepresets-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "681666f5b88ae5a3cecbbdf56197631a2d38c942d7ad023729acf8a4a383f6f9",
                "md5": "06aff48e47f06d69038d30e22c23c6b5",
                "sha256": "65334cefd58dc5859f7a64768d532bb54efc75e59b3de5f5f87e561f741c33be"
            },
            "downloads": -1,
            "filename": "cmakepresets-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "06aff48e47f06d69038d30e22c23c6b5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 115438,
            "upload_time": "2025-10-25T17:19:21",
            "upload_time_iso_8601": "2025-10-25T17:19:21.743256Z",
            "url": "https://files.pythonhosted.org/packages/68/16/66f5b88ae5a3cecbbdf56197631a2d38c942d7ad023729acf8a4a383f6f9/cmakepresets-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-25 17:19:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tkk2112",
    "github_project": "cmakepresets",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cmakepresets"
}
        
Elapsed time: 2.71605s