Metadata-Version: 2.4
Name: cikit
Version: 0.4.0
Summary: CI helper toolkit
Author-email: Sven Schlender <svesch@gmx.de>
License-Expression: LGPL-3.0-or-later
Project-URL: Documentation, https://cikit-a4de14.gitlab.io
Project-URL: Repository, https://gitlab.com/svesch/cikit
Keywords: ci,gitlab,devops,pipeline,artifacts,sphinx
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.34
Requires-Dist: anybadge>=1.16
Requires-Dist: pygal>=3.1.0
Requires-Dist: packaging>=24
Dynamic: license-file

# cikit

![pybuild](https://cikit-a4de14.gitlab.io/_images/pybuild.svg)
![python](https://cikit-a4de14.gitlab.io/_images/python.svg)
![ai assisted](https://cikit-a4de14.gitlab.io/_images/ai_assisted.svg)
![ruff](https://cikit-a4de14.gitlab.io/_images/ruff.svg)
![pylint](https://cikit-a4de14.gitlab.io/_images/pylint.svg)
![unittests](https://cikit-a4de14.gitlab.io/_images/unittests.svg)
![systemtests](https://cikit-a4de14.gitlab.io/_images/systemtests.svg)
![coverage](https://cikit-a4de14.gitlab.io/_images/coverage.svg)

**cikit** is a lightweight Python toolkit for implementing local development and CI workflows
with reusable Python building blocks instead of large shell scripts or provider-specific pipeline
logic.

It combines a CI command framework with CI environment abstraction, reusable macros,
run data, artifact management, reports, timeline charts, and Sphinx integration.

[Documentation](https://cikit-a4de14.gitlab.io/) ·
[Repository](https://gitlab.com/svesch/cikit)

## Highlights

| Category | Features |
| --- | --- |
| CI Framework | Built-in and custom commands, installed command packages, lazy loading |
| CI Providers | Local Git, GitLab, Azure DevOps |
| Builds | CMake, CTest, PlatformIO, Python package builds and publishing, Tectonic |
| Code Quality | Ruff, Pylint, clang-tidy/cloc, pytest, Python and C/C++ coverage |
| Documentation | Sphinx, Doxygen |
| Repository Analysis | Repomix repository packing, token and file statistics |
| Data and Artifacts | Persistent run data, artifact registry, bundles, historical metrics |
| Reporting | Badges, RST reports, interactive SVG timelines and Sphinx extensions |

## Installation

cikit requires Python 3.12 or newer.

```bash
pip install cikit
```

For projects using uv, add cikit as a development dependency:

```bash
uv add --dev cikit
```

Tool-specific dependencies must be provided by the project or CI environment.
cikit does not install external tools automatically.

By default, cikit uses `uv run` as the execution prefix for tools configured to
use it. When working without uv, set `EXEC_TOOL` to an empty string, for example
in a POSIX shell:

```bash
export EXEC_TOOL=""
```

## Quick Start

For a Python project with a `pyproject.toml`, source files under `src/`, and tests
under `tests/`, a basic CI workflow looks like this:

```bash
uv add --dev cikit ruff pytest

uv run cikit init
uv run cikit ruff src tests
uv run cikit pytest tests
```

`init` removes the configured public output directory, including previously generated
artifacts and cached run data. Subsequent commands can share their results within the
same workflow.

List the available commands or inspect command-specific options with:

```bash
uv run cikit --help
uv run cikit ruff --help
```

When using pip without uv, invoke `cikit` directly. See the
[Getting Started guide](https://cikit-a4de14.gitlab.io/getting_started.html)
for a complete introduction.

## CI Command Framework

The `cikit` console command discovers three sources of commands, with increasing precedence:

```text
Built-in commands < Installed command packages < Project-local commands
```

Installed command packages use the `cikit.commands` entry-point group. Project-local
commands can be added in a root-level `ci_commands` package. Only the selected command
implementation is loaded, keeping unrelated tool dependencies optional.

For example, add an empty `ci_commands/__init__.py` and the following `ci_commands/check.py`:

```python
from cikit.ci import run_ci_script


def command(args):
    return run_ci_script("check", lambda env, status: print(env["PROJECT_ROOT"]), args=args)


def register(subparsers, name):
    parser = subparsers.add_parser(name, help="Show the project root.")
    parser.set_defaults(func=command)
```

The command is then available through the normal CLI:

```bash
uv run cikit check
uv run cikit --name custom-check check
```

The logical run name identifies run data and artifact metadata. The `--name` and
`--verbose` options precede the command name. For command registration, discovery,
overrides and orchestration, see the
[CI Commands guide](https://cikit-a4de14.gitlab.io/guides/ci_commands.html).

## Environment and Providers

`cikit.env` resolves configuration and provides a common environment API for commands
and macros. The active provider is detected automatically. Local Git, GitLab and Azure
DevOps supply pipeline and revision metadata through the same interface.

The [Environment concept](https://cikit-a4de14.gitlab.io/concepts/environment.html)
explains configuration and the CI lifecycle. The
[CI Provider Integration guides](https://cikit-a4de14.gitlab.io/guides/providers/index.html)
cover provider-specific setup and artifact handling.

## Project Metadata

cikit combines project metadata from `pyproject.toml` with CI and Git information.
Both static versions and optional PEP 517 dynamic version resolution are supported,
as well as configurable version parsing and metadata templates.

See [Project Metadata](https://cikit-a4de14.gitlab.io/concepts/metadata.html)
for configuration and dependency requirements.

## Macros and Build Workflows

The `cikit.macros` package provides reusable Python building blocks for tool integration,
metrics, artifacts and reports. Built-in and project-specific commands can use the same macros.

Examples of independent built-in workflows for projects with the corresponding tools and
configuration:

```bash
cikit cbuild
cikit ctest
cikit platformio
cikit pybuild
cikit doxygen
cikit repomix
cikit sphinx
```

Build reports combine available build and compiler metadata, timings, diagnostics, memory
usage, downloadable artifacts and logs. Python distributions can be published separately
with `pypublish`.

Explore the [Built-in CI Commands](https://cikit-a4de14.gitlab.io/guides/builtin_commands/index.html),
[Macros](https://cikit-a4de14.gitlab.io/guides/macros/index.html) and
[Builds](https://cikit-a4de14.gitlab.io/guides/builds.html) guides for tool requirements,
command options and Python API examples.

## Data and Artifacts

`CiRunEnvironment` associates metrics and registered artifacts with a logical run. Run data
is stored locally and can optionally be synchronized with a remote cikit data service:

```python
env.data_set("build_time", 4.2)
env.data_update({"warnings": 0, "errors": 0})
```

Registered artifacts include files, bundles and folders with optional entry points.
The persistent artifact registry enables subsequent commands to discover generated outputs
without hard-coded physical paths. Separate CI jobs must transfer the required artifacts
and registry explicitly.

See [cikit Data](https://cikit-a4de14.gitlab.io/concepts/cikit_data.html) for the data model
and [Artifacts](https://cikit-a4de14.gitlab.io/concepts/artifacts.html) for the artifact API.

## Timeline Charts

Historical run data can be queried from the optional remote data service and rendered
as configurable SVG charts. In an active run environment with remote access configured:

```python
from cikit.macros import chart_timeline

chart = chart_timeline(env, keys=["build_time"], title="Build duration", limit=20)
chart.create(env, "build-duration")
```

Registered timeline charts can be included in generated reports. See
[Timeline Charts](https://cikit-a4de14.gitlab.io/guides/timelines.html) for chart presets,
configuration and standalone rendering.

## Sphinx Integration

The Sphinx macro prepares registered reports, badges and other artifacts for a documentation
build and registers the resulting HTML folder as an artifact.

The bundled extensions provide the following RST interfaces:

| RST interface | Purpose |
| --- | --- |
| `.. cikit-chart::` | Interactive SVG timeline charts |
| `:cikit-hash:` | Compact and copyable hash values |
| `.. cikit-log::` | Collapsible command logs |
| `:cikit-metric:` | Inline values from local run data |

Enable all four extensions in the Sphinx configuration:

```python
extensions = ["cikit.sphinx_ext"]
```

See the [Sphinx Build](https://cikit-a4de14.gitlab.io/guides/sphinx_build.html) and
[Sphinx Extensions](https://cikit-a4de14.gitlab.io/guides/sphinx_extensions.html) guides
for setup and usage examples.

## Console Entry Points

| Command | Purpose |
| --- | --- |
| `cikit` | Discover and execute CI commands |
| `cikit-data` | Access cikit data operations |
| `cikit-env` | Inspect, export, document and prepare the CI environment |

Use `--help` on each command for available options.

## License

GNU Lesser General Public License, version 3 or later (`LGPL-3.0-or-later`).

See the [GNU LGPLv3 license text](https://www.gnu.org/licenses/lgpl-3.0.html).
