Skip to main content

cpre

cpre analyzes Boolean conditions in C and C++ preprocessor conditional blocks without preprocessing or parsing the surrounding source code. It identifies dead and redundant branches, simplifies Boolean conditions using ROBDD-backed reasoning, and preserves value-bearing expressions as opaque Boolean predicates.

Installation

python -m pip install cpre

For development:

git clone https://github.com/sahebbiswas/cpre.git
cd cpre
python -m pip install -e ".[dev]"

Usage

After installation, run:

cpre source.c

Or invoke the module directly:

python -m cpre.cpre source.c

Useful options include:

--recursive          recursively scan C/C++ source files under directories
--json               emit JSON output
--verbose            include unchanged conditional branches
--fail-on-findings   exit with status 1 when dead or redundant branches are found

By default, text and JSON reports are filtered to branches that are dead, redundant, or whose condition can be simplified. --verbose restores the full conditional tree.

Python API

The analyzer implementation currently lives in cpre/cpre.py and can be imported as:

from cpre import cpre

tree = cpre.analyze_source(source_text)

The initial package layout intentionally preserves the analyzer implementation while establishing a reusable Python package boundary. Public API refinement can follow independently.

Development

Run the test suite with:

pytest

The CI workflow runs the tests across supported Python versions on Linux, macOS, and Windows.

Versioning

The package version is defined once in cpre/__init__.py as __version__ and is consumed by pyproject.toml during builds. The initial version is 0.1.0.

Publishing releases

Publishing to PyPI is handled by .github/workflows/release.yml using PyPI Trusted Publishing. The workflow runs whenever a GitHub release is published, builds both source and wheel distributions, and publishes them to PyPI without a stored API token.

Before the first release, configure a PyPI Trusted Publisher for this repository with:

  • Owner: sahebbiswas
  • Repository: cpre
  • Workflow: release.yml
  • Environment: pypi

Create a GitHub Actions environment named pypi as well. It can optionally require approval before deployment.

Before publishing a release, update cpre/__init__.py to the release version and create the GitHub release from a matching tag. Both 0.1.0 and v0.1.0 tag forms are accepted for version 0.1.0; a mismatch causes the publish workflow to fail before uploading anything.

License

Licensed under the Apache License, Version 2.0. See LICENSE.

Metadata

Release files for cpre 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cpre 0.1.0
File Size Uploaded
cpre-0.1.0.tar.gz 28.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cpre 0.1.0
File Interpreter ABI Platform
cpre-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 50.1 kB

Release files / cpre-0.1.0.tar.gz

Download URL cpre-0.1.0.tar.gz
Size 28.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7bbcb4e009190519c3d88695e24644b2583d0a900930adaf3ceaedc9af8a1fe1
BLAKE2b-256 checksum
How to use checksums
1e925c846a3c279d28142f291fe847fc217833ea2379727fb7554cc213f83ed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

Release files / cpre-0.1.0-py3-none-any.whl

Download URL cpre-0.1.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
438f7f37006924d1b157ac443542f2d3d7084be6521acdcaabeaaabbaec204a2
BLAKE2b-256 checksum
How to use checksums
ccaede814077d0a6972040ad2c68938085aef0d9fdd64270a4255cd1c204d36a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

Release history Release notifications | RSS feed

0.11.0

2 release files

0.7.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page